1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use infer
::canonical
::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse}
;
12 use traits
::query
::Fallible
;
13 use ty
::{ParamEnvAnd, Predicate, TyCtxt}
;
15 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
16 pub struct ProvePredicate
<'tcx
> {
17 pub predicate
: Predicate
<'tcx
>,
20 impl<'tcx
> ProvePredicate
<'tcx
> {
21 pub fn new(predicate
: Predicate
<'tcx
>) -> Self {
22 ProvePredicate { predicate }
26 impl<'gcx
: 'tcx
, 'tcx
> super::QueryTypeOp
<'gcx
, 'tcx
> for ProvePredicate
<'tcx
> {
27 type QueryResponse
= ();
30 tcx
: TyCtxt
<'_
, 'gcx
, 'tcx
>,
31 key
: &ParamEnvAnd
<'tcx
, Self>,
32 ) -> Option
<Self::QueryResponse
> {
33 // Proving Sized, very often on "obviously sized" types like
34 // `&T`, accounts for about 60% percentage of the predicates
35 // we have to prove. No need to canonicalize and all that for
37 if let Predicate
::Trait(trait_ref
) = key
.value
.predicate
{
38 if let Some(sized_def_id
) = tcx
.lang_items().sized_trait() {
39 if trait_ref
.def_id() == sized_def_id
{
40 if trait_ref
.skip_binder().self_ty().is_trivially_sized(tcx
) {
51 tcx
: TyCtxt
<'_
, 'gcx
, 'tcx
>,
52 canonicalized
: Canonicalized
<'gcx
, ParamEnvAnd
<'tcx
, Self>>,
53 ) -> Fallible
<CanonicalizedQueryResponse
<'gcx
, ()>> {
54 tcx
.type_op_prove_predicate(canonicalized
)
57 fn shrink_to_tcx_lifetime(
58 v
: &'a CanonicalizedQueryResponse
<'gcx
, ()>,
59 ) -> &'a Canonical
<'tcx
, QueryResponse
<'tcx
, ()>> {
64 BraceStructTypeFoldableImpl
! {
65 impl<'tcx
> TypeFoldable
<'tcx
> for ProvePredicate
<'tcx
> {
70 BraceStructLiftImpl
! {
71 impl<'a
, 'tcx
> Lift
<'tcx
> for ProvePredicate
<'a
> {
72 type Lifted
= ProvePredicate
<'tcx
>;
77 impl_stable_hash_for
! {
78 struct ProvePredicate
<'tcx
> { predicate }