about summary refs log tree commit diff
path: root/src/librustc_mir
diff options
context:
space:
mode:
authorAriel Ben-Yehuda <ariel.byd@gmail.com>2017-03-01 02:29:57 +0200
committerAriel Ben-Yehuda <ariel.byd@gmail.com>2017-03-01 16:56:13 +0200
commit34ff9aa83fa014f77ffe8fa5a12268a033c95694 (patch)
tree0a320a50f2e1b3b9904bbe4aee2125ceaeed7ae0 /src/librustc_mir
parentca8708273b6d7ee506e7d03051778d520cfaa50f (diff)
downloadrust-34ff9aa83fa014f77ffe8fa5a12268a033c95694.tar.gz
rust-34ff9aa83fa014f77ffe8fa5a12268a033c95694.zip
store the normalized types of statics in MIR Lvalues
The types of statics, like all other items, are stored in the tcx
unnormalized. This is necessarily so, because
    a) Item types other than statics have generics, which can't be
normalized.
    b) Eager normalization causes undesirable on-demand dependencies.

Keeping with the principle that MIR lvalues require no normalization in
order to interpret, this patch stores the normalized type of the statics
in the Lvalue and reads it to get the lvalue type.

Fixes #39367.
Diffstat (limited to 'src/librustc_mir')
-rw-r--r--src/librustc_mir/build/expr/as_lvalue.rs2
-rw-r--r--src/librustc_mir/transform/type_check.rs14
2 files changed, 13 insertions, 3 deletions
diff --git a/src/librustc_mir/build/expr/as_lvalue.rs b/src/librustc_mir/build/expr/as_lvalue.rs
index 5abfe084f22..ec412d4e9c6 100644
--- a/src/librustc_mir/build/expr/as_lvalue.rs
+++ b/src/librustc_mir/build/expr/as_lvalue.rs
@@ -84,7 +84,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
                 block.and(Lvalue::Local(index))
             }
             ExprKind::StaticRef { id } => {
-                block.and(Lvalue::Static(id))
+                block.and(Lvalue::Static(Box::new(Static { def_id: id, ty: expr.ty })))
             }
 
             ExprKind::Array { .. } |
diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs
index af4a4a53905..c2faf27412c 100644
--- a/src/librustc_mir/transform/type_check.rs
+++ b/src/librustc_mir/transform/type_check.rs
@@ -126,8 +126,18 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
         debug!("sanitize_lvalue: {:?}", lvalue);
         match *lvalue {
             Lvalue::Local(index) => LvalueTy::Ty { ty: self.mir.local_decls[index].ty },
-            Lvalue::Static(def_id) =>
-                LvalueTy::Ty { ty: self.tcx().item_type(def_id) },
+            Lvalue::Static(box Static { def_id, ty: sty }) => {
+                let sty = self.sanitize_type(lvalue, sty);
+                let ty = self.tcx().item_type(def_id);
+                let ty = self.cx.normalize(&ty);
+                if let Err(terr) = self.cx.eq_types(self.last_span, ty, sty) {
+                    span_mirbug!(
+                        self, lvalue, "bad static type ({:?}: {:?}): {:?}",
+                        ty, sty, terr);
+                }
+                LvalueTy::Ty { ty: sty }
+
+            },
             Lvalue::Projection(ref proj) => {
                 let base_ty = self.sanitize_lvalue(&proj.base, location);
                 if let LvalueTy::Ty { ty } = base_ty {