Convert mutable statics error to have error code and add explanation.

Also changes 'owned pointers' => 'boxes' in the error message.
This commit is contained in:
Nick Hamann 2015-05-28 13:11:05 -05:00
parent eb15030dc1
commit 7e78e708fb
3 changed files with 17 additions and 4 deletions

View File

@ -880,6 +880,19 @@ From [RFC 246]:
> required that all references be borrowed.
[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
"##,
E0397: r##"
It is not allowed for a mutable static to allocate or have destructors. For
example:
```
// error: mutable statics are not allowed to have boxes
static mut FOO: Option<Box<usize>> = None;
// error: mutable statics are not allowed to have destructors
static mut BAR: Option<Vec<i32>> = None;
```
"##
}

View File

@ -249,13 +249,13 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
let suffix = if tcontents.has_dtor() {
"destructors"
} else if tcontents.owns_owned() {
"owned pointers"
"boxes"
} else {
return
};
self.tcx.sess.span_err(e.span, &format!("mutable statics are not allowed \
to have {}", suffix));
span_err!(self.tcx.sess, e.span, E0397,
"mutable statics are not allowed to have {}", suffix);
}
fn check_static_type(&self, e: &ast::Expr) {

View File

@ -12,6 +12,6 @@
static mut a: Box<isize> = box 3;
//~^ ERROR allocations are not allowed in statics
//~^^ ERROR mutable statics are not allowed to have owned pointers
//~^^ ERROR mutable statics are not allowed to have boxes
fn main() {}