diff options
| author | David Wood <david.wood2@arm.com> | 2025-03-18 03:06:17 +0000 |
|---|---|---|
| committer | David Wood <david.wood2@arm.com> | 2025-04-09 10:42:26 +0000 |
| commit | 72d17bfebbf5463dac1a7eb71c513b151b523e1f (patch) | |
| tree | 48ff8adb8dcaa040619cb11675553b3efe9cd7d4 /compiler/rustc_traits/src/codegen.rs | |
| parent | 97c966bb40756903f8aa13995629128d157f6056 (diff) | |
| download | rust-72d17bfebbf5463dac1a7eb71c513b151b523e1f.tar.gz rust-72d17bfebbf5463dac1a7eb71c513b151b523e1f.zip | |
re-use sized fast path
There's an existing fast path for the `type_op_prove_predicate` predicate, checking for trivially `Sized` types, which can be re-used when evaluating obligations within queries. This should improve performance, particularly in anticipation of new sizedness traits being added which can take advantage of this.
Diffstat (limited to 'compiler/rustc_traits/src/codegen.rs')
| -rw-r--r-- | compiler/rustc_traits/src/codegen.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler/rustc_traits/src/codegen.rs b/compiler/rustc_traits/src/codegen.rs index 4a889abfc28..88f02d16c7d 100644 --- a/compiler/rustc_traits/src/codegen.rs +++ b/compiler/rustc_traits/src/codegen.rs @@ -6,11 +6,11 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::bug; use rustc_middle::traits::CodegenObligationError; -use rustc_middle::ty::{self, PseudoCanonicalInput, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{self, PseudoCanonicalInput, TyCtxt, TypeVisitableExt, Upcast}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::traits::{ ImplSource, Obligation, ObligationCause, ObligationCtxt, ScrubbedTraitError, SelectionContext, - Unimplemented, + Unimplemented, sizedness_fast_path, }; use tracing::debug; @@ -34,6 +34,13 @@ pub(crate) fn codegen_select_candidate<'tcx>( let (infcx, param_env) = tcx.infer_ctxt().ignoring_regions().build_with_typing_env(typing_env); let mut selcx = SelectionContext::new(&infcx); + if sizedness_fast_path(tcx, trait_ref.upcast(tcx)) { + return Ok(&*tcx.arena.alloc(ImplSource::Builtin( + ty::solve::BuiltinImplSource::Trivial, + Default::default(), + ))); + } + let obligation_cause = ObligationCause::dummy(); let obligation = Obligation::new(tcx, obligation_cause, param_env, trait_ref); |
