about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSaleem Jaffer <saleem@acko.com>2019-03-18 14:51:08 +0530
committerSaleem Jaffer <saleem@acko.com>2019-03-18 15:03:30 +0530
commit23c87a1f53a502cfca3ced42a33cf1389f6c081e (patch)
tree428658fde49afde8024982ff61ae19d0ecab290e
parenta837b8a3688d746bc392a65524fe7d06fdb61263 (diff)
downloadrust-23c87a1f53a502cfca3ced42a33cf1389f6c081e.tar.gz
rust-23c87a1f53a502cfca3ced42a33cf1389f6c081e.zip
fixed all compilation errors
-rw-r--r--src/librustc_codegen_ssa/mir/block.rs12
-rw-r--r--src/librustc_codegen_ssa/mir/place.rs10
-rw-r--r--src/librustc_mir/borrow_check/mod.rs14
-rw-r--r--src/librustc_mir/borrow_check/place_ext.rs7
-rw-r--r--src/librustc_mir/borrow_check/places_conflict.rs2
-rw-r--r--src/librustc_mir/interpret/place.rs2
-rw-r--r--src/librustc_mir/transform/const_prop.rs2
-rw-r--r--src/librustc_mir/transform/inline.rs1
-rw-r--r--src/librustc_mir/transform/promote_consts.rs17
-rw-r--r--src/librustc_mir/transform/qualify_consts.rs4
10 files changed, 41 insertions, 30 deletions
diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs
index 35fd30f34ad..62f454f1b9f 100644
--- a/src/librustc_codegen_ssa/mir/block.rs
+++ b/src/librustc_codegen_ssa/mir/block.rs
@@ -1,7 +1,7 @@
 use rustc::middle::lang_items;
 use rustc::ty::{self, Ty, TypeFoldable};
 use rustc::ty::layout::{self, LayoutOf, HasTyCtxt};
-use rustc::mir;
+use rustc::mir::{self, Place, PlaceBase};
 use rustc::mir::interpret::EvalErrorKind;
 use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode};
 use rustc_target::spec::abi::Abi;
@@ -621,15 +621,19 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                         // but specified directly in the code. This means it gets promoted
                         // and we can then extract the value by evaluating the promoted.
                         mir::Operand::Copy(
-                            mir::Place::Base(mir::PlaceBase::Promoted(box(index, ty)))
+                            Place::Base(PlaceBase::Static(
+                                            box mir::Static {promoted: Some(promoted), ty, ..}
+                                        ))
                         ) |
                         mir::Operand::Move(
-                            mir::Place::Base(mir::PlaceBase::Promoted(box(index, ty)))
+                            Place::Base(PlaceBase::Static(
+                                            box mir::Static {promoted: Some(promoted), ty, ..}
+                                        ))
                         ) => {
                             let param_env = ty::ParamEnv::reveal_all();
                             let cid = mir::interpret::GlobalId {
                                 instance: self.instance,
-                                promoted: Some(index),
+                                promoted: Some(promoted),
                             };
                             let c = bx.tcx().const_eval(param_env.and(cid));
                             let (llval, ty) = self.simd_shuffle_indices(
diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs
index 0408ccf039f..1608429b070 100644
--- a/src/librustc_codegen_ssa/mir/place.rs
+++ b/src/librustc_codegen_ssa/mir/place.rs
@@ -408,11 +408,13 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
 
         let result = match *place {
             mir::Place::Base(mir::PlaceBase::Local(_)) => bug!(), // handled above
-            mir::Place::Base(mir::PlaceBase::Promoted(box (index, ty))) => {
+            mir::Place::Base(
+                mir::PlaceBase::Static(box mir::Static { def_id: _, ty, promoted: Some(promoted) })
+            ) => {
                 let param_env = ty::ParamEnv::reveal_all();
                 let cid = mir::interpret::GlobalId {
                     instance: self.instance,
-                    promoted: Some(index),
+                    promoted: Some(promoted),
                 };
                 let layout = cx.layout_of(self.monomorphize(&ty));
                 match bx.tcx().const_eval(param_env.and(cid)) {
@@ -435,7 +437,9 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                     }
                 }
             }
-            mir::Place::Base(mir::PlaceBase::Static(box mir::Static { def_id, ty })) => {
+            mir::Place::Base(
+                mir::PlaceBase::Static(box mir::Static { def_id, ty, promoted: None })
+            ) => {
                 // NB: The layout of a static may be unsized as is the case when working
                 // with a static that is an extern_type.
                 let layout = cx.layout_of(self.monomorphize(&ty));
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs
index e92ed1f2c7c..e538622103a 100644
--- a/src/librustc_mir/borrow_check/mod.rs
+++ b/src/librustc_mir/borrow_check/mod.rs
@@ -1983,20 +1983,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
             // The rules for promotion are made by `qualify_consts`, there wouldn't even be a
             // `Place::Promoted` if the promotion weren't 100% legal. So we just forward this
             Place::Base(PlaceBase::Static(ref static_)) => {
-                if static_.promoted.is_some() {
+                if static_.promoted.is_some() ||
+                    (static_.promoted.is_none() &&
+                        self.infcx.tcx.is_static(static_.def_id) == Some(hir::Mutability::MutMutable)
+                    ){
                     Ok(RootPlace {
                         place,
                         is_local_mutation_allowed,
                     })
                 } else {
-                    if self.infcx.tcx.is_static(static_.def_id) != Some(hir::Mutability::MutMutable) {
-                        Err(place)
-                    } else {
-                        Ok(RootPlace {
-                            place,
-                            is_local_mutation_allowed,
-                        })
-                    }
+                    Err(place)
                 }
             }
             Place::Projection(ref proj) => {
diff --git a/src/librustc_mir/borrow_check/place_ext.rs b/src/librustc_mir/borrow_check/place_ext.rs
index 5e691db0a2e..0452465f0b9 100644
--- a/src/librustc_mir/borrow_check/place_ext.rs
+++ b/src/librustc_mir/borrow_check/place_ext.rs
@@ -50,11 +50,8 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
                 }
             }
             Place::Base(PlaceBase::Static(static_)) => {
-                if static_.promoted.is_none() {
-                    tcx.is_static(static_.def_id) == Some(hir::Mutability::MutMutable)
-                } else {
-                    false
-                }
+                static_.promoted.is_none() &&
+                    (tcx.is_static(static_.def_id) == Some(hir::Mutability::MutMutable))
             }
             Place::Projection(proj) => match proj.elem {
                 ProjectionElem::Field(..)
diff --git a/src/librustc_mir/borrow_check/places_conflict.rs b/src/librustc_mir/borrow_check/places_conflict.rs
index c4f9df0cfe5..783751056d7 100644
--- a/src/librustc_mir/borrow_check/places_conflict.rs
+++ b/src/librustc_mir/borrow_check/places_conflict.rs
@@ -403,7 +403,7 @@ fn place_element_conflict<'a, 'gcx: 'tcx, 'tcx>(
                         Overlap::Disjoint
                     }
                 },
-                (p1_, p2_) => {
+                (_, _) => {
                     debug!("place_element_conflict: DISJOINT-STATIC-PROMOTED");
                     Overlap::Disjoint
                 }
diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs
index 7adcb118f84..6089e491684 100644
--- a/src/librustc_mir/interpret/place.rs
+++ b/src/librustc_mir/interpret/place.rs
@@ -584,7 +584,7 @@ where
         use rustc::mir::PlaceBase;
         use rustc::mir::Static;
         Ok(match *mir_place {
-            Base(PlaceBase::Static(box Static {promoted: Some(promoted), ty, ..})) => {
+            Base(PlaceBase::Static(box Static {promoted: Some(promoted), ty: _, ..})) => {
                 let instance = self.frame().instance;
                 self.const_eval_raw(GlobalId {
                     instance,
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index 3ee26e7dd26..c5c3a1b8eca 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -283,7 +283,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
                 // an `Index` projection would throw us off-track.
                 _ => None,
             },
-            Place::Base(PlaceBase::Static(box Static {promoted: Some(promoted), ty, ..})) => {
+            Place::Base(PlaceBase::Static(box Static {promoted: Some(promoted), ty: _, ..})) => {
                 let generics = self.tcx.generics_of(self.source.def_id());
                 if generics.requires_monomorphization(self.tcx) {
                     // FIXME: can't handle code with generics
diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs
index 0b2a34d5fb9..86b7da17879 100644
--- a/src/librustc_mir/transform/inline.rs
+++ b/src/librustc_mir/transform/inline.rs
@@ -702,6 +702,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
                     None => self.super_place(place, _ctxt, _location)
                 }
             },
+            _ => self.super_place(place, _ctxt, _location)
         }
     }
 
diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs
index 831d8b46a65..d777a7b362b 100644
--- a/src/librustc_mir/transform/promote_consts.rs
+++ b/src/librustc_mir/transform/promote_consts.rs
@@ -12,6 +12,7 @@
 //! initialization and can otherwise silence errors, if
 //! move analysis runs after promotion on broken MIR.
 
+use rustc::hir::def_id::DefId;
 use rustc::mir::*;
 use rustc::mir::visit::{PlaceContext, MutatingUseContext, MutVisitor, Visitor};
 use rustc::mir::traversal::ReversePostorder;
@@ -151,7 +152,8 @@ struct Promoter<'a, 'tcx: 'a> {
 
     /// If true, all nested temps are also kept in the
     /// source MIR, not moved to the promoted MIR.
-    keep_original: bool
+    keep_original: bool,
+    def_id: DefId
 }
 
 impl<'a, 'tcx> Promoter<'a, 'tcx> {
@@ -287,14 +289,19 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
     }
 
     fn promote_candidate(mut self, candidate: Candidate) {
+        use rustc::mir::Static;
         let mut operand = {
+            let def_id = self.def_id.clone();
             let promoted = &mut self.promoted;
             let promoted_id = Promoted::new(self.source.promoted.len());
             let mut promoted_place = |ty, span| {
                 promoted.span = span;
                 promoted.local_decls[RETURN_PLACE] =
                     LocalDecl::new_return_place(ty, span);
-                Place::Base(PlaceBase::Promoted(box (promoted_id, ty)))
+                Place::Base(PlaceBase::Static(
+                        Box::new(Static { def_id: def_id, ty, promoted: Some(promoted_id) })
+                    )
+                )
             };
             let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut();
             match candidate {
@@ -367,7 +374,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
 pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
                                     tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                     mut temps: IndexVec<Local, TempState>,
-                                    candidates: Vec<Candidate>) {
+                                    candidates: Vec<Candidate>,
+                                    def_id: DefId) {
     // Visit candidates in reverse, in case they're nested.
     debug!("promote_candidates({:?})", candidates);
 
@@ -412,7 +420,8 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
             tcx,
             source: mir,
             temps: &mut temps,
-            keep_original: false
+            keep_original: false,
+            def_id
         };
         promoter.promote_candidate(candidate);
     }
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs
index 9cbb891316d..c01ed4b1c59 100644
--- a/src/librustc_mir/transform/qualify_consts.rs
+++ b/src/librustc_mir/transform/qualify_consts.rs
@@ -922,7 +922,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
         match *place {
             Place::Base(PlaceBase::Local(_)) => {}
             Place::Base(PlaceBase::Static(ref global)) => {
-                assert!(global.promoted.is_none(), {});
+                assert!(global.promoted.is_none());
                 if self.tcx
                        .get_attrs(global.def_id)
                        .iter()
@@ -1516,7 +1516,7 @@ impl MirPass for QualifyAndPromoteConstants {
             };
 
             // Do the actual promotion, now that we know what's viable.
-            promote_consts::promote_candidates(mir, tcx, temps, candidates);
+            promote_consts::promote_candidates(mir, tcx, temps, candidates, def_id);
         } else {
             if !mir.control_flow_destroyed.is_empty() {
                 let mut locals = mir.vars_iter();