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, CanonicalizedQueryResult, QueryResult}
;
12 use traits
::query
::Fallible
;
13 use ty
::{ParamEnvAnd, Ty, TyCtxt}
;
15 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
16 pub struct Subtype
<'tcx
> {
21 impl<'tcx
> Subtype
<'tcx
> {
22 pub fn new(sub
: Ty
<'tcx
>, sup
: Ty
<'tcx
>) -> Self {
30 impl<'gcx
: 'tcx
, 'tcx
> super::QueryTypeOp
<'gcx
, 'tcx
> for Subtype
<'tcx
> {
31 type QueryResult
= ();
33 fn try_fast_path(_tcx
: TyCtxt
<'_
, 'gcx
, 'tcx
>, key
: &ParamEnvAnd
<'tcx
, Self>) -> Option
<()> {
34 if key
.value
.sub
== key
.value
.sup
{
42 tcx
: TyCtxt
<'_
, 'gcx
, 'tcx
>,
43 canonicalized
: Canonicalized
<'gcx
, ParamEnvAnd
<'tcx
, Self>>,
44 ) -> Fallible
<CanonicalizedQueryResult
<'gcx
, ()>> {
45 tcx
.type_op_subtype(canonicalized
)
48 fn shrink_to_tcx_lifetime(
49 v
: &'a CanonicalizedQueryResult
<'gcx
, ()>,
50 ) -> &'a Canonical
<'tcx
, QueryResult
<'tcx
, ()>> {
55 BraceStructTypeFoldableImpl
! {
56 impl<'tcx
> TypeFoldable
<'tcx
> for Subtype
<'tcx
> {
62 BraceStructLiftImpl
! {
63 impl<'a
, 'tcx
> Lift
<'tcx
> for Subtype
<'a
> {
64 type Lifted
= Subtype
<'tcx
>;
70 impl_stable_hash_for
! {
71 struct Subtype
<'tcx
> { sub, sup }