Allow static items that don't fulfill Freeze
This commit is contained in:
parent
ff1c49fa54
commit
68a3ec08b3
@ -18,8 +18,11 @@
|
||||
// - For each *immutable* static item, it checks that its **value**:
|
||||
// - doesn't own owned, managed pointers
|
||||
// - doesn't contain a struct literal or a call to an enum variant / struct constructor where
|
||||
// - the type of the struct/enum is not freeze
|
||||
// - the type of the struct/enum has a dtor
|
||||
//
|
||||
// Rules Enforced Elsewhere:
|
||||
// - It's not possible to take the address of a static item with unsafe interior. This is enforced
|
||||
// by borrowck::gather_loans
|
||||
|
||||
use middle::ty;
|
||||
|
||||
@ -121,21 +124,6 @@ impl<'a> Visitor<bool> for CheckStaticVisitor<'a> {
|
||||
self.tcx.sess.span_err(e.span,
|
||||
"static items are not allowed to have owned pointers");
|
||||
}
|
||||
ast::ExprProc(..) => {
|
||||
self.report_error(e.span,
|
||||
Some(~"immutable static items must be `Freeze`"));
|
||||
return;
|
||||
}
|
||||
ast::ExprAddrOf(mutability, _) => {
|
||||
match mutability {
|
||||
ast::MutMutable => {
|
||||
self.report_error(e.span,
|
||||
Some(~"immutable static items must be `Freeze`"));
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let node_ty = ty::node_id_to_type(self.tcx, e.id);
|
||||
|
||||
@ -147,11 +135,6 @@ impl<'a> Visitor<bool> for CheckStaticVisitor<'a> {
|
||||
Some(~"static items are not allowed to have destructors"));
|
||||
return;
|
||||
}
|
||||
if Some(did) == self.tcx.lang_items.no_freeze_bound() {
|
||||
self.report_error(e.span,
|
||||
Some(~"immutable static items must be `Freeze`"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -124,30 +124,6 @@ static STATIC18: @SafeStruct = @SafeStruct{field1: Variant1, field2: Variant2(0)
|
||||
static STATIC19: ~int = box 3;
|
||||
//~^ ERROR static items are not allowed to have owned pointers
|
||||
|
||||
|
||||
struct StructNoFreeze<'a> {
|
||||
nf: &'a int
|
||||
}
|
||||
|
||||
enum EnumNoFreeze<'a> {
|
||||
FreezableVariant,
|
||||
NonFreezableVariant(StructNoFreeze<'a>)
|
||||
}
|
||||
|
||||
static STATIC20: StructNoFreeze<'static> = StructNoFreeze{nf: &'static mut 4};
|
||||
//~^ ERROR immutable static items must be `Freeze`
|
||||
|
||||
static STATIC21: EnumNoFreeze<'static> = FreezableVariant;
|
||||
static STATIC22: EnumNoFreeze<'static> = NonFreezableVariant(StructNoFreeze{nf: &'static mut 4});
|
||||
//~^ ERROR immutable static items must be `Freeze`
|
||||
|
||||
struct NFMarker {
|
||||
nf: marker::NoFreeze
|
||||
}
|
||||
|
||||
static STATIC23: NFMarker = NFMarker{nf: marker::NoFreeze};
|
||||
//~^ ERROR immutable static items must be `Freeze`
|
||||
|
||||
pub fn main() {
|
||||
let y = { static x: ~int = ~3; x };
|
||||
//~^ ERROR static items are not allowed to have owned pointers
|
||||
|
Loading…
Reference in New Issue
Block a user