]>
Commit | Line | Data |
---|---|---|
e74abb32 | 1 | use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse}; |
9fa01778 | 2 | use crate::traits::query::Fallible; |
f9f354fc | 3 | use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt}; |
8faf50e0 | 4 | |
ba9703b0 | 5 | pub use rustc_middle::traits::query::type_op::ProvePredicate; |
8faf50e0 | 6 | |
dc9dc135 | 7 | impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> { |
0bf4aa26 | 8 | type QueryResponse = (); |
8faf50e0 XL |
9 | |
10 | fn try_fast_path( | |
dc9dc135 | 11 | tcx: TyCtxt<'tcx>, |
b7449926 | 12 | key: &ParamEnvAnd<'tcx, Self>, |
0bf4aa26 | 13 | ) -> Option<Self::QueryResponse> { |
b7449926 XL |
14 | // Proving Sized, very often on "obviously sized" types like |
15 | // `&T`, accounts for about 60% percentage of the predicates | |
16 | // we have to prove. No need to canonicalize and all that for | |
17 | // such cases. | |
94222f64 | 18 | if let ty::PredicateKind::Trait(trait_ref) = key.value.predicate.kind().skip_binder() { |
b7449926 XL |
19 | if let Some(sized_def_id) = tcx.lang_items().sized_trait() { |
20 | if trait_ref.def_id() == sized_def_id { | |
3dfed10e | 21 | if trait_ref.self_ty().is_trivially_sized(tcx) { |
b7449926 XL |
22 | return Some(()); |
23 | } | |
24 | } | |
25 | } | |
26 | } | |
27 | ||
8faf50e0 XL |
28 | None |
29 | } | |
30 | ||
31 | fn perform_query( | |
dc9dc135 | 32 | tcx: TyCtxt<'tcx>, |
a2a8927a | 33 | mut canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>, |
dc9dc135 | 34 | ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> { |
a2a8927a XL |
35 | match canonicalized.value.value.predicate.kind().skip_binder() { |
36 | ty::PredicateKind::Trait(pred) => { | |
37 | canonicalized.value.param_env.remap_constness_with(pred.constness); | |
38 | } | |
39 | _ => canonicalized.value.param_env = canonicalized.value.param_env.without_const(), | |
40 | } | |
8faf50e0 XL |
41 | tcx.type_op_prove_predicate(canonicalized) |
42 | } | |
8faf50e0 | 43 | } |