Skip to content

Commit 7e78e70

Browse files
author
Nick Hamann
committed
Convert mutable statics error to have error code and add explanation.
Also changes 'owned pointers' => 'boxes' in the error message.
1 parent eb15030 commit 7e78e70

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/librustc/diagnostics.rs

+13
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,19 @@ From [RFC 246]:
880880
> required that all references be borrowed.
881881
882882
[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
883+
"##,
884+
885+
E0397: r##"
886+
It is not allowed for a mutable static to allocate or have destructors. For
887+
example:
888+
889+
```
890+
// error: mutable statics are not allowed to have boxes
891+
static mut FOO: Option<Box<usize>> = None;
892+
893+
// error: mutable statics are not allowed to have destructors
894+
static mut BAR: Option<Vec<i32>> = None;
895+
```
883896
"##
884897

885898
}

src/librustc/middle/check_const.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
249249
let suffix = if tcontents.has_dtor() {
250250
"destructors"
251251
} else if tcontents.owns_owned() {
252-
"owned pointers"
252+
"boxes"
253253
} else {
254254
return
255255
};
256256

257-
self.tcx.sess.span_err(e.span, &format!("mutable statics are not allowed \
258-
to have {}", suffix));
257+
span_err!(self.tcx.sess, e.span, E0397,
258+
"mutable statics are not allowed to have {}", suffix);
259259
}
260260

261261
fn check_static_type(&self, e: &ast::Expr) {

src/test/compile-fail/static-mut-not-constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212

1313
static mut a: Box<isize> = box 3;
1414
//~^ ERROR allocations are not allowed in statics
15-
//~^^ ERROR mutable statics are not allowed to have owned pointers
15+
//~^^ ERROR mutable statics are not allowed to have boxes
1616

1717
fn main() {}

0 commit comments

Comments
 (0)