]> git.proxmox.com Git - rustc.git/blame - src/librustc/traits/query/type_op/subtype.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / librustc / traits / query / type_op / subtype.rs
CommitLineData
8faf50e0
XL
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.
4//
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.
10
0bf4aa26 11use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
8faf50e0
XL
12use traits::query::Fallible;
13use ty::{ParamEnvAnd, Ty, TyCtxt};
14
15#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
16pub struct Subtype<'tcx> {
17 pub sub: Ty<'tcx>,
18 pub sup: Ty<'tcx>,
19}
20
21impl<'tcx> Subtype<'tcx> {
22 pub fn new(sub: Ty<'tcx>, sup: Ty<'tcx>) -> Self {
23 Self {
24 sub,
25 sup,
26 }
27 }
28}
29
30impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Subtype<'tcx> {
0bf4aa26 31 type QueryResponse = ();
8faf50e0
XL
32
33 fn try_fast_path(_tcx: TyCtxt<'_, 'gcx, 'tcx>, key: &ParamEnvAnd<'tcx, Self>) -> Option<()> {
34 if key.value.sub == key.value.sup {
35 Some(())
36 } else {
37 None
38 }
39 }
40
41 fn perform_query(
42 tcx: TyCtxt<'_, 'gcx, 'tcx>,
43 canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
0bf4aa26 44 ) -> Fallible<CanonicalizedQueryResponse<'gcx, ()>> {
8faf50e0
XL
45 tcx.type_op_subtype(canonicalized)
46 }
47
48 fn shrink_to_tcx_lifetime(
0bf4aa26
XL
49 v: &'a CanonicalizedQueryResponse<'gcx, ()>,
50 ) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
8faf50e0
XL
51 v
52 }
53}
54
55BraceStructTypeFoldableImpl! {
56 impl<'tcx> TypeFoldable<'tcx> for Subtype<'tcx> {
57 sub,
58 sup,
59 }
60}
61
62BraceStructLiftImpl! {
63 impl<'a, 'tcx> Lift<'tcx> for Subtype<'a> {
64 type Lifted = Subtype<'tcx>;
65 sub,
66 sup,
67 }
68}
69
70impl_stable_hash_for! {
71 struct Subtype<'tcx> { sub, sup }
72}