]> git.lizzy.rs Git - rust.git/commitdiff
Minor refactoring.
authorAlexander Regueiro <alexreg@me.com>
Sun, 24 Jun 2018 23:08:36 +0000 (00:08 +0100)
committerAlexander Regueiro <alexreg@me.com>
Sat, 30 Jun 2018 22:53:52 +0000 (23:53 +0100)
src/librustc/mir/interpret/error.rs
src/librustc_mir/transform/qualify_consts.rs
src/test/compile-fail/issue-28324.rs

index 2363e2870ec47db8c5cfecaedff53b098920509f..7e2c144e0a71df68731067f21cd4e2ac1fd9aa63 100644 (file)
@@ -306,7 +306,7 @@ pub fn description(&self) -> &str {
             ReadBytesAsPointer =>
                 "a memory access tried to interpret some bytes as a pointer",
             ReadForeignStatic =>
-                "tried to read foreign (extern) static",
+                "tried to read from foreign (extern) static",
             InvalidPointerMath =>
                 "attempted to do invalid arithmetic on pointers that would leak base addresses, e.g. comparing pointers into different allocations",
             ReadUndefBytes =>
index 66106c7eca149c7cffb889a20fdcc7240f87f228..986957d5a82676b1fdf64f41d0aeb35c306603e5 100644 (file)
@@ -450,25 +450,26 @@ fn visit_place(&mut self,
         match *place {
             Place::Local(ref local) => self.visit_local(local, context, location),
             Place::Static(ref global) => {
-                // Only allow statics (not consts) to refer to other statics.
-                if !(self.mode == Mode::Static || self.mode == Mode::StaticMut) {
+                if self.tcx
+                       .get_attrs(global.def_id)
+                       .iter()
+                       .any(|attr| attr.check_name("thread_local")) {
+                    if self.mode != Mode::Fn {
+                        span_err!(self.tcx.sess, self.span, E0625,
+                                  "thread-local statics cannot be \
+                                   accessed at compile-time");
+                    }
                     self.add(Qualif::NOT_CONST);
+                    return;
                 }
 
-                if self.mode != Mode::Fn {
-                    if self.tcx
-                           .get_attrs(global.def_id)
-                           .iter()
-                           .any(|attr| attr.check_name("thread_local")) {
-                        span_err!(self.tcx.sess, self.span, E0625,
-                                    "thread-local statics cannot be \
-                                    accessed at compile-time");
-                        self.add(Qualif::NOT_CONST);
-                        return;
-                    }
+                // Only allow statics (not consts) to refer to other statics.
+                if self.mode == Mode::Static || self.mode == Mode::StaticMut {
+                    return;
                 }
+                self.add(Qualif::NOT_CONST);
 
-                if self.mode == Mode::Const || self.mode == Mode::ConstFn {
+                if self.mode != Mode::Fn {
                     let mut err = struct_span_err!(self.tcx.sess, self.span, E0013,
                                                    "{}s cannot refer to statics, use \
                                                     a constant instead", self.mode);
@@ -544,13 +545,11 @@ fn visit_place(&mut self,
     }
 
     fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
+        self.super_operand(operand, location);
+
         match *operand {
             Operand::Copy(_) |
             Operand::Move(_) => {
-                self.nest(|this| {
-                    this.super_operand(operand, location);
-                });
-
                 // Mark the consumed locals to indicate later drops are noops.
                 if let Operand::Move(Place::Local(local)) = *operand {
                     self.local_qualif[local] = self.local_qualif[local].map(|q|
@@ -595,12 +594,10 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
             }
 
             if is_reborrow {
-                self.nest(|this| {
-                    this.super_place(place, PlaceContext::Borrow {
-                        region,
-                        kind
-                    }, location);
-                });
+                self.super_place(place, PlaceContext::Borrow {
+                    region,
+                    kind
+                }, location);
             } else {
                 self.super_rvalue(rvalue, location);
             }
index 369f919471ca87f8637fe33118ecdf29f6010944..0f9fe3fe246f679173bc906f478161e718c22b8e 100644 (file)
@@ -16,6 +16,6 @@
 
 pub static BAZ: u32 = *&error_message_count;
 //~^ ERROR constant evaluation error
-//~| tried to read foreign (extern) static
+//~| tried to read from foreign (extern) static
 
 fn main() {}