]> git.proxmox.com Git - rustc.git/blame - src/librustc/traits/query/type_op/prove_predicate.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc / traits / query / type_op / prove_predicate.rs
CommitLineData
e74abb32 1use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
9fa01778
XL
2use crate::traits::query::Fallible;
3use crate::ty::{ParamEnvAnd, Predicate, TyCtxt};
8faf50e0 4
60c5eb7d 5#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, Lift)]
8faf50e0
XL
6pub struct ProvePredicate<'tcx> {
7 pub predicate: Predicate<'tcx>,
8}
9
10impl<'tcx> ProvePredicate<'tcx> {
11 pub fn new(predicate: Predicate<'tcx>) -> Self {
12 ProvePredicate { predicate }
13 }
14}
15
dc9dc135 16impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
0bf4aa26 17 type QueryResponse = ();
8faf50e0
XL
18
19 fn try_fast_path(
dc9dc135 20 tcx: TyCtxt<'tcx>,
b7449926 21 key: &ParamEnvAnd<'tcx, Self>,
0bf4aa26 22 ) -> Option<Self::QueryResponse> {
b7449926
XL
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
8faf50e0
XL
37 None
38 }
39
40 fn perform_query(
dc9dc135
XL
41 tcx: TyCtxt<'tcx>,
42 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
43 ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
8faf50e0
XL
44 tcx.type_op_prove_predicate(canonicalized)
45 }
8faf50e0 46}