]> git.lizzy.rs Git - rust.git/commitdiff
review fixes
authorSaleem Jaffer <saleem@acko.com>
Wed, 20 Mar 2019 19:07:08 +0000 (00:37 +0530)
committerSaleem Jaffer <saleem@acko.com>
Thu, 21 Mar 2019 16:43:09 +0000 (22:13 +0530)
src/librustc_codegen_ssa/mir/block.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/transform/const_prop.rs
src/librustc_mir/transform/inline.rs
src/librustc_mir/transform/promote_consts.rs

index 62f454f1b9feab018ce1c88687b997d27e76703c..066b38be3dbc22cf0f6bfb973690768e5bac1b94 100644 (file)
@@ -622,13 +622,13 @@ fn codegen_call_terminator<'b>(
                         // and we can then extract the value by evaluating the promoted.
                         mir::Operand::Copy(
                             Place::Base(PlaceBase::Static(
-                                            box mir::Static {promoted: Some(promoted), ty, ..}
-                                        ))
+                                box mir::Static {promoted: Some(promoted), ty, ..}
+                            ))
                         ) |
                         mir::Operand::Move(
                             Place::Base(PlaceBase::Static(
-                                            box mir::Static {promoted: Some(promoted), ty, ..}
-                                        ))
+                                box mir::Static {promoted: Some(promoted), ty, ..}
+                            ))
                         ) => {
                             let param_env = ty::ParamEnv::reveal_all();
                             let cid = mir::interpret::GlobalId {
index c2efd3625c32bef756cb7443f83f3f2d149864df..2a32b475c7991b4881d5ee30ccac5ff8d89e31c1 100644 (file)
@@ -455,6 +455,27 @@ fn sanitize_place(
             },
             Place::Base(PlaceBase::Static(box Static { def_id, ty: sty, promoted })) => {
                 let sty = self.sanitize_type(place, sty);
+                let check_err =
+                    |verifier: &mut TypeVerifier<'a, 'b, 'gcx, 'tcx> ,
+                     place: &Place<'tcx>,
+                     ty,
+                     sty| {
+                    if let Err(terr) = verifier.cx.eq_types(
+                        sty,
+                        ty,
+                        location.to_locations(),
+                        ConstraintCategory::Boring,
+                    ) {
+                        span_mirbug!(
+                            verifier,
+                            place,
+                            "bad promoted type ({:?}: {:?}): {:?}",
+                            ty,
+                            sty,
+                            terr
+                        );
+                    };
+                };
                 match promoted {
                     Some(pr) => {
                         if !self.errors_reported {
@@ -462,45 +483,14 @@ fn sanitize_place(
                             self.sanitize_promoted(promoted_mir, location);
 
                             let promoted_ty = promoted_mir.return_ty();
-
-                            if let Err(terr) = self.cx.eq_types(
-                                sty,
-                                promoted_ty,
-                                location.to_locations(),
-                                ConstraintCategory::Boring,
-                            ) {
-                                span_mirbug!(
-                                    self,
-                                    place,
-                                    "bad promoted type ({:?}: {:?}): {:?}",
-                                    promoted_ty,
-                                    sty,
-                                    terr
-                                );
-                            };
+                            check_err(self, place, promoted_ty, sty);
                         }
                     }
                     None => {
                         let ty = self.tcx().type_of(def_id);
                         let ty = self.cx.normalize(ty, location);
-                        if let Err(terr) =
-                            self.cx
-                                .eq_types(
-                                    ty,
-                                    sty,
-                                    location.to_locations(),
-                                    ConstraintCategory::Boring
-                                )
-                        {
-                            span_mirbug!(
-                                self,
-                                place,
-                                "bad static type ({:?}: {:?}): {:?}",
-                                ty,
-                                sty,
-                                terr
-                            );
-                        };
+
+                        check_err(self, place, ty, sty);
                     }
                 }
                 PlaceTy::Ty { ty: sty }
index c5c3a1b8eca1800a53eb6996e55496dfd86ef6ec..81cdb00100595beec200026704cf5b4991ce3200 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), ..})) => {
                 let generics = self.tcx.generics_of(self.source.def_id());
                 if generics.requires_monomorphization(self.tcx) {
                     // FIXME: can't handle code with generics
index 86b7da178791999ff327e47919a6fb966ce15aa6..ec2cf8a4c0348cb4ae7f4323d73b074463ff8936 100644 (file)
@@ -692,14 +692,9 @@ fn visit_place(&mut self,
                 // Return pointer; update the place itself
                 *place = self.destination.clone();
             },
-            Place::Base(PlaceBase::Static(ref mut static_)) => {
-                match static_.promoted {
-                    Some(promoted) => {
-                        if let Some(p) = self.promoted_map.get(promoted).cloned() {
-                            static_.promoted = Some(p);
-                        }
-                    }
-                    None => self.super_place(place, _ctxt, _location)
+            Place::Base(PlaceBase::Static(box Static { promoted: Some(promoted), .. })) => {
+                if let Some(p) = self.promoted_map.get(*promoted).cloned() {
+                    *promoted = p;
                 }
             },
             _ => self.super_place(place, _ctxt, _location)
index d777a7b362b90c3b819616b0d5bee219c6a82c2a..2344f070ea67048daca91c1a080a10a4c585e8cd 100644 (file)
@@ -153,7 +153,7 @@ 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,
-    def_id: DefId
+    def_id: DefId,
 }
 
 impl<'a, 'tcx> Promoter<'a, 'tcx> {
@@ -291,17 +291,14 @@ 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 def_id = self.def_id;
             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::Static(
-                        Box::new(Static { def_id: def_id, ty, promoted: Some(promoted_id) })
-                    )
-                )
+                promoted.local_decls[RETURN_PLACE] = LocalDecl::new_return_place(ty, span);
+                Place::Base(
+                    PlaceBase::Static(Box::new(Static { def_id, ty, promoted: Some(promoted_id) })))
             };
             let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut();
             match candidate {
@@ -421,7 +418,7 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
             source: mir,
             temps: &mut temps,
             keep_original: false,
-            def_id
+            def_id,
         };
         promoter.promote_candidate(candidate);
     }