diff options
| author | bors <bors@rust-lang.org> | 2025-07-20 21:29:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-07-20 21:29:18 +0000 |
| commit | 460259d14de0274b97b8801e08cb2fe5f16fdac5 (patch) | |
| tree | 5fa58c069e98871e94a13bb49cbf1d2edf02d872 /compiler/rustc_trait_selection/src/traits/util.rs | |
| parent | 9982d6462bedf1e793f7b2dbd655a4e57cdf67d4 (diff) | |
| parent | 1e96d7a55304f8573b6dfeb5ccbdabdb407b89b9 (diff) | |
| download | rust-460259d14de0274b97b8801e08cb2fe5f16fdac5.tar.gz rust-460259d14de0274b97b8801e08cb2fe5f16fdac5.zip | |
Auto merge of #143309 - compiler-errors:param-sized-fast-path, r=lcnr
Consider param-env for sizedness fast path Look up `T: Sized` in param-env if `T` is a param or placeholder (the latter is for use in the new solver).
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 |
