Skip to content

Commit 4cb5e4f

Browse files
committed
Auto merge of #160863 - JonathanBrouwer:rollup-RAWntd8, r=<try>
Rollup of 9 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple-1 try-job: aarch64-apple-2 try-job: x86_64-mingw-1 try-job: i686-msvc-1 try-job: i686-msvc-2
2 parents ea06042 + cd6c365 commit 4cb5e4f

47 files changed

Lines changed: 568 additions & 103 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,25 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
647647
None
648648
}
649649
} else {
650+
// We are not checking dereferenceability, but we still want to ensure that the pointer
651+
// *could* be dereferenceable in *some* memory: we have to be able to compute the
652+
// address at the end of this range without overflowing..
653+
let scalar = Scalar::from_maybe_pointer(place.ptr(), self.ecx);
654+
// Skip this if we don't know the absolute address (during CTFE).
655+
if let Ok(addr) = scalar.try_to_scalar_int() {
656+
// Try to compute the end address.
657+
let addr = Size::from_bytes(addr.to_target_usize(*self.ecx.tcx));
658+
if addr.checked_add(size, self.ecx).is_none() {
659+
throw_validation_failure!(
660+
self.path,
661+
format!(
662+
"encountered a {ptr_kind} that is too close to the end of the address space for a pointee of {} bytes",
663+
size.bytes(),
664+
)
665+
)
666+
}
667+
}
668+
650669
// Pointer remains unchanged.
651670
None
652671
};
@@ -658,20 +677,6 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
658677
self.reset_pointer_provenance(value, &ptr)?;
659678
}
660679

661-
// Check alignment after dereferenceable (if both are violated, trigger the error above).
662-
try_validation!(
663-
self.ecx.check_ptr_align(
664-
place.ptr(),
665-
align,
666-
),
667-
self.path,
668-
Ub(AlignmentCheckFailed(Misalignment { required, has }, _msg)) => format!(
669-
"encountered an unaligned {ptr_kind} (required {required_bytes} byte alignment but found {found_bytes})",
670-
required_bytes = required.bytes(),
671-
found_bytes = has.bytes()
672-
),
673-
);
674-
675680
// Make sure this is non-null. This is obviously needed when `may_dangle` is set,
676681
// but even if we did check dereferenceability above that would still allow null
677682
// pointers if `size` is zero.
@@ -686,6 +691,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
686691
)
687692
)
688693
}
694+
689695
// Do not allow references to uninhabited types.
690696
if !place.layout.ty.is_opsem_inhabited(*self.ecx.tcx, self.ecx.typing_env) {
691697
let ty = place.layout.ty;
@@ -695,6 +701,20 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
695701
)
696702
}
697703

704+
// Check alignment after dereferenceable (if both are violated, trigger the error above).
705+
try_validation!(
706+
self.ecx.check_ptr_align(
707+
place.ptr(),
708+
align,
709+
),
710+
self.path,
711+
Ub(AlignmentCheckFailed(Misalignment { required, has }, _msg)) => format!(
712+
"encountered an unaligned {ptr_kind} (required {required_bytes} byte alignment but found {found_bytes})",
713+
required_bytes = required.bytes(),
714+
found_bytes = has.bytes()
715+
),
716+
);
717+
698718
// Recursive checking (but not inside `MaybeDangling` of course).
699719
if let Some(ref_tracking) = self.ref_tracking.as_deref_mut()
700720
&& !self.may_dangle

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11921192
// Type check the pattern. Override if necessary to avoid knock-on errors.
11931193
self.check_pat_top(decl.pat, decl_ty, ty_span, origin_expr, Some(decl.origin));
11941194
let pat_ty = self.node_ty(decl.pat.hir_id);
1195+
if decl.ty.is_none()
1196+
&& decl.init.is_none()
1197+
&& !matches!(decl.pat.kind, hir::PatKind::Binding(.., None) | hir::PatKind::Wild)
1198+
{
1199+
self.register_wf_obligation(
1200+
decl_ty.into(),
1201+
decl.pat.span,
1202+
ObligationCauseCode::WellFormed(None),
1203+
);
1204+
}
11951205
self.overwrite_local_ty_if_err(decl.hir_id, decl.pat, pat_ty);
11961206

11971207
if let Some(blk) = decl.origin.try_get_else() {

compiler/rustc_infer/src/infer/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
372372
use rustc_data_structures::undo_log::UndoLogs;
373373

374374
use crate::infer::UndoLog;
375-
inner.undo_log.push(UndoLog::PushSolverRegionConstraint);
375+
let previous_was_and = inner.solver_region_constraint_storage.is_and();
376+
inner.undo_log.push(UndoLog::PushSolverRegionConstraint { previous_was_and });
376377
inner.solver_region_constraint_storage.push(c);
377378
}
378379

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,12 +1895,21 @@ impl<'tcx> SolverRegionConstraintStorage<'tcx> {
18951895
self.0.clone()
18961896
}
18971897

1898-
fn pop(&mut self) -> Option<SolverRegionConstraint<'tcx>> {
1898+
fn is_and(&self) -> bool {
1899+
self.0.is_and()
1900+
}
1901+
1902+
fn pop(&mut self, previous_was_and: bool) -> Option<SolverRegionConstraint<'tcx>> {
18991903
match &mut self.0 {
19001904
SolverRegionConstraint::And(and) => {
19011905
let mut and = core::mem::take(and).into_iter().collect::<Vec<_>>();
19021906
let popped = and.pop()?;
1903-
self.0 = SolverRegionConstraint::And(and.into_boxed_slice());
1907+
if previous_was_and {
1908+
self.0 = SolverRegionConstraint::And(and.into_boxed_slice());
1909+
} else {
1910+
assert_eq!(and.len(), 1);
1911+
self.0 = and.pop().unwrap();
1912+
}
19041913
Some(popped)
19051914
}
19061915
_ => unreachable!(),
@@ -1909,26 +1918,21 @@ impl<'tcx> SolverRegionConstraintStorage<'tcx> {
19091918

19101919
#[instrument(level = "debug")]
19111920
fn push(&mut self, constraint: SolverRegionConstraint<'tcx>) {
1912-
match &mut self.0 {
1921+
match core::mem::replace(&mut self.0, SolverRegionConstraint::new_true()) {
19131922
SolverRegionConstraint::And(and) => {
1914-
let and = core::mem::take(and)
1915-
.into_iter()
1916-
.chain([constraint])
1917-
.collect::<Vec<_>>()
1918-
.into_boxed_slice();
1923+
let and =
1924+
and.into_iter().chain([constraint]).collect::<Vec<_>>().into_boxed_slice();
19191925
self.0 = SolverRegionConstraint::And(and);
19201926
}
1921-
_ => unreachable!(),
1927+
previous => {
1928+
self.0 = SolverRegionConstraint::And(Box::new([previous, constraint]));
1929+
}
19221930
}
19231931
}
19241932

19251933
#[instrument(level = "debug", skip(self))]
19261934
fn overwrite_solver_region_constraint(&mut self, constraint: SolverRegionConstraint<'tcx>) {
1927-
if !constraint.is_and() {
1928-
self.0 = SolverRegionConstraint::And(vec![constraint].into_boxed_slice())
1929-
} else {
1930-
self.0 = constraint;
1931-
}
1935+
self.0 = constraint;
19321936
}
19331937
}
19341938

compiler/rustc_infer/src/infer/snapshot/undo_log.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) enum UndoLog<'tcx> {
2828
RegionUnificationTable(sv::UndoLog<ut::Delegate<RegionVidKey<'tcx>>>),
2929
ProjectionCache(traits::UndoLog<'tcx>),
3030
PushTypeOutlivesConstraint,
31-
PushSolverRegionConstraint,
31+
PushSolverRegionConstraint { previous_was_and: bool },
3232
OverwriteSolverRegionConstraint { old_constraint: SolverRegionConstraint<'tcx> },
3333
PushRegionAssumption,
3434
PushHirTypeckPotentiallyRegionDependentGoal,
@@ -79,8 +79,8 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for InferCtxtInner<'tcx> {
7979
self.region_constraint_storage.as_mut().unwrap().unification_table.reverse(undo)
8080
}
8181
UndoLog::ProjectionCache(undo) => self.projection_cache.reverse(undo),
82-
UndoLog::PushSolverRegionConstraint => {
83-
let popped = self.solver_region_constraint_storage.pop();
82+
UndoLog::PushSolverRegionConstraint { previous_was_and } => {
83+
let popped = self.solver_region_constraint_storage.pop(previous_was_and);
8484
assert_matches!(
8585
popped,
8686
Some(_),

compiler/rustc_mir_transform/src/sroa.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ fn escaping_locals<'tcx>(
6969
return true;
7070
}
7171
if let ty::Adt(def, _args) = ty.kind()
72-
&& (def.repr().simd() || tcx.is_lang_item(def.did(), LangItem::DynMetadata))
72+
&& (def.repr().simd()
73+
|| def.repr().scalable()
74+
|| tcx.is_lang_item(def.did(), LangItem::DynMetadata))
7375
{
7476
// Exclude #[repr(simd)] types so that they are not de-optimized into an array
7577
// (MCP#838 banned projections into SIMD types, but if the value is unused

compiler/rustc_mir_transform/src/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
707707
);
708708
}
709709

710-
if adt_def.repr().simd() {
710+
if adt_def.repr().simd() || adt_def.repr().scalable() {
711711
self.fail(
712712
location,
713713
format!(

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::ControlFlow;
55
use rustc_macros::StableHash;
66
use rustc_type_ir::data_structures::HashSet;
77
use rustc_type_ir::inherent::*;
8-
use rustc_type_ir::region_constraint::RegionConstraint;
8+
use rustc_type_ir::region_constraint::{RegionConstraint, evaluate_solver_constraint};
99
use rustc_type_ir::relate::Relate;
1010
use rustc_type_ir::relate::solver_relating::RelateExt;
1111
use rustc_type_ir::search_graph::{CandidateHeadUsages, LowerAvailableDepth, PathKind};
@@ -1656,7 +1656,12 @@ where
16561656
// `tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.rs`.
16571657
let region_constraints = if self.cx().assumptions_on_binders() {
16581658
ExternalRegionConstraints::NextGen(if let Certainty::Yes = certainty {
1659-
self.delegate.get_solver_region_constraint()
1659+
let constraint = self.delegate.get_solver_region_constraint();
1660+
debug_assert_eq!(
1661+
constraint,
1662+
evaluate_solver_constraint(&constraint.clone().canonical_form())
1663+
);
1664+
constraint
16601665
} else {
16611666
RegionConstraint::new_true()
16621667
})

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/solver_region_constraints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_type_ir::outlives::{Component, push_outlives_components};
99
use rustc_type_ir::region_constraint::TransitiveRelationBuilder;
1010
use rustc_type_ir::region_constraint::{
1111
Assumptions, RegionConstraint, eagerly_handle_placeholders_in_universe,
12+
evaluate_solver_constraint,
1213
};
1314
use rustc_type_ir::{
1415
AliasTy, Binder, ClauseKind, InferCtxtLike, Interner, OutlivesClause, Region, TypeVisitable,
@@ -136,6 +137,7 @@ where
136137
.fold(constraint, |constraint, u| {
137138
eagerly_handle_placeholders_in_universe(&**self.delegate, constraint, u)
138139
});
140+
let constraint = evaluate_solver_constraint(&constraint.canonical_form());
139141

140142
self.delegate.overwrite_solver_region_constraint(constraint.clone());
141143

compiler/rustc_resolve/src/diagnostics/impls.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2973,7 +2973,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
29732973
};
29742974
let scope = match &path[..failed_segment_idx] {
29752975
[.., prev] => {
2976-
if prev.ident.name == kw::PathRoot {
2976+
if prev.ident.name == kw::PathRoot && self.tcx.sess.edition() > Edition::Edition2015
2977+
{
2978+
format!("the list of imported crates")
2979+
} else if prev.ident.name == kw::PathRoot || prev.ident.name == kw::Crate {
29772980
format!("the crate root")
29782981
} else {
29792982
format!("`{}`", prev.ident)

0 commit comments

Comments
 (0)