]> git.lizzy.rs Git - rust.git/blob - src/librustc_infer/traits/query/type_op/prove_predicate.rs
Update const_forget.rs
[rust.git] / src / librustc_infer / traits / query / type_op / prove_predicate.rs
1 use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
2 use crate::traits::query::Fallible;
3 use rustc::ty::{ParamEnvAnd, Predicate, TyCtxt};
4
5 pub use rustc::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 Predicate::Trait(trait_ref, _) = key.value.predicate {
19             if let Some(sized_def_id) = tcx.lang_items().sized_trait() {
20                 if trait_ref.def_id() == sized_def_id {
21                     if trait_ref.skip_binder().self_ty().is_trivially_sized(tcx) {
22                         return Some(());
23                     }
24                 }
25             }
26         }
27
28         None
29     }
30
31     fn perform_query(
32         tcx: TyCtxt<'tcx>,
33         canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
34     ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
35         tcx.type_op_prove_predicate(canonicalized)
36     }
37 }