|
| 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 | + |
| 11 | +use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse}; |
| 12 | +use mir::UserTypeAnnotation; |
| 13 | +use traits::query::Fallible; |
| 14 | +use ty::{self, ParamEnvAnd, Ty, TyCtxt}; |
| 15 | + |
| 16 | +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] |
| 17 | +pub struct AscribeUserType<'tcx> { |
| 18 | + pub mir_ty: Ty<'tcx>, |
| 19 | + pub variance: ty::Variance, |
| 20 | + pub user_ty: UserTypeAnnotation<'tcx>, |
| 21 | +} |
| 22 | + |
| 23 | +impl<'tcx> AscribeUserType<'tcx> { |
| 24 | + pub fn new( |
| 25 | + mir_ty: Ty<'tcx>, |
| 26 | + variance: ty::Variance, |
| 27 | + user_ty: UserTypeAnnotation<'tcx>, |
| 28 | + ) -> Self { |
| 29 | + AscribeUserType { mir_ty, variance, user_ty } |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for AscribeUserType<'tcx> { |
| 34 | + type QueryResponse = (); |
| 35 | + |
| 36 | + fn try_fast_path( |
| 37 | + _tcx: TyCtxt<'_, 'gcx, 'tcx>, |
| 38 | + _key: &ParamEnvAnd<'tcx, Self>, |
| 39 | + ) -> Option<Self::QueryResponse> { |
| 40 | + None |
| 41 | + } |
| 42 | + |
| 43 | + fn perform_query( |
| 44 | + tcx: TyCtxt<'_, 'gcx, 'tcx>, |
| 45 | + canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>, |
| 46 | + ) -> Fallible<CanonicalizedQueryResponse<'gcx, ()>> { |
| 47 | + tcx.type_op_ascribe_user_type(canonicalized) |
| 48 | + } |
| 49 | + |
| 50 | + fn shrink_to_tcx_lifetime( |
| 51 | + v: &'a CanonicalizedQueryResponse<'gcx, ()>, |
| 52 | + ) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> { |
| 53 | + v |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +BraceStructTypeFoldableImpl! { |
| 58 | + impl<'tcx> TypeFoldable<'tcx> for AscribeUserType<'tcx> { |
| 59 | + mir_ty, variance, user_ty |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +BraceStructLiftImpl! { |
| 64 | + impl<'a, 'tcx> Lift<'tcx> for AscribeUserType<'a> { |
| 65 | + type Lifted = AscribeUserType<'tcx>; |
| 66 | + mir_ty, variance, user_ty |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +impl_stable_hash_for! { |
| 71 | + struct AscribeUserType<'tcx> { |
| 72 | + mir_ty, variance, user_ty |
| 73 | + } |
| 74 | +} |
0 commit comments