diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-10-10 17:07:10 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-10-15 16:24:46 -0400 |
| commit | aed6e4a0834d11cad0bf5e1ebe065eabff1f405c (patch) | |
| tree | 25f4d86f919813d744870bf7e60c97d9ce37fddb /src/librustc | |
| parent | e339e84fffb3156aaa78fbf686436de02ba4cf48 (diff) | |
| download | rust-aed6e4a0834d11cad0bf5e1ebe065eabff1f405c.tar.gz rust-aed6e4a0834d11cad0bf5e1ebe065eabff1f405c.zip | |
introduce a `UserTypeAnnotation` enum
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/ich/impls_mir.rs | 13 | ||||
| -rw-r--r-- | src/librustc/mir/mod.rs | 24 | ||||
| -rw-r--r-- | src/librustc/mir/visit.rs | 22 |
3 files changed, 43 insertions, 16 deletions
diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index 337cc0fc627..38a298d81dd 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -587,3 +587,16 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::ClosureOutlivesSubj } impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted }); + +impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::UserTypeAnnotation<'gcx> { + fn hash_stable<W: StableHasherResult>(&self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut StableHasher<W>) { + mem::discriminant(self).hash_stable(hcx, hasher); + match *self { + mir::UserTypeAnnotation::Ty(ref ty) => { + ty.hash_stable(hcx, hasher); + } + } + } +} diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 2587e19b1cb..eb4aa7ece49 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -710,7 +710,7 @@ pub struct LocalDecl<'tcx> { /// e.g. via `let x: T`, then we carry that type here. The MIR /// borrow checker needs this information since it can affect /// region inference. - pub user_ty: Option<(CanonicalTy<'tcx>, Span)>, + pub user_ty: Option<(UserTypeAnnotation<'tcx>, Span)>, /// Name of the local, used in debuginfo and pretty-printing. /// @@ -1737,7 +1737,7 @@ pub enum StatementKind<'tcx> { /// - `Contravariant` -- requires that `T_y :> T` /// - `Invariant` -- requires that `T_y == T` /// - `Bivariant` -- no effect - AscribeUserType(Place<'tcx>, ty::Variance, CanonicalTy<'tcx>), + AscribeUserType(Place<'tcx>, ty::Variance, UserTypeAnnotation<'tcx>), /// No-op. Useful for deleting instructions without affecting statement indices. Nop, @@ -2188,7 +2188,7 @@ pub enum AggregateKind<'tcx> { &'tcx AdtDef, usize, &'tcx Substs<'tcx>, - Option<CanonicalTy<'tcx>>, + Option<UserTypeAnnotation<'tcx>>, Option<usize>, ), @@ -2392,7 +2392,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { /// this does not necessarily mean that they are "==" in Rust -- in /// particular one must be wary of `NaN`! -#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] pub struct Constant<'tcx> { pub span: Span, pub ty: Ty<'tcx>, @@ -2402,11 +2402,25 @@ pub struct Constant<'tcx> { /// indicate that `Vec<_>` was explicitly specified. /// /// Needed for NLL to impose user-given type constraints. - pub user_ty: Option<CanonicalTy<'tcx>>, + pub user_ty: Option<UserTypeAnnotation<'tcx>>, pub literal: &'tcx ty::Const<'tcx>, } +/// A user-given type annotation attached to a constant. These arise +/// from constants that are named via paths, like `Foo::<A>::new` and +/// so forth. +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +pub enum UserTypeAnnotation<'tcx> { + Ty(CanonicalTy<'tcx>), +} + +EnumTypeFoldableImpl! { + impl<'tcx> TypeFoldable<'tcx> for UserTypeAnnotation<'tcx> { + (UserTypeAnnotation::Ty)(ty), + } +} + newtype_index! { pub struct Promoted { DEBUG_FORMAT = "promoted[{}]" diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 920dc88d6a8..3e92b1fd7ce 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -10,7 +10,7 @@ use hir::def_id::DefId; use ty::subst::Substs; -use ty::{CanonicalTy, ClosureSubsts, GeneratorSubsts, Region, Ty}; +use ty::{ClosureSubsts, GeneratorSubsts, Region, Ty}; use mir::*; use syntax_pos::Span; @@ -147,9 +147,9 @@ macro_rules! make_mir_visitor { fn visit_ascribe_user_ty(&mut self, place: & $($mutability)* Place<'tcx>, variance: & $($mutability)* ty::Variance, - c_ty: & $($mutability)* CanonicalTy<'tcx>, + user_ty: & $($mutability)* UserTypeAnnotation<'tcx>, location: Location) { - self.super_ascribe_user_ty(place, variance, c_ty, location); + self.super_ascribe_user_ty(place, variance, user_ty, location); } fn visit_place(&mut self, @@ -214,8 +214,8 @@ macro_rules! make_mir_visitor { self.super_ty(ty); } - fn visit_user_ty(&mut self, ty: & $($mutability)* CanonicalTy<'tcx>) { - self.super_canonical_ty(ty); + fn visit_user_type_annotation(&mut self, ty: & $($mutability)* UserTypeAnnotation<'tcx>) { + self.super_user_type_annotation(ty); } fn visit_region(&mut self, @@ -390,9 +390,9 @@ macro_rules! make_mir_visitor { StatementKind::AscribeUserType( ref $($mutability)* place, ref $($mutability)* variance, - ref $($mutability)* c_ty, + ref $($mutability)* user_ty, ) => { - self.visit_ascribe_user_ty(place, variance, c_ty, location); + self.visit_ascribe_user_ty(place, variance, user_ty, location); } StatementKind::Nop => {} } @@ -637,10 +637,10 @@ macro_rules! make_mir_visitor { fn super_ascribe_user_ty(&mut self, place: & $($mutability)* Place<'tcx>, _variance: & $($mutability)* ty::Variance, - c_ty: & $($mutability)* CanonicalTy<'tcx>, + user_ty: & $($mutability)* UserTypeAnnotation<'tcx>, location: Location) { self.visit_place(place, PlaceContext::Validate, location); - self.visit_user_ty(c_ty); + self.visit_user_type_annotation(user_ty); } fn super_place(&mut self, @@ -736,7 +736,7 @@ macro_rules! make_mir_visitor { source_info: *source_info, }); if let Some((user_ty, _)) = user_ty { - self.visit_user_ty(user_ty); + self.visit_user_type_annotation(user_ty); } self.visit_source_info(source_info); self.visit_source_scope(visibility_scope); @@ -783,7 +783,7 @@ macro_rules! make_mir_visitor { self.visit_source_scope(scope); } - fn super_canonical_ty(&mut self, _ty: & $($mutability)* CanonicalTy<'tcx>) { + fn super_user_type_annotation(&mut self, _ty: & $($mutability)* UserTypeAnnotation<'tcx>) { } fn super_ty(&mut self, _ty: & $($mutability)* Ty<'tcx>) { |
