]> git.lizzy.rs Git - rust.git/blob - src/librustc/traits/query/type_op/prove_predicate.rs
Add `constness` field to `ty::Predicate::Trait`
[rust.git] / src / librustc / traits / query / type_op / prove_predicate.rs
1 use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
2 use crate::traits::query::Fallible;
3 use crate::ty::{ParamEnvAnd, Predicate, TyCtxt};
4
5 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, Lift)]
6 pub struct ProvePredicate<'tcx> {
7     pub predicate: Predicate<'tcx>,
8 }
9
10 impl<'tcx> ProvePredicate<'tcx> {
11     pub fn new(predicate: Predicate<'tcx>) -> Self {
12         ProvePredicate { predicate }
13     }
14 }
15
16 impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
17     type QueryResponse = ();
18
19     fn try_fast_path(
20         tcx: TyCtxt<'tcx>,
21         key: &ParamEnvAnd<'tcx, Self>,
22     ) -> Option<Self::QueryResponse> {
23         // Proving Sized, very often on "obviously sized" types like
24         // `&T`, accounts for about 60% percentage of the predicates
25         // we have to prove. No need to canonicalize and all that for
26         // such cases.
27         if let Predicate::Trait(trait_ref, _) = key.value.predicate {
28             if let Some(sized_def_id) = tcx.lang_items().sized_trait() {
29                 if trait_ref.def_id() == sized_def_id {
30                     if trait_ref.skip_binder().self_ty().is_trivially_sized(tcx) {
31                         return Some(());
32                     }
33                 }
34             }
35         }
36
37         None
38     }
39
40     fn perform_query(
41         tcx: TyCtxt<'tcx>,
42         canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
43     ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
44         tcx.type_op_prove_predicate(canonicalized)
45     }
46 }