]> git.proxmox.com Git - rustc.git/blame - src/librustc/traits/query/type_op/subtype.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc / traits / query / type_op / subtype.rs
CommitLineData
e74abb32 1use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
9fa01778
XL
2use crate::traits::query::Fallible;
3use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
8faf50e0 4
60c5eb7d 5#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, Lift)]
8faf50e0
XL
6pub struct Subtype<'tcx> {
7 pub sub: Ty<'tcx>,
8 pub sup: Ty<'tcx>,
9}
10
11impl<'tcx> Subtype<'tcx> {
12 pub fn new(sub: Ty<'tcx>, sup: Ty<'tcx>) -> Self {
13 Self {
14 sub,
15 sup,
16 }
17 }
18}
19
dc9dc135 20impl<'tcx> super::QueryTypeOp<'tcx> for Subtype<'tcx> {
0bf4aa26 21 type QueryResponse = ();
8faf50e0 22
dc9dc135 23 fn try_fast_path(_tcx: TyCtxt<'tcx>, key: &ParamEnvAnd<'tcx, Self>) -> Option<()> {
8faf50e0
XL
24 if key.value.sub == key.value.sup {
25 Some(())
26 } else {
27 None
28 }
29 }
30
31 fn perform_query(
dc9dc135
XL
32 tcx: TyCtxt<'tcx>,
33 canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
34 ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
8faf50e0
XL
35 tcx.type_op_subtype(canonicalized)
36 }
8faf50e0 37}