]> git.lizzy.rs Git - rust.git/blob - src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs
24551299df252649a45038b004f5c38a96f42b09
[rust.git] / src / librustc_trait_selection / traits / query / type_op / prove_predicate.rs
1 use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
2 use crate::traits::query::Fallible;
3 use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt};
4
5 pub use rustc_middle::traits::query::type_op::ProvePredicate;
6
7 impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
8     type QueryResponse = ();
9
10     fn try_fast_path(
11         tcx: TyCtxt<'tcx>,
12         key: &ParamEnvAnd<'tcx, Self>,
13     ) -> Option<Self::QueryResponse> {
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.
18         if let ty::PredicateKind::Trait(trait_ref, _) =
19             key.value.predicate.ignore_quantifiers().skip_binder().kind()
20         {
21             if let Some(sized_def_id) = tcx.lang_items().sized_trait() {
22                 if trait_ref.def_id() == sized_def_id {
23                     if trait_ref.self_ty().is_trivially_sized(tcx) {
24                         return Some(());
25                     }
26                 }
27             }
28         }
29
30         None
31     }
32
33     fn perform_query(
34         tcx: TyCtxt<'tcx>,
35         canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
36     ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
37         tcx.type_op_prove_predicate(canonicalized)
38     }
39 }