From 34ff9aa83fa014f77ffe8fa5a12268a033c95694 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 1 Mar 2017 02:29:57 +0200 Subject: 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. --- src/librustc_mir/transform/type_check.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/librustc_mir/transform') 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 { -- cgit 1.4.1-3-g733a5