diff options
| author | Michael Goulet <michael@errs.io> | 2025-07-20 17:44:55 +0000 | 
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-07-20 17:45:01 +0000 | 
| commit | 1e96d7a55304f8573b6dfeb5ccbdabdb407b89b9 (patch) | |
| tree | bd4a6b035e34ef145ae60090224efc8de666ed7e /compiler/rustc_trait_selection/src/traits/util.rs | |
| parent | 0864097cd31ee30f5081ba588a5c9820c2c6fc71 (diff) | |
| download | rust-1e96d7a55304f8573b6dfeb5ccbdabdb407b89b9.tar.gz rust-1e96d7a55304f8573b6dfeb5ccbdabdb407b89b9.zip | |
Consider param-env for fast path
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits/util.rs')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/util.rs | 20 | 
1 files changed, 19 insertions, 1 deletions
| diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 0c14b124e25..c3d60ec45c4 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -365,7 +365,11 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for PlaceholderReplacer<'_, 'tcx> { } } -pub fn sizedness_fast_path<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tcx>) -> bool { +pub fn sizedness_fast_path<'tcx>( + tcx: TyCtxt<'tcx>, + predicate: ty::Predicate<'tcx>, + param_env: ty::ParamEnv<'tcx>, +) -> bool { // Proving `Sized`/`MetaSized`, very often on "obviously sized" types like // `&T`, accounts for about 60% percentage of the predicates we have to prove. No need to // canonicalize and all that for such cases. @@ -390,6 +394,20 @@ pub fn sizedness_fast_path<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc debug!("fast path -- trivial sizedness"); return true; } + + if matches!(trait_pred.self_ty().kind(), ty::Param(_) | ty::Placeholder(_)) { + for clause in param_env.caller_bounds() { + if let ty::ClauseKind::Trait(clause_pred) = clause.kind().skip_binder() + && clause_pred.polarity == ty::PredicatePolarity::Positive + && clause_pred.self_ty() == trait_pred.self_ty() + && (clause_pred.def_id() == trait_pred.def_id() + || (sizedness == SizedTraitKind::MetaSized + && tcx.is_lang_item(clause_pred.def_id(), LangItem::Sized))) + { + return true; + } + } + } } false | 
