1
Fork 0

Minor refactoring.

This commit is contained in:
Alexander Regueiro 2018-06-25 00:08:36 +01:00
parent 9f751a9c5a
commit 13b82ecf80
3 changed files with 24 additions and 27 deletions

View file

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

View file

@ -450,25 +450,26 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
match *place { match *place {
Place::Local(ref local) => self.visit_local(local, context, location), Place::Local(ref local) => self.visit_local(local, context, location),
Place::Static(ref global) => { Place::Static(ref global) => {
// Only allow statics (not consts) to refer to other statics.
if !(self.mode == Mode::Static || self.mode == Mode::StaticMut) {
self.add(Qualif::NOT_CONST);
}
if self.mode != Mode::Fn {
if self.tcx if self.tcx
.get_attrs(global.def_id) .get_attrs(global.def_id)
.iter() .iter()
.any(|attr| attr.check_name("thread_local")) { .any(|attr| attr.check_name("thread_local")) {
if self.mode != Mode::Fn {
span_err!(self.tcx.sess, self.span, E0625, span_err!(self.tcx.sess, self.span, E0625,
"thread-local statics cannot be \ "thread-local statics cannot be \
accessed at compile-time"); accessed at compile-time");
}
self.add(Qualif::NOT_CONST); self.add(Qualif::NOT_CONST);
return; return;
} }
}
if self.mode == Mode::Const || self.mode == Mode::ConstFn { // 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::Fn {
let mut err = struct_span_err!(self.tcx.sess, self.span, E0013, let mut err = struct_span_err!(self.tcx.sess, self.span, E0013,
"{}s cannot refer to statics, use \ "{}s cannot refer to statics, use \
a constant instead", self.mode); a constant instead", self.mode);
@ -544,13 +545,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
} }
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) { fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
self.super_operand(operand, location);
match *operand { match *operand {
Operand::Copy(_) | Operand::Copy(_) |
Operand::Move(_) => { Operand::Move(_) => {
self.nest(|this| {
this.super_operand(operand, location);
});
// Mark the consumed locals to indicate later drops are noops. // Mark the consumed locals to indicate later drops are noops.
if let Operand::Move(Place::Local(local)) = *operand { if let Operand::Move(Place::Local(local)) = *operand {
self.local_qualif[local] = self.local_qualif[local].map(|q| self.local_qualif[local] = self.local_qualif[local].map(|q|
@ -595,12 +594,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
} }
if is_reborrow { if is_reborrow {
self.nest(|this| { self.super_place(place, PlaceContext::Borrow {
this.super_place(place, PlaceContext::Borrow {
region, region,
kind kind
}, location); }, location);
});
} else { } else {
self.super_rvalue(rvalue, location); self.super_rvalue(rvalue, location);
} }

View file

@ -16,6 +16,6 @@ extern {
pub static BAZ: u32 = *&error_message_count; pub static BAZ: u32 = *&error_message_count;
//~^ ERROR constant evaluation error //~^ ERROR constant evaluation error
//~| tried to read foreign (extern) static //~| tried to read from foreign (extern) static
fn main() {} fn main() {}