Skip to content

Commit

Permalink
Minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Regueiro committed Jun 24, 2018
1 parent aa35607 commit c7a35eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<'tcx, O> EvalErrorKind<'tcx, O> {
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 =>
Expand Down
45 changes: 21 additions & 24 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,25 +450,26 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
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);
Expand Down Expand Up @@ -544,13 +545,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
}

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|
Expand Down Expand Up @@ -595,12 +594,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
}

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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-28324.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ extern {

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() {}

0 comments on commit c7a35eb

Please sign in to comment.