]> git.lizzy.rs Git - rust.git/commitdiff
fixed all compilation errors
authorSaleem Jaffer <saleem@acko.com>
Mon, 18 Mar 2019 09:21:08 +0000 (14:51 +0530)
committerSaleem Jaffer <saleem@acko.com>
Mon, 18 Mar 2019 09:33:30 +0000 (15:03 +0530)
src/librustc_codegen_ssa/mir/block.rs
src/librustc_codegen_ssa/mir/place.rs
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/place_ext.rs
src/librustc_mir/borrow_check/places_conflict.rs
src/librustc_mir/interpret/place.rs
src/librustc_mir/transform/const_prop.rs
src/librustc_mir/transform/inline.rs
src/librustc_mir/transform/promote_consts.rs
src/librustc_mir/transform/qualify_consts.rs

index 35fd30f34ad24e2a248224ff8fc6e73ce99cb3f7..62f454f1b9feab018ce1c88687b997d27e76703c 100644 (file)
@@ -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 @@ fn codegen_call_terminator<'b>(
                         // 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(
index 0408ccf039f340093dde20b6a4979e4cdebde86d..1608429b07024a1474919393ed341c58b1cb6fc0 100644 (file)
@@ -408,11 +408,13 @@ pub fn codegen_place(
 
         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 @@ pub fn codegen_place(
                     }
                 }
             }
-            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));
index e92ed1f2c7caa0d89e27a7c4e50edc40a169750e..e538622103acaf4ff3954eb819e144cb7de17075 100644 (file)
@@ -1983,20 +1983,16 @@ fn is_mutable<'d>(
             // 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) => {
index 5e691db0a2e4e754ba7eab9f011917cca5f83b11..0452465f0b9d77baf02a4c1bd59a061e18af4e61 100644 (file)
@@ -50,11 +50,8 @@ fn ignore_borrow(
                 }
             }
             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(..)
index c4f9df0cfe57961b97defca6bf3b5037ed952ddd..783751056d76b2918cb8427ea5e2662ac62b5a27 100644 (file)
@@ -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
                 }
index 7adcb118f843c3c7ab64a57645638063999571e6..6089e491684e9f279b17eaf096c03a1c230ff844 100644 (file)
@@ -584,7 +584,7 @@ pub(super) fn eval_place_to_mplace(
         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,
index 3ee26e7dd26d98a0c638ef050aaf6af7906308d3..c5c3a1b8eca1800a53eb6996e55496dfd86ef6ec 100644 (file)
@@ -283,7 +283,7 @@ fn eval_place(&mut self, place: &Place<'tcx>, source_info: SourceInfo) -> Option
                 // 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
index 0b2a34d5fb97555568de6bffd5fcfdece1fa4237..86b7da178791999ff327e47919a6fb966ce15aa6 100644 (file)
@@ -702,6 +702,7 @@ fn visit_place(&mut self,
                     None => self.super_place(place, _ctxt, _location)
                 }
             },
+            _ => self.super_place(place, _ctxt, _location)
         }
     }
 
index 831d8b46a65c3a8ad2681abb9be92fc4cab5cda2..d777a7b362b90c3b819616b0d5bee219c6a82c2a 100644 (file)
@@ -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 @@ fn promote_temp(&mut self, temp: Local) -> Local {
     }
 
     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 @@ fn visit_local(&mut self,
 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);
     }
index 9cbb891316dca07ef34db0bc7f764892c5599b79..c01ed4b1c59e820c9df00f788e4136f5a423aa59 100644 (file)
@@ -922,7 +922,7 @@ fn visit_place(&mut self,
         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 @@ fn run_pass<'a, 'tcx>(&self,
             };
 
             // 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();