]> git.lizzy.rs Git - rust.git/commitdiff
Use a struct for user type annotations
authorMatthew Jasper <mjjasper1@gmail.com>
Sun, 6 Jan 2019 17:10:53 +0000 (17:10 +0000)
committerMatthew Jasper <mjjasper1@gmail.com>
Sat, 19 Jan 2019 15:15:07 +0000 (15:15 +0000)
13 files changed:
src/librustc/ich/impls_ty.rs
src/librustc/mir/mod.rs
src/librustc/mir/visit.rs
src/librustc/ty/context.rs
src/librustc/ty/mod.rs
src/librustc_mir/borrow_check/nll/renumber.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/build/expr/as_constant.rs
src/librustc_mir/build/expr/as_place.rs
src/librustc_mir/build/expr/as_rvalue.rs
src/librustc_mir/build/matches/mod.rs
src/librustc_mir/hair/pattern/mod.rs
src/librustc_mir/util/pretty.rs

index 7a6852ddc55ed0cf3e282f283b190414298fed7d..9b613e3e1abad02ba3f689ae5c5984d6617aa9ca 100644 (file)
@@ -1240,6 +1240,12 @@ impl<'tcx, G> for struct traits::InEnvironment<'tcx, G> {
     }
 );
 
+impl_stable_hash_for!(
+    struct ty::CanonicalUserTypeAnnotation<'tcx> {
+        user_ty, span
+    }
+);
+
 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::UserType<'gcx> {
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'a>,
index 9bd0efcbbb4b1924dbd8cbdc524a29459b42c786..f824ab7e5b39546c4c989a827b346b4b237067ea 100644 (file)
@@ -31,7 +31,7 @@
 use ty::layout::VariantIdx;
 use ty::{
     self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt,
-    UserTypeAnnotationIndex, UserType,
+    UserTypeAnnotationIndex,
 };
 use util::ppaux;
 
index 7ae77b221da75b1f648f431535da645c5def209c..49a1e5046aa0e3d87a3b9cfde035ab3c82711215 100644 (file)
@@ -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 @@ fn visit_user_type_projection(
             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! basic_blocks {
                     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 @@ fn super_user_type_projection(
             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>) {
index ef8f7bd9a7561d4375d19090fce2754927dd0162..59835afc8410369349539bc28ce909bb74034acd 100644 (file)
@@ -807,7 +807,27 @@ pub struct UserTypeAnnotationIndex {
 
 /// Mapping of type annotation indices to canonical user type annotations.
 pub type CanonicalUserTypeAnnotations<'tcx> =
-    IndexVec<UserTypeAnnotationIndex, (Span, CanonicalUserType<'tcx>)>;
+    IndexVec<UserTypeAnnotationIndex, CanonicalUserTypeAnnotation<'tcx>>;
+
+#[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>>;
index a6e226302e51b00b34d2dc81c332f7e54ff17020..dc91a30ef9273fa8487ff5c05cde0f1534db2971 100644 (file)
@@ -74,7 +74,7 @@
 pub use self::context::{Lift, TypeckTables, CtxtInterners};
 pub use self::context::{
     UserTypeAnnotationIndex, UserType, CanonicalUserType,
-    CanonicalUserTypeAnnotations,
+    CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
 };
 
 pub use self::instance::{Instance, InstanceDef};
index f6275230eebfb912dab59dcf61502726eb364f5f..ade06bce4690bf1582fe5cd2d3ab987f655b32a8 100644 (file)
@@ -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 @@ fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
     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
index 7c3507e06cb1cb130cc99cae3dfc8fd007ef61be..82ffafa4ce975b80323e817a486309314858f0ba 100644 (file)
@@ -38,7 +38,7 @@
 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 @@ fn instantiate_user_type_annotations(&mut self) {
              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);
index a431bfc61b37ae8c2aa2f9855d2c935b02bb492d..4f812f53745d7ee0ebc22a6a0ac2a11e364016fc 100644 (file)
@@ -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 @@ fn expr_as_constant(&mut self, expr: Expr<'tcx>) -> Constant<'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,
index 3ed00d5797907f638932cb4d51e097d6e94f724c..5429ce2a2e3dfe34214aff6804bc03d802722729 100644 (file)
@@ -6,7 +6,7 @@
 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 @@ fn expr_as_place(
                 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 @@ fn expr_as_place(
                 );
                 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,
index e0fc90931696e57851889e5f8286f9d083d711a6..501a10cfbb900dccca8d8b77cd03329e6b9c1e6b 100644 (file)
@@ -9,7 +9,7 @@
 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 @@ fn expr_as_rvalue(
                 };
 
                 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,
index d52ce9a67d29a87dd4a35dfb68c7260dfb716e41..61d1216fd3ea8c025e6aa7d840828b24f33940c2 100644 (file)
@@ -9,7 +9,7 @@
 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 @@ pub(super) fn visit_bindings(
                 //
                 // 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(),
index 7aaf74ae18fb3a4481780e92edb60550063bf3ff..8a5e6a581b3323316bd6ff8686dac1e20afffb40 100644 (file)
@@ -14,8 +14,8 @@
 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 @@ pub(crate) fn user_ty(
         span: Span,
     ) -> UserTypeProjection<'tcx> {
         UserTypeProjection {
-            base: annotations.push((span, self.base)),
+            base: annotations.push(CanonicalUserTypeAnnotation{ span, user_ty: self.base }),
             projs: self.projs
         }
     }
index fca208b340d2ac5e8a240eb557a17a1246b652d5..e99f2da73385df0839e90edc2fa35f5950bc47bb 100644 (file)
@@ -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(), annotationspan)?;
+    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, "|")?;