Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_infer/src/infer/outlives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down