Skip to content

Commit 4ac032f

Browse files
committed
Auto merge of rust-lang#138768 - matthiaskrgr:rollup-nfu3cm3, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#137357 (Document results of non-positive logarithms) - rust-lang#138650 (Optimize `io::Write::write_fmt` for constant strings) - rust-lang#138694 (Fix: add ohos target notes) - rust-lang#138713 (interpret memory access hooks: also pass through the Pointer used for the access) - rust-lang#138724 (Check attrs: Don't try to retrieve the name of list stems) - rust-lang#138743 (bootstrap: add `--ci` flag) - rust-lang#138751 (Fix the "used_with_archive" test on Fuchsia) - rust-lang#138754 (Handle spans of `~const`, `const` and `async` trait bounds in macro expansion) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5d85a71 + 5ba395a commit 4ac032f

File tree

33 files changed

+727
-118
lines changed

33 files changed

+727
-118
lines changed

compiler/rustc_ast/src/mut_visit.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ pub trait MutVisitor: Sized {
238238
walk_ident(self, i);
239239
}
240240

241+
fn visit_modifiers(&mut self, m: &mut TraitBoundModifiers) {
242+
walk_modifiers(self, m);
243+
}
244+
241245
fn visit_path(&mut self, p: &mut Path) {
242246
walk_path(self, p);
243247
}
@@ -1156,12 +1160,29 @@ fn walk_trait_ref<T: MutVisitor>(vis: &mut T, TraitRef { path, ref_id }: &mut Tr
11561160
}
11571161

11581162
fn walk_poly_trait_ref<T: MutVisitor>(vis: &mut T, p: &mut PolyTraitRef) {
1159-
let PolyTraitRef { bound_generic_params, modifiers: _, trait_ref, span } = p;
1163+
let PolyTraitRef { bound_generic_params, modifiers, trait_ref, span } = p;
1164+
vis.visit_modifiers(modifiers);
11601165
bound_generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
11611166
vis.visit_trait_ref(trait_ref);
11621167
vis.visit_span(span);
11631168
}
11641169

1170+
fn walk_modifiers<V: MutVisitor>(vis: &mut V, m: &mut TraitBoundModifiers) {
1171+
let TraitBoundModifiers { constness, asyncness, polarity } = m;
1172+
match constness {
1173+
BoundConstness::Never => {}
1174+
BoundConstness::Always(span) | BoundConstness::Maybe(span) => vis.visit_span(span),
1175+
}
1176+
match asyncness {
1177+
BoundAsyncness::Normal => {}
1178+
BoundAsyncness::Async(span) => vis.visit_span(span),
1179+
}
1180+
match polarity {
1181+
BoundPolarity::Positive => {}
1182+
BoundPolarity::Negative(span) | BoundPolarity::Maybe(span) => vis.visit_span(span),
1183+
}
1184+
}
1185+
11651186
pub fn walk_field_def<T: MutVisitor>(visitor: &mut T, fd: &mut FieldDef) {
11661187
let FieldDef { span, ident, vis, id, ty, attrs, is_placeholder: _, safety, default } = fd;
11671188
visitor.visit_id(id);

compiler/rustc_const_eval/src/const_eval/machine.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::errors::{LongRunning, LongRunningWarn};
2222
use crate::fluent_generated as fluent;
2323
use crate::interpret::{
2424
self, AllocId, AllocInit, AllocRange, ConstAllocation, CtfeProvenance, FnArg, Frame,
25-
GlobalAlloc, ImmTy, InterpCx, InterpResult, MPlaceTy, OpTy, RangeSet, Scalar,
25+
GlobalAlloc, ImmTy, InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, RangeSet, Scalar,
2626
compile_time_machine, interp_ok, throw_exhaust, throw_inval, throw_ub, throw_ub_custom,
2727
throw_unsup, throw_unsup_format,
2828
};
@@ -688,6 +688,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
688688
_tcx: TyCtxtAt<'tcx>,
689689
_machine: &mut Self,
690690
_alloc_extra: &mut Self::AllocExtra,
691+
_ptr: Pointer<Option<Self::Provenance>>,
691692
(_alloc_id, immutable): (AllocId, bool),
692693
range: AllocRange,
693694
) -> InterpResult<'tcx> {

compiler/rustc_const_eval/src/interpret/machine.rs

+9
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ pub trait Machine<'tcx>: Sized {
400400
) -> InterpResult<'tcx, Self::AllocExtra>;
401401

402402
/// Hook for performing extra checks on a memory read access.
403+
/// `ptr` will always be a pointer with the provenance in `prov` pointing to the beginning of
404+
/// `range`.
403405
///
404406
/// This will *not* be called during validation!
405407
///
@@ -413,6 +415,7 @@ pub trait Machine<'tcx>: Sized {
413415
_tcx: TyCtxtAt<'tcx>,
414416
_machine: &Self,
415417
_alloc_extra: &Self::AllocExtra,
418+
_ptr: Pointer<Option<Self::Provenance>>,
416419
_prov: (AllocId, Self::ProvenanceExtra),
417420
_range: AllocRange,
418421
) -> InterpResult<'tcx> {
@@ -432,23 +435,29 @@ pub trait Machine<'tcx>: Sized {
432435

433436
/// Hook for performing extra checks on a memory write access.
434437
/// This is not invoked for ZST accesses, as no write actually happens.
438+
/// `ptr` will always be a pointer with the provenance in `prov` pointing to the beginning of
439+
/// `range`.
435440
#[inline(always)]
436441
fn before_memory_write(
437442
_tcx: TyCtxtAt<'tcx>,
438443
_machine: &mut Self,
439444
_alloc_extra: &mut Self::AllocExtra,
445+
_ptr: Pointer<Option<Self::Provenance>>,
440446
_prov: (AllocId, Self::ProvenanceExtra),
441447
_range: AllocRange,
442448
) -> InterpResult<'tcx> {
443449
interp_ok(())
444450
}
445451

446452
/// Hook for performing extra operations on a memory deallocation.
453+
/// `ptr` will always be a pointer with the provenance in `prov` pointing to the beginning of
454+
/// the allocation.
447455
#[inline(always)]
448456
fn before_memory_deallocation(
449457
_tcx: TyCtxtAt<'tcx>,
450458
_machine: &mut Self,
451459
_alloc_extra: &mut Self::AllocExtra,
460+
_ptr: Pointer<Option<Self::Provenance>>,
452461
_prov: (AllocId, Self::ProvenanceExtra),
453462
_size: Size,
454463
_align: Align,

compiler/rustc_const_eval/src/interpret/memory.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
385385
self.tcx,
386386
&mut self.machine,
387387
&mut alloc.extra,
388+
ptr,
388389
(alloc_id, prov),
389390
size,
390391
alloc.align,
@@ -727,6 +728,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
727728
self.tcx,
728729
&self.machine,
729730
&alloc.extra,
731+
ptr,
730732
(alloc_id, prov),
731733
range,
732734
)?;
@@ -816,7 +818,14 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
816818
if let Some((alloc_id, offset, prov, alloc, machine)) = ptr_and_alloc {
817819
let range = alloc_range(offset, size);
818820
if !validation_in_progress {
819-
M::before_memory_write(tcx, machine, &mut alloc.extra, (alloc_id, prov), range)?;
821+
M::before_memory_write(
822+
tcx,
823+
machine,
824+
&mut alloc.extra,
825+
ptr,
826+
(alloc_id, prov),
827+
range,
828+
)?;
820829
}
821830
interp_ok(Some(AllocRefMut { alloc, range, tcx: *tcx, alloc_id }))
822831
} else {
@@ -1373,6 +1382,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
13731382
tcx,
13741383
&self.machine,
13751384
&src_alloc.extra,
1385+
src,
13761386
(src_alloc_id, src_prov),
13771387
src_range,
13781388
)?;
@@ -1403,6 +1413,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
14031413
tcx,
14041414
extra,
14051415
&mut dest_alloc.extra,
1416+
dest,
14061417
(dest_alloc_id, dest_prov),
14071418
dest_range,
14081419
)?;

compiler/rustc_passes/src/check_attr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
954954
tcx.dcx().emit_err(errors::DocAliasBadLocation { span, attr_str, location });
955955
return;
956956
}
957-
let item_name = self.tcx.hir_name(hir_id);
958-
if item_name == doc_alias {
957+
if self.tcx.hir_opt_name(hir_id) == Some(doc_alias) {
959958
tcx.dcx().emit_err(errors::DocAliasNotAnAlias { span, attr_str });
960959
return;
961960
}

library/core/src/fmt/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,10 @@ impl<'a> Arguments<'a> {
710710
}
711711

712712
/// Same as [`Arguments::as_str`], but will only return `Some(s)` if it can be determined at compile time.
713+
#[unstable(feature = "fmt_internals", reason = "internal to standard library", issue = "none")]
713714
#[must_use]
714715
#[inline]
715-
fn as_statically_known_str(&self) -> Option<&'static str> {
716+
pub fn as_statically_known_str(&self) -> Option<&'static str> {
716717
let s = self.as_str();
717718
if core::intrinsics::is_val_statically_known(s.is_some()) { s } else { None }
718719
}

library/std/src/f128.rs

+60
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ impl f128 {
468468

469469
/// Returns the natural logarithm of the number.
470470
///
471+
/// This returns NaN when the number is negative, and negative infinity when number is zero.
472+
///
471473
/// # Unspecified precision
472474
///
473475
/// The precision of this function is non-deterministic. This means it varies by platform,
@@ -489,6 +491,16 @@ impl f128 {
489491
/// assert!(abs_difference <= f128::EPSILON);
490492
/// # }
491493
/// ```
494+
///
495+
/// Non-positive values:
496+
/// ```
497+
/// #![feature(f128)]
498+
/// # #[cfg(reliable_f128_math)] {
499+
///
500+
/// assert_eq!(0_f128.ln(), f128::NEG_INFINITY);
501+
/// assert!((-42_f128).ln().is_nan());
502+
/// # }
503+
/// ```
492504
#[inline]
493505
#[rustc_allow_incoherent_impl]
494506
#[unstable(feature = "f128", issue = "116909")]
@@ -499,6 +511,8 @@ impl f128 {
499511

500512
/// Returns the logarithm of the number with respect to an arbitrary base.
501513
///
514+
/// This returns NaN when the number is negative, and negative infinity when number is zero.
515+
///
502516
/// The result might not be correctly rounded owing to implementation details;
503517
/// `self.log2()` can produce more accurate results for base 2, and
504518
/// `self.log10()` can produce more accurate results for base 10.
@@ -522,6 +536,16 @@ impl f128 {
522536
/// assert!(abs_difference <= f128::EPSILON);
523537
/// # }
524538
/// ```
539+
///
540+
/// Non-positive values:
541+
/// ```
542+
/// #![feature(f128)]
543+
/// # #[cfg(reliable_f128_math)] {
544+
///
545+
/// assert_eq!(0_f128.log(10.0), f128::NEG_INFINITY);
546+
/// assert!((-42_f128).log(10.0).is_nan());
547+
/// # }
548+
/// ```
525549
#[inline]
526550
#[rustc_allow_incoherent_impl]
527551
#[unstable(feature = "f128", issue = "116909")]
@@ -532,6 +556,8 @@ impl f128 {
532556

533557
/// Returns the base 2 logarithm of the number.
534558
///
559+
/// This returns NaN when the number is negative, and negative infinity when number is zero.
560+
///
535561
/// # Unspecified precision
536562
///
537563
/// The precision of this function is non-deterministic. This means it varies by platform,
@@ -551,6 +577,16 @@ impl f128 {
551577
/// assert!(abs_difference <= f128::EPSILON);
552578
/// # }
553579
/// ```
580+
///
581+
/// Non-positive values:
582+
/// ```
583+
/// #![feature(f128)]
584+
/// # #[cfg(reliable_f128_math)] {
585+
///
586+
/// assert_eq!(0_f128.log2(), f128::NEG_INFINITY);
587+
/// assert!((-42_f128).log2().is_nan());
588+
/// # }
589+
/// ```
554590
#[inline]
555591
#[rustc_allow_incoherent_impl]
556592
#[unstable(feature = "f128", issue = "116909")]
@@ -561,6 +597,8 @@ impl f128 {
561597

562598
/// Returns the base 10 logarithm of the number.
563599
///
600+
/// This returns NaN when the number is negative, and negative infinity when number is zero.
601+
///
564602
/// # Unspecified precision
565603
///
566604
/// The precision of this function is non-deterministic. This means it varies by platform,
@@ -580,6 +618,16 @@ impl f128 {
580618
/// assert!(abs_difference <= f128::EPSILON);
581619
/// # }
582620
/// ```
621+
///
622+
/// Non-positive values:
623+
/// ```
624+
/// #![feature(f128)]
625+
/// # #[cfg(reliable_f128_math)] {
626+
///
627+
/// assert_eq!(0_f128.log10(), f128::NEG_INFINITY);
628+
/// assert!((-42_f128).log10().is_nan());
629+
/// # }
630+
/// ```
583631
#[inline]
584632
#[rustc_allow_incoherent_impl]
585633
#[unstable(feature = "f128", issue = "116909")]
@@ -966,6 +1014,8 @@ impl f128 {
9661014
/// Returns `ln(1+n)` (natural logarithm) more accurately than if
9671015
/// the operations were performed separately.
9681016
///
1017+
/// This returns NaN when `n < -1.0`, and negative infinity when `n == -1.0`.
1018+
///
9691019
/// # Unspecified precision
9701020
///
9711021
/// The precision of this function is non-deterministic. This means it varies by platform,
@@ -989,6 +1039,16 @@ impl f128 {
9891039
/// assert!(abs_difference < 1e-10);
9901040
/// # }
9911041
/// ```
1042+
///
1043+
/// Out-of-range values:
1044+
/// ```
1045+
/// #![feature(f128)]
1046+
/// # #[cfg(reliable_f128_math)] {
1047+
///
1048+
/// assert_eq!((-1.0_f128).ln_1p(), f128::NEG_INFINITY);
1049+
/// assert!((-2.0_f128).ln_1p().is_nan());
1050+
/// # }
1051+
/// ```
9921052
#[inline]
9931053
#[doc(alias = "log1p")]
9941054
#[must_use = "method returns a new number and does not mutate the original value"]

0 commit comments

Comments
 (0)