diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 7a6852ddc55e..9b613e3e1aba 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -1240,6 +1240,12 @@ impl_stable_hash_for!( } ); +impl_stable_hash_for!( + struct ty::CanonicalUserTypeAnnotation<'tcx> { + user_ty, span + } +); + impl<'a, 'gcx> HashStable> for ty::UserType<'gcx> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 9bd0efcbbb4b..f824ab7e5b39 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -31,7 +31,7 @@ use ty::subst::{Subst, Substs}; use ty::layout::VariantIdx; use ty::{ self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt, - UserTypeAnnotationIndex, UserType, + UserTypeAnnotationIndex, }; use util::ppaux; diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 7ae77b221da7..49a1e5046aa0 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -1,7 +1,6 @@ use hir::def_id::DefId; -use infer::canonical::Canonical; use ty::subst::Substs; -use ty::{ClosureSubsts, GeneratorSubsts, Region, Ty}; +use ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Region, Ty}; use mir::*; use syntax_pos::Span; @@ -221,7 +220,7 @@ macro_rules! make_mir_visitor { fn visit_user_type_annotation( &mut self, index: UserTypeAnnotationIndex, - ty: & $($mutability)* Canonical<'tcx, UserType<'tcx>>, + ty: & $($mutability)* CanonicalUserTypeAnnotation<'tcx>, ) { self.super_user_type_annotation(index, ty); } @@ -309,12 +308,15 @@ macro_rules! make_mir_visitor { self.visit_local_decl(local, & $($mutability)* mir.local_decls[local]); } - for index in mir.user_type_annotations.indices() { - let (span, annotation) = & $($mutability)* mir.user_type_annotations[index]; + macro_rules! type_annotations { + (mut) => (mir.user_type_annotations.iter_enumerated_mut()); + () => (mir.user_type_annotations.iter_enumerated()); + }; + + for (index, annotation) in type_annotations!($($mutability)*) { self.visit_user_type_annotation( index, annotation ); - self.visit_span(span); } self.visit_span(&$($mutability)* mir.span); @@ -882,8 +884,9 @@ macro_rules! make_mir_visitor { fn super_user_type_annotation( &mut self, _index: UserTypeAnnotationIndex, - _ty: & $($mutability)* Canonical<'tcx, UserType<'tcx>>, + ty: & $($mutability)* CanonicalUserTypeAnnotation<'tcx>, ) { + self.visit_span(& $($mutability)* ty.span); } fn super_ty(&mut self, _ty: & $($mutability)* Ty<'tcx>) { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index ef8f7bd9a756..59835afc8410 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -807,7 +807,27 @@ newtype_index! { /// Mapping of type annotation indices to canonical user type annotations. pub type CanonicalUserTypeAnnotations<'tcx> = - IndexVec)>; + IndexVec>; + +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +pub struct CanonicalUserTypeAnnotation<'tcx> { + pub user_ty: CanonicalUserType<'tcx>, + pub span: Span, +} + +BraceStructTypeFoldableImpl! { + impl<'tcx> TypeFoldable<'tcx> for CanonicalUserTypeAnnotation<'tcx> { + user_ty, span + } +} + +BraceStructLiftImpl! { + impl<'a, 'tcx> Lift<'tcx> for CanonicalUserTypeAnnotation<'a> { + type Lifted = CanonicalUserTypeAnnotation<'tcx>; + user_ty, span + } +} + /// Canonicalized user type annotation. pub type CanonicalUserType<'gcx> = Canonical<'gcx, UserType<'gcx>>; diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index a6e226302e51..dc91a30ef927 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -74,7 +74,7 @@ pub use self::context::{TyCtxt, FreeRegionInfo, GlobalArenas, AllArenas, tls, ke pub use self::context::{Lift, TypeckTables, CtxtInterners}; pub use self::context::{ UserTypeAnnotationIndex, UserType, CanonicalUserType, - CanonicalUserTypeAnnotations, + CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, }; pub use self::instance::{Instance, InstanceDef}; diff --git a/src/librustc_mir/borrow_check/nll/renumber.rs b/src/librustc_mir/borrow_check/nll/renumber.rs index f6275230eebf..ade06bce4690 100644 --- a/src/librustc_mir/borrow_check/nll/renumber.rs +++ b/src/librustc_mir/borrow_check/nll/renumber.rs @@ -1,8 +1,7 @@ -use rustc::infer::canonical::Canonical; use rustc::ty::subst::Substs; use rustc::ty::{ - self, ClosureSubsts, GeneratorSubsts, Ty, TypeFoldable, UserType, - UserTypeAnnotationIndex, + self, ClosureSubsts, GeneratorSubsts, Ty, TypeFoldable, + UserTypeAnnotationIndex, CanonicalUserTypeAnnotation }; use rustc::mir::{Location, Mir}; use rustc::mir::visit::{MutVisitor, TyContext}; @@ -62,7 +61,7 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> { fn visit_user_type_annotation( &mut self, _index: UserTypeAnnotationIndex, - _ty: &mut Canonical<'tcx, UserType<'tcx>>, + _ty: &mut CanonicalUserTypeAnnotation, ) { // User type annotations represent the types that the user // wrote in the progarm. We don't want to erase the regions diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 7c3507e06cb1..82ffafa4ce97 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -38,7 +38,7 @@ use rustc::ty::fold::TypeFoldable; use rustc::ty::subst::{Subst, Substs, UnpackedKind}; use rustc::ty::{ self, RegionVid, ToPolyTraitRef, Ty, TyCtxt, TyKind, UserType, - UserTypeAnnotationIndex, + CanonicalUserTypeAnnotation, UserTypeAnnotationIndex, }; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; @@ -920,13 +920,14 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { self.mir.user_type_annotations ); for annotation_index in self.mir.user_type_annotations.indices() { - let (span, canonical_annotation) = &self.mir.user_type_annotations[annotation_index]; + let CanonicalUserTypeAnnotation { span, ref user_ty } = + self.mir.user_type_annotations[annotation_index]; let (mut annotation, _) = self.infcx.instantiate_canonical_with_fresh_inference_vars( - *span, &canonical_annotation + span, user_ty ); match annotation { UserType::Ty(ref mut ty) => - *ty = self.normalize(ty, Locations::All(*span)), + *ty = self.normalize(ty, Locations::All(span)), _ => {}, } self.instantiated_type_annotations.insert(annotation_index, annotation); diff --git a/src/librustc_mir/build/expr/as_constant.rs b/src/librustc_mir/build/expr/as_constant.rs index a431bfc61b37..4f812f53745d 100644 --- a/src/librustc_mir/build/expr/as_constant.rs +++ b/src/librustc_mir/build/expr/as_constant.rs @@ -3,6 +3,7 @@ use build::Builder; use hair::*; use rustc::mir::*; +use rustc::ty::CanonicalUserTypeAnnotation; impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// Compile `expr`, yielding a compile-time constant. Assumes that @@ -31,7 +32,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { } => this.as_constant(value), ExprKind::Literal { literal, user_ty } => { let user_ty = user_ty.map(|ty| { - this.canonical_user_type_annotations.push((span, ty)) + this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { + span, + user_ty: ty, + }) }); Constant { span, diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index 3ed00d579790..5429ce2a2e3d 100644 --- a/src/librustc_mir/build/expr/as_place.rs +++ b/src/librustc_mir/build/expr/as_place.rs @@ -6,7 +6,7 @@ use build::{BlockAnd, BlockAndExtension, Builder}; use hair::*; use rustc::mir::interpret::EvalErrorKind::BoundsCheck; use rustc::mir::*; -use rustc::ty::Variance; +use rustc::ty::{CanonicalUserTypeAnnotation, Variance}; use rustc_data_structures::indexed_vec::Idx; @@ -134,7 +134,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let place = unpack!(block = this.as_place(block, source)); if let Some(user_ty) = user_ty { let annotation_index = this.canonical_user_type_annotations.push( - (source_info.span, user_ty) + CanonicalUserTypeAnnotation { span: source_info.span, user_ty } ); this.cfg.push( block, @@ -157,7 +157,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ); if let Some(user_ty) = user_ty { let annotation_index = this.canonical_user_type_annotations.push( - (source_info.span, user_ty) + CanonicalUserTypeAnnotation { span: source_info.span, user_ty } ); this.cfg.push( block, diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index e0fc90931696..501a10cfbb90 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -9,7 +9,7 @@ use hair::*; use rustc::middle::region; use rustc::mir::interpret::EvalErrorKind; use rustc::mir::*; -use rustc::ty::{self, Ty, UpvarSubsts}; +use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts}; use syntax_pos::Span; impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { @@ -332,7 +332,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { }; let user_ty = user_ty.map(|ty| { - this.canonical_user_type_annotations.push((expr_span, ty)) + this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { + span: source_info.span, + user_ty: ty, + }) }); let adt = box AggregateKind::Adt( adt_def, diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index d52ce9a67d29..61d1216fd3ea 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -9,7 +9,7 @@ use build::{BlockAnd, BlockAndExtension, Builder}; use build::{GuardFrame, GuardFrameLocal, LocalsForNode}; use hair::*; use rustc::mir::*; -use rustc::ty::{self, Ty}; +use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty}; use rustc::ty::layout::VariantIdx; use rustc_data_structures::bit_set::BitSet; use rustc_data_structures::fx::FxHashMap; @@ -570,7 +570,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // // Note that the variance doesn't apply here, as we are tracking the effect // of `user_ty` on any bindings contained with subpattern. - let annotation = (user_ty_span, user_ty.base); + let annotation = CanonicalUserTypeAnnotation { + span: user_ty_span, + user_ty: user_ty.base, + }; let projection = UserTypeProjection { base: self.canonical_user_type_annotations.push(annotation), projs: user_ty.projs.clone(), diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 7aaf74ae18fb..8a5e6a581b33 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -14,8 +14,8 @@ use hair::constant::*; use rustc::mir::{fmt_const_val, Field, BorrowKind, Mutability}; use rustc::mir::{ProjectionElem, UserTypeProjection}; use rustc::mir::interpret::{Scalar, GlobalId, ConstValue, sign_extend}; -use rustc::ty::{self, Region, TyCtxt, AdtDef, Ty, Lift}; -use rustc::ty::{CanonicalUserType, CanonicalUserTypeAnnotations, UserType}; +use rustc::ty::{self, Region, TyCtxt, AdtDef, Ty, Lift, UserType}; +use rustc::ty::{CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations}; use rustc::ty::subst::{Substs, Kind}; use rustc::ty::layout::VariantIdx; use rustc::hir::{self, PatKind, RangeEnd}; @@ -78,7 +78,7 @@ impl<'tcx> PatternTypeProjection<'tcx> { span: Span, ) -> UserTypeProjection<'tcx> { UserTypeProjection { - base: annotations.push((span, self.base)), + base: annotations.push(CanonicalUserTypeAnnotation{ span, user_ty: self.base }), projs: self.projs } } diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index fca208b340d2..e99f2da73385 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -632,8 +632,8 @@ fn write_user_type_annotations(mir: &Mir, w: &mut dyn Write) -> io::Result<()> { if !mir.user_type_annotations.is_empty() { writeln!(w, "| User Type Annotations")?; } - for (index, (span, annotation)) in mir.user_type_annotations.iter_enumerated() { - writeln!(w, "| {:?}: {:?} at {:?}", index.index(), annotation, span)?; + for (index, annotation) in mir.user_type_annotations.iter_enumerated() { + writeln!(w, "| {:?}: {:?} at {:?}", index.index(), annotation.user_ty, annotation.span)?; } if !mir.user_type_annotations.is_empty() { writeln!(w, "|")?;