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, CanonicalizedQueryResponse, QueryResponse};
12 use traits::query::Fallible;
13 use hir::def_id::DefId;
14 use ty::{self, ParamEnvAnd, Ty, TyCtxt};
15 use ty::subst::UserSubsts;
17 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
18 pub struct AscribeUserType<'tcx> {
20 pub variance: ty::Variance,
22 pub user_substs: UserSubsts<'tcx>,
25 impl<'tcx> AscribeUserType<'tcx> {
28 variance: ty::Variance,
30 user_substs: UserSubsts<'tcx>,
32 AscribeUserType { mir_ty, variance, def_id, user_substs }
36 impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for AscribeUserType<'tcx> {
37 type QueryResponse = ();
40 _tcx: TyCtxt<'_, 'gcx, 'tcx>,
41 _key: &ParamEnvAnd<'tcx, Self>,
42 ) -> Option<Self::QueryResponse> {
47 tcx: TyCtxt<'_, 'gcx, 'tcx>,
48 canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
49 ) -> Fallible<CanonicalizedQueryResponse<'gcx, ()>> {
50 tcx.type_op_ascribe_user_type(canonicalized)
53 fn shrink_to_tcx_lifetime(
54 v: &'a CanonicalizedQueryResponse<'gcx, ()>,
55 ) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
60 BraceStructTypeFoldableImpl! {
61 impl<'tcx> TypeFoldable<'tcx> for AscribeUserType<'tcx> {
62 mir_ty, variance, def_id, user_substs
66 BraceStructLiftImpl! {
67 impl<'a, 'tcx> Lift<'tcx> for AscribeUserType<'a> {
68 type Lifted = AscribeUserType<'tcx>;
69 mir_ty, variance, def_id, user_substs
73 impl_stable_hash_for! {
74 struct AscribeUserType<'tcx> {
75 mir_ty, variance, def_id, user_substs