1 use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
2 use crate::traits::query::Fallible;
3 use crate::ty::{ParamEnvAnd, Predicate, TyCtxt};
5 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, Lift)]
6 pub struct ProvePredicate<'tcx> {
7 pub predicate: Predicate<'tcx>,
10 impl<'tcx> ProvePredicate<'tcx> {
11 pub fn new(predicate: Predicate<'tcx>) -> Self {
12 ProvePredicate { predicate }
16 impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
17 type QueryResponse = ();
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
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) {
42 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
43 ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
44 tcx.type_op_prove_predicate(canonicalized)