Skip to content

Commit caccb4d

Browse files
committed
Auto merge of #146999 - matthiaskrgr:rollup-0gbkm82, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #146711 (fix 2 borrowck issues) - #146857 (revert change removing `has_infer` check. Commit conservatively patch…) - #146897 (fix ICE in rustdoc::invalid_html_tags) - #146915 (Make missed precondition-free float intrinsics safe) - #146932 (Switch next-solver related rustc dependencies of r-a to crates.io ones) - #146959 (temporary-lifetime-extension-tuple-ctor.rs: make usable on all editions) - #146964 (library: std: sys: pal: uefi: Add some comments) - #146969 (const-eval: better wording for errors involving maybe-null pointers) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 15283f6 + ec378dc commit caccb4d

File tree

38 files changed

+385
-114
lines changed

38 files changed

+385
-114
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,9 +1736,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
17361736
// `BoringNoLocation` constraints can point to user-written code, but are less
17371737
// specific, and are not used for relations that would make sense to blame.
17381738
ConstraintCategory::BoringNoLocation => 6,
1739-
// Do not blame internal constraints.
1740-
ConstraintCategory::OutlivesUnnameablePlaceholder(_) => 7,
1741-
ConstraintCategory::Internal => 8,
1739+
// Do not blame internal constraints if we can avoid it. Never blame
1740+
// the `'region: 'static` constraints introduced by placeholder outlives.
1741+
ConstraintCategory::Internal => 7,
1742+
ConstraintCategory::OutlivesUnnameablePlaceholder(_) => 8,
17421743
};
17431744

17441745
debug!("constraint {constraint:?} category: {category:?}, interest: {interest:?}");

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
505505
let mut constraints = Default::default();
506506
let mut liveness_constraints =
507507
LivenessValues::without_specific_points(Rc::new(DenseLocationMap::new(promoted_body)));
508+
let mut deferred_closure_requirements = Default::default();
508509

509510
// Don't try to add borrow_region facts for the promoted MIR as they refer
510511
// to the wrong locations.
511512
let mut swap_constraints = |this: &mut Self| {
512513
mem::swap(this.polonius_facts, polonius_facts);
513514
mem::swap(&mut this.constraints.outlives_constraints, &mut constraints);
514515
mem::swap(&mut this.constraints.liveness_constraints, &mut liveness_constraints);
516+
mem::swap(this.deferred_closure_requirements, &mut deferred_closure_requirements);
515517
};
516518

517519
swap_constraints(self);
@@ -536,6 +538,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
536538
}
537539
self.constraints.outlives_constraints.push(constraint)
538540
}
541+
542+
// If there are nested bodies in promoteds, we also need to update their
543+
// location to something in the actual body, not the promoted.
544+
//
545+
// We don't update the constraint categories of the resulting constraints
546+
// as returns in nested bodies are a proper return, even if that nested body
547+
// is in a promoted.
548+
for (closure_def_id, args, _locations) in deferred_closure_requirements {
549+
self.deferred_closure_requirements.push((closure_def_id, args, locations));
550+
}
551+
539552
// If the region is live at least one location in the promoted MIR,
540553
// then add a liveness constraint to the main MIR for this region
541554
// at the location provided as an argument to this method

compiler/rustc_const_eval/messages.ftl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,20 @@ const_eval_validation_invalid_vtable_trait = {$front_matter}: wrong trait in wid
476476
const_eval_validation_mutable_ref_in_const = {$front_matter}: encountered mutable reference in `const` value
477477
const_eval_validation_mutable_ref_to_immutable = {$front_matter}: encountered mutable reference or box pointing to read-only memory
478478
const_eval_validation_never_val = {$front_matter}: encountered a value of the never type `!`
479-
const_eval_validation_null_box = {$front_matter}: encountered a null box
479+
const_eval_validation_null_box = {$front_matter}: encountered a {$maybe ->
480+
[true] maybe-null
481+
*[false] null
482+
} box
480483
const_eval_validation_null_fn_ptr = {$front_matter}: encountered a null function pointer
481-
const_eval_validation_null_ref = {$front_matter}: encountered a null reference
482-
const_eval_validation_nullable_ptr_out_of_range = {$front_matter}: encountered a potentially null pointer, but expected something that cannot possibly fail to be {$in_range}
484+
const_eval_validation_null_ref = {$front_matter}: encountered a {$maybe ->
485+
[true] maybe-null
486+
*[false] null
487+
} reference
488+
const_eval_validation_nonnull_ptr_out_of_range = {$front_matter}: encountered a maybe-null pointer, but expected something that is definitely non-zero
483489
const_eval_validation_out_of_range = {$front_matter}: encountered {$value}, but expected something {$in_range}
484490
const_eval_validation_partial_pointer = {$front_matter}: encountered a partial pointer or a mix of pointers
485491
const_eval_validation_pointer_as_int = {$front_matter}: encountered a pointer, but {$expected}
486-
const_eval_validation_ptr_out_of_range = {$front_matter}: encountered a pointer, but expected something that cannot possibly fail to be {$in_range}
492+
const_eval_validation_ptr_out_of_range = {$front_matter}: encountered a pointer with unknown absolute address, but expected something that is definitely {$in_range}
487493
const_eval_validation_ref_to_uninhabited = {$front_matter}: encountered a reference pointing to uninhabited type {$ty}
488494
const_eval_validation_unaligned_box = {$front_matter}: encountered an unaligned box (required {$required_bytes} byte alignment but found {$found_bytes})
489495
const_eval_validation_unaligned_ref = {$front_matter}: encountered an unaligned reference (required {$required_bytes} byte alignment but found {$found_bytes})

compiler/rustc_const_eval/src/errors.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
668668
MutableRefInConst => const_eval_validation_mutable_ref_in_const,
669669
NullFnPtr => const_eval_validation_null_fn_ptr,
670670
NeverVal => const_eval_validation_never_val,
671-
NullablePtrOutOfRange { .. } => const_eval_validation_nullable_ptr_out_of_range,
671+
NonnullPtrMaybeNull { .. } => const_eval_validation_nonnull_ptr_out_of_range,
672672
PtrOutOfRange { .. } => const_eval_validation_ptr_out_of_range,
673673
OutOfRange { .. } => const_eval_validation_out_of_range,
674674
UnsafeCellInImmutable => const_eval_validation_unsafe_cell,
@@ -696,8 +696,8 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
696696
}
697697
UnalignedPtr { ptr_kind: PointerKind::Box, .. } => const_eval_validation_unaligned_box,
698698

699-
NullPtr { ptr_kind: PointerKind::Box } => const_eval_validation_null_box,
700-
NullPtr { ptr_kind: PointerKind::Ref(_) } => const_eval_validation_null_ref,
699+
NullPtr { ptr_kind: PointerKind::Box, .. } => const_eval_validation_null_box,
700+
NullPtr { ptr_kind: PointerKind::Ref(_), .. } => const_eval_validation_null_ref,
701701
DanglingPtrNoProvenance { ptr_kind: PointerKind::Box, .. } => {
702702
const_eval_validation_dangling_box_no_provenance
703703
}
@@ -804,9 +804,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
804804
| InvalidFnPtr { value } => {
805805
err.arg("value", value);
806806
}
807-
NullablePtrOutOfRange { range, max_value } | PtrOutOfRange { range, max_value } => {
808-
add_range_arg(range, max_value, err)
809-
}
807+
PtrOutOfRange { range, max_value } => add_range_arg(range, max_value, err),
810808
OutOfRange { range, max_value, value } => {
811809
err.arg("value", value);
812810
add_range_arg(range, max_value, err);
@@ -822,10 +820,13 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
822820
err.arg("vtable_dyn_type", vtable_dyn_type.to_string());
823821
err.arg("expected_dyn_type", expected_dyn_type.to_string());
824822
}
825-
NullPtr { .. }
826-
| MutableRefToImmutable
823+
NullPtr { maybe, .. } => {
824+
err.arg("maybe", maybe);
825+
}
826+
MutableRefToImmutable
827827
| MutableRefInConst
828828
| NullFnPtr
829+
| NonnullPtrMaybeNull
829830
| NeverVal
830831
| UnsafeCellInImmutable
831832
| InvalidMetaSliceTooLarge { .. }

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
511511
CheckInAllocMsg::Dereferenceable, // will anyway be replaced by validity message
512512
),
513513
self.path,
514-
Ub(DanglingIntPointer { addr: 0, .. }) => NullPtr { ptr_kind },
514+
Ub(DanglingIntPointer { addr: 0, .. }) => NullPtr { ptr_kind, maybe: false },
515515
Ub(DanglingIntPointer { addr: i, .. }) => DanglingPtrNoProvenance {
516516
ptr_kind,
517517
// FIXME this says "null pointer" when null but we need translate
@@ -538,8 +538,10 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
538538
);
539539
// Make sure this is non-null. We checked dereferenceability above, but if `size` is zero
540540
// that does not imply non-null.
541-
if self.ecx.scalar_may_be_null(Scalar::from_maybe_pointer(place.ptr(), self.ecx))? {
542-
throw_validation_failure!(self.path, NullPtr { ptr_kind })
541+
let scalar = Scalar::from_maybe_pointer(place.ptr(), self.ecx);
542+
if self.ecx.scalar_may_be_null(scalar)? {
543+
let maybe = !M::Provenance::OFFSET_IS_ADDR && matches!(scalar, Scalar::Ptr(..));
544+
throw_validation_failure!(self.path, NullPtr { ptr_kind, maybe })
543545
}
544546
// Do not allow references to uninhabited types.
545547
if place.layout.is_uninhabited() {
@@ -757,6 +759,11 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
757759
} else {
758760
// Otherwise (for standalone Miri), we have to still check it to be non-null.
759761
if self.ecx.scalar_may_be_null(scalar)? {
762+
let maybe =
763+
!M::Provenance::OFFSET_IS_ADDR && matches!(scalar, Scalar::Ptr(..));
764+
// This can't be a "maybe-null" pointer since the check for this being
765+
// a fn ptr at all already ensures that the pointer is inbounds.
766+
assert!(!maybe);
760767
throw_validation_failure!(self.path, NullFnPtr);
761768
}
762769
}
@@ -819,10 +826,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
819826
if start == 1 && end == max_value {
820827
// Only null is the niche. So make sure the ptr is NOT null.
821828
if self.ecx.scalar_may_be_null(scalar)? {
822-
throw_validation_failure!(
823-
self.path,
824-
NullablePtrOutOfRange { range: valid_range, max_value }
825-
)
829+
throw_validation_failure!(self.path, NonnullPtrMaybeNull)
826830
} else {
827831
return interp_ok(());
828832
}

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
9090
| sym::contract_check_ensures
9191
| sym::contract_check_requires
9292
| sym::contract_checks
93+
| sym::copysignf16
94+
| sym::copysignf32
95+
| sym::copysignf64
96+
| sym::copysignf128
9397
| sym::cosf16
9498
| sym::cosf32
9599
| sym::cosf64
@@ -106,6 +110,10 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
106110
| sym::expf32
107111
| sym::expf64
108112
| sym::expf128
113+
| sym::fabsf16
114+
| sym::fabsf32
115+
| sym::fabsf64
116+
| sym::fabsf128
109117
| sym::fadd_algebraic
110118
| sym::fdiv_algebraic
111119
| sym::floorf16

compiler/rustc_middle/src/mir/interpret/error.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,7 @@ pub enum ValidationErrorKind<'tcx> {
499499
MutableRefInConst,
500500
NullFnPtr,
501501
NeverVal,
502-
NullablePtrOutOfRange {
503-
range: WrappingRange,
504-
max_value: u128,
505-
},
502+
NonnullPtrMaybeNull,
506503
PtrOutOfRange {
507504
range: WrappingRange,
508505
max_value: u128,
@@ -544,6 +541,8 @@ pub enum ValidationErrorKind<'tcx> {
544541
},
545542
NullPtr {
546543
ptr_kind: PointerKind,
544+
/// Records whether this pointer is definitely null or just may be null.
545+
maybe: bool,
547546
},
548547
DanglingPtrNoProvenance {
549548
ptr_kind: PointerKind,

compiler/rustc_middle/src/ty/util.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,6 @@ impl<'tcx> Ty<'tcx> {
13681368
/// 2229 drop reorder migration analysis.
13691369
#[inline]
13701370
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> bool {
1371-
assert!(!self.has_non_region_infer());
13721371
// Avoid querying in simple cases.
13731372
match needs_drop_components(tcx, self) {
13741373
Err(AlwaysRequiresDrop) => true,
@@ -1381,6 +1380,16 @@ impl<'tcx> Ty<'tcx> {
13811380
_ => self,
13821381
};
13831382

1383+
// FIXME
1384+
// We should be canonicalizing, or else moving this to a method of inference
1385+
// context, or *something* like that,
1386+
// but for now just avoid passing inference variables
1387+
// to queries that can't cope with them.
1388+
// Instead, conservatively return "true" (may change drop order).
1389+
if query_ty.has_infer() {
1390+
return true;
1391+
}
1392+
13841393
// This doesn't depend on regions, so try to minimize distinct
13851394
// query keys used.
13861395
let erased = tcx.normalize_erasing_regions(typing_env, query_ty);

library/core/src/intrinsics/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,7 +3170,7 @@ pub const fn maximumf128(x: f128, y: f128) -> f128 {
31703170
/// [`f16::abs`](../../std/primitive.f16.html#method.abs)
31713171
#[rustc_nounwind]
31723172
#[rustc_intrinsic]
3173-
pub const unsafe fn fabsf16(x: f16) -> f16;
3173+
pub const fn fabsf16(x: f16) -> f16;
31743174

31753175
/// Returns the absolute value of an `f32`.
31763176
///
@@ -3179,7 +3179,7 @@ pub const unsafe fn fabsf16(x: f16) -> f16;
31793179
#[rustc_nounwind]
31803180
#[rustc_intrinsic_const_stable_indirect]
31813181
#[rustc_intrinsic]
3182-
pub const unsafe fn fabsf32(x: f32) -> f32;
3182+
pub const fn fabsf32(x: f32) -> f32;
31833183

31843184
/// Returns the absolute value of an `f64`.
31853185
///
@@ -3188,23 +3188,23 @@ pub const unsafe fn fabsf32(x: f32) -> f32;
31883188
#[rustc_nounwind]
31893189
#[rustc_intrinsic_const_stable_indirect]
31903190
#[rustc_intrinsic]
3191-
pub const unsafe fn fabsf64(x: f64) -> f64;
3191+
pub const fn fabsf64(x: f64) -> f64;
31923192

31933193
/// Returns the absolute value of an `f128`.
31943194
///
31953195
/// The stabilized version of this intrinsic is
31963196
/// [`f128::abs`](../../std/primitive.f128.html#method.abs)
31973197
#[rustc_nounwind]
31983198
#[rustc_intrinsic]
3199-
pub const unsafe fn fabsf128(x: f128) -> f128;
3199+
pub const fn fabsf128(x: f128) -> f128;
32003200

32013201
/// Copies the sign from `y` to `x` for `f16` values.
32023202
///
32033203
/// The stabilized version of this intrinsic is
32043204
/// [`f16::copysign`](../../std/primitive.f16.html#method.copysign)
32053205
#[rustc_nounwind]
32063206
#[rustc_intrinsic]
3207-
pub const unsafe fn copysignf16(x: f16, y: f16) -> f16;
3207+
pub const fn copysignf16(x: f16, y: f16) -> f16;
32083208

32093209
/// Copies the sign from `y` to `x` for `f32` values.
32103210
///
@@ -3213,23 +3213,23 @@ pub const unsafe fn copysignf16(x: f16, y: f16) -> f16;
32133213
#[rustc_nounwind]
32143214
#[rustc_intrinsic_const_stable_indirect]
32153215
#[rustc_intrinsic]
3216-
pub const unsafe fn copysignf32(x: f32, y: f32) -> f32;
3216+
pub const fn copysignf32(x: f32, y: f32) -> f32;
32173217
/// Copies the sign from `y` to `x` for `f64` values.
32183218
///
32193219
/// The stabilized version of this intrinsic is
32203220
/// [`f64::copysign`](../../std/primitive.f64.html#method.copysign)
32213221
#[rustc_nounwind]
32223222
#[rustc_intrinsic_const_stable_indirect]
32233223
#[rustc_intrinsic]
3224-
pub const unsafe fn copysignf64(x: f64, y: f64) -> f64;
3224+
pub const fn copysignf64(x: f64, y: f64) -> f64;
32253225

32263226
/// Copies the sign from `y` to `x` for `f128` values.
32273227
///
32283228
/// The stabilized version of this intrinsic is
32293229
/// [`f128::copysign`](../../std/primitive.f128.html#method.copysign)
32303230
#[rustc_nounwind]
32313231
#[rustc_intrinsic]
3232-
pub const unsafe fn copysignf128(x: f128, y: f128) -> f128;
3232+
pub const fn copysignf128(x: f128, y: f128) -> f128;
32333233

32343234
/// Generates the LLVM body for the automatic differentiation of `f` using Enzyme,
32353235
/// with `df` as the derivative function and `args` as its arguments.

library/core/src/num/f128.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,8 +1367,7 @@ impl f128 {
13671367
#[rustc_const_unstable(feature = "f128", issue = "116909")]
13681368
#[must_use = "method returns a new number and does not mutate the original value"]
13691369
pub const fn copysign(self, sign: f128) -> f128 {
1370-
// SAFETY: this is actually a safe intrinsic
1371-
unsafe { intrinsics::copysignf128(self, sign) }
1370+
intrinsics::copysignf128(self, sign)
13721371
}
13731372

13741373
/// Float addition that allows optimizations based on algebraic rules.

0 commit comments

Comments
 (0)