Skip to content

Commit 13b82ec

Browse files
author
Alexander Regueiro
committed
Minor refactoring.
1 parent 9f751a9 commit 13b82ec

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

src/librustc/mir/interpret/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'tcx, O> EvalErrorKind<'tcx, O> {
306306
ReadBytesAsPointer =>
307307
"a memory access tried to interpret some bytes as a pointer",
308308
ReadForeignStatic =>
309-
"tried to read foreign (extern) static",
309+
"tried to read from foreign (extern) static",
310310
InvalidPointerMath =>
311311
"attempted to do invalid arithmetic on pointers that would leak base addresses, e.g. comparing pointers into different allocations",
312312
ReadUndefBytes =>

src/librustc_mir/transform/qualify_consts.rs

+21-24
Original file line numberDiff line numberDiff line change
@@ -450,25 +450,26 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
450450
match *place {
451451
Place::Local(ref local) => self.visit_local(local, context, location),
452452
Place::Static(ref global) => {
453-
// Only allow statics (not consts) to refer to other statics.
454-
if !(self.mode == Mode::Static || self.mode == Mode::StaticMut) {
453+
if self.tcx
454+
.get_attrs(global.def_id)
455+
.iter()
456+
.any(|attr| attr.check_name("thread_local")) {
457+
if self.mode != Mode::Fn {
458+
span_err!(self.tcx.sess, self.span, E0625,
459+
"thread-local statics cannot be \
460+
accessed at compile-time");
461+
}
455462
self.add(Qualif::NOT_CONST);
463+
return;
456464
}
457465

458-
if self.mode != Mode::Fn {
459-
if self.tcx
460-
.get_attrs(global.def_id)
461-
.iter()
462-
.any(|attr| attr.check_name("thread_local")) {
463-
span_err!(self.tcx.sess, self.span, E0625,
464-
"thread-local statics cannot be \
465-
accessed at compile-time");
466-
self.add(Qualif::NOT_CONST);
467-
return;
468-
}
466+
// Only allow statics (not consts) to refer to other statics.
467+
if self.mode == Mode::Static || self.mode == Mode::StaticMut {
468+
return;
469469
}
470+
self.add(Qualif::NOT_CONST);
470471

471-
if self.mode == Mode::Const || self.mode == Mode::ConstFn {
472+
if self.mode != Mode::Fn {
472473
let mut err = struct_span_err!(self.tcx.sess, self.span, E0013,
473474
"{}s cannot refer to statics, use \
474475
a constant instead", self.mode);
@@ -544,13 +545,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
544545
}
545546

546547
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
548+
self.super_operand(operand, location);
549+
547550
match *operand {
548551
Operand::Copy(_) |
549552
Operand::Move(_) => {
550-
self.nest(|this| {
551-
this.super_operand(operand, location);
552-
});
553-
554553
// Mark the consumed locals to indicate later drops are noops.
555554
if let Operand::Move(Place::Local(local)) = *operand {
556555
self.local_qualif[local] = self.local_qualif[local].map(|q|
@@ -595,12 +594,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
595594
}
596595

597596
if is_reborrow {
598-
self.nest(|this| {
599-
this.super_place(place, PlaceContext::Borrow {
600-
region,
601-
kind
602-
}, location);
603-
});
597+
self.super_place(place, PlaceContext::Borrow {
598+
region,
599+
kind
600+
}, location);
604601
} else {
605602
self.super_rvalue(rvalue, location);
606603
}

src/test/compile-fail/issue-28324.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ extern {
1616

1717
pub static BAZ: u32 = *&error_message_count;
1818
//~^ ERROR constant evaluation error
19-
//~| tried to read foreign (extern) static
19+
//~| tried to read from foreign (extern) static
2020

2121
fn main() {}

0 commit comments

Comments
 (0)