From 765476ff7110fc40875d5c9a9207b0cecbf48793 Mon Sep 17 00:00:00 2001 From: xmakro Date: Tue, 8 Sep 2026 12:43:29 -0700 Subject: [PATCH] Check trivial MIR sizedness before interning an obligation [skip ci] --- compiler/rustc_borrowck/src/type_check/mod.rs | 27 ++++++++++++------- .../rustc_infer/src/infer/outlives/mod.rs | 10 +++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 65cced536603a..ff4636098abb1 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -690,16 +690,23 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { } if !self.tcx().features().unsized_fn_params() { - let trait_ref = ty::TraitRef::new( - tcx, - tcx.require_lang_item(LangItem::Sized, self.last_span), - [place_ty], - ); - self.prove_trait_ref( - trait_ref, - location.to_locations(), - ConstraintCategory::SizedBound, - ); + let sized = tcx.require_lang_item(LangItem::Sized, self.last_span); + // Apply the type-op's trivial Sized path before interning its + // trait reference and predicate. Preserve the full operation + // when it has region state to collect or fast paths are disabled. + let trivial = !self.infcx.next_trait_solver() + && !self.infcx.disable_trait_solver_fast_paths() + && !self.infcx.in_snapshot() + && !self.infcx.has_pending_region_state() + && place_ty.has_trivial_sizedness(tcx, ty::SizedTraitKind::Sized); + if !trivial { + let trait_ref = ty::TraitRef::new(tcx, sized, [place_ty]); + self.prove_trait_ref( + trait_ref, + location.to_locations(), + ConstraintCategory::SizedBound, + ); + } } } StatementKind::AscribeUserType((place, projection), variance) => { diff --git a/compiler/rustc_infer/src/infer/outlives/mod.rs b/compiler/rustc_infer/src/infer/outlives/mod.rs index 79c1a4fb7662f..5b80da4d7ba14 100644 --- a/compiler/rustc_infer/src/infer/outlives/mod.rs +++ b/compiler/rustc_infer/src/infer/outlives/mod.rs @@ -32,6 +32,16 @@ pub fn explicit_outlives_bounds<'tcx>( } impl<'tcx> InferCtxt<'tcx> { + pub fn has_pending_region_state(&self) -> bool { + let inner = self.inner.borrow(); + !inner.region_obligations.is_empty() + || !inner.region_assumptions.is_empty() + || inner + .region_constraint_storage + .as_ref() + .is_none_or(|storage| !storage.data.is_empty()) + } + /// Process the region constraints and return any errors that /// result. After this, no more unification operations should be /// done -- or the compiler will panic -- but it is legal to use