Skip to content

Commit 68a3ec0

Browse files
committed
Allow static items that don't fulfill Freeze
1 parent ff1c49f commit 68a3ec0

File tree

2 files changed

+4
-45
lines changed

2 files changed

+4
-45
lines changed

src/librustc/middle/check_static.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
// - For each *immutable* static item, it checks that its **value**:
1919
// - doesn't own owned, managed pointers
2020
// - doesn't contain a struct literal or a call to an enum variant / struct constructor where
21-
// - the type of the struct/enum is not freeze
2221
// - the type of the struct/enum has a dtor
22+
//
23+
// Rules Enforced Elsewhere:
24+
// - It's not possible to take the address of a static item with unsafe interior. This is enforced
25+
// by borrowck::gather_loans
2326

2427
use middle::ty;
2528

@@ -121,21 +124,6 @@ impl<'a> Visitor<bool> for CheckStaticVisitor<'a> {
121124
self.tcx.sess.span_err(e.span,
122125
"static items are not allowed to have owned pointers");
123126
}
124-
ast::ExprProc(..) => {
125-
self.report_error(e.span,
126-
Some(~"immutable static items must be `Freeze`"));
127-
return;
128-
}
129-
ast::ExprAddrOf(mutability, _) => {
130-
match mutability {
131-
ast::MutMutable => {
132-
self.report_error(e.span,
133-
Some(~"immutable static items must be `Freeze`"));
134-
return;
135-
}
136-
_ => {}
137-
}
138-
}
139127
_ => {
140128
let node_ty = ty::node_id_to_type(self.tcx, e.id);
141129

@@ -147,11 +135,6 @@ impl<'a> Visitor<bool> for CheckStaticVisitor<'a> {
147135
Some(~"static items are not allowed to have destructors"));
148136
return;
149137
}
150-
if Some(did) == self.tcx.lang_items.no_freeze_bound() {
151-
self.report_error(e.span,
152-
Some(~"immutable static items must be `Freeze`"));
153-
return;
154-
}
155138
}
156139
_ => {}
157140
}

src/test/compile-fail/check-static-values-constraints.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,30 +124,6 @@ static STATIC18: @SafeStruct = @SafeStruct{field1: Variant1, field2: Variant2(0)
124124
static STATIC19: ~int = box 3;
125125
//~^ ERROR static items are not allowed to have owned pointers
126126

127-
128-
struct StructNoFreeze<'a> {
129-
nf: &'a int
130-
}
131-
132-
enum EnumNoFreeze<'a> {
133-
FreezableVariant,
134-
NonFreezableVariant(StructNoFreeze<'a>)
135-
}
136-
137-
static STATIC20: StructNoFreeze<'static> = StructNoFreeze{nf: &'static mut 4};
138-
//~^ ERROR immutable static items must be `Freeze`
139-
140-
static STATIC21: EnumNoFreeze<'static> = FreezableVariant;
141-
static STATIC22: EnumNoFreeze<'static> = NonFreezableVariant(StructNoFreeze{nf: &'static mut 4});
142-
//~^ ERROR immutable static items must be `Freeze`
143-
144-
struct NFMarker {
145-
nf: marker::NoFreeze
146-
}
147-
148-
static STATIC23: NFMarker = NFMarker{nf: marker::NoFreeze};
149-
//~^ ERROR immutable static items must be `Freeze`
150-
151127
pub fn main() {
152128
let y = { static x: ~int = ~3; x };
153129
//~^ ERROR static items are not allowed to have owned pointers

0 commit comments

Comments
 (0)