]> git.lizzy.rs Git - rust.git/blob - src/librustc/traits/query/type_op/subtype.rs
Retire BraceStructLiftImpl.
[rust.git] / src / librustc / traits / query / type_op / subtype.rs
1 use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
2 use crate::traits::query::Fallible;
3 use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
4
5 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable, Lift)]
6 pub struct Subtype<'tcx> {
7     pub sub: Ty<'tcx>,
8     pub sup: Ty<'tcx>,
9 }
10
11 impl<'tcx> Subtype<'tcx> {
12     pub fn new(sub: Ty<'tcx>, sup: Ty<'tcx>) -> Self {
13         Self {
14             sub,
15             sup,
16         }
17     }
18 }
19
20 impl<'tcx> super::QueryTypeOp<'tcx> for Subtype<'tcx> {
21     type QueryResponse = ();
22
23     fn try_fast_path(_tcx: TyCtxt<'tcx>, key: &ParamEnvAnd<'tcx, Self>) -> Option<()> {
24         if key.value.sub == key.value.sup {
25             Some(())
26         } else {
27             None
28         }
29     }
30
31     fn perform_query(
32         tcx: TyCtxt<'tcx>,
33         canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
34     ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
35         tcx.type_op_subtype(canonicalized)
36     }
37 }
38
39 impl_stable_hash_for! {
40     struct Subtype<'tcx> { sub, sup }
41 }