Add feature gate
This commit is contained in:
parent
605a472948
commit
1eb42f1c78
@ -1178,10 +1178,11 @@ let px: i32 = match p { Point(x, _) => x };
|
||||
```
|
||||
|
||||
A _unit-like struct_ is a structure without any fields, defined by leaving off
|
||||
the list of fields entirely. Such structure implicitly defines a constant of
|
||||
the list of fields entirely. Such a structure implicitly defines a constant of
|
||||
its type with the same name. For example:
|
||||
|
||||
```
|
||||
# #![feature(braced_empty_structs)]
|
||||
struct Cookie;
|
||||
let c = [Cookie, Cookie {}, Cookie, Cookie {}];
|
||||
```
|
||||
@ -1189,6 +1190,7 @@ let c = [Cookie, Cookie {}, Cookie, Cookie {}];
|
||||
is equivalent to
|
||||
|
||||
```
|
||||
# #![feature(braced_empty_structs)]
|
||||
struct Cookie {}
|
||||
const Cookie: Cookie = Cookie {};
|
||||
let c = [Cookie, Cookie {}, Cookie, Cookie {}];
|
||||
@ -2420,6 +2422,7 @@ The currently implemented features of the reference compiler are:
|
||||
terms of encapsulation).
|
||||
* - `default_type_parameter_fallback` - Allows type parameter defaults to
|
||||
influence type inference.
|
||||
* - `braced_empty_structs` - Allows use of empty structs with braces.
|
||||
|
||||
If a feature is promoted to a language feature, then all existing programs will
|
||||
start to receive compilation warnings about `#![feature]` directives which enabled
|
||||
|
@ -191,6 +191,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status
|
||||
|
||||
// allow `#[unwind]`
|
||||
("unwind_attributes", "1.4.0", None, Active),
|
||||
|
||||
// allow empty structs/enum variants with braces
|
||||
("braced_empty_structs", "1.5.0", None, Active),
|
||||
];
|
||||
// (changing above list without updating src/doc/reference.md makes @cmr sad)
|
||||
|
||||
@ -775,7 +778,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
ast::ItemStruct(..) => {
|
||||
ast::ItemStruct(ref def, _) => {
|
||||
if attr::contains_name(&i.attrs[..], "simd") {
|
||||
self.gate_feature("simd", i.span,
|
||||
"SIMD types are experimental and possibly buggy");
|
||||
@ -794,6 +797,10 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if def.fields.is_empty() && def.ctor_id.is_none() {
|
||||
self.gate_feature("braced_empty_structs", i.span,
|
||||
"empty structs with braces are unstable");
|
||||
}
|
||||
}
|
||||
|
||||
ast::ItemDefaultImpl(..) => {
|
||||
@ -843,6 +850,12 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
|
||||
"box expression syntax is experimental; \
|
||||
you can call `Box::new` instead.");
|
||||
}
|
||||
ast::ExprStruct(_, ref fields, ref expr) => {
|
||||
if fields.is_empty() && expr.is_none() {
|
||||
self.gate_feature("braced_empty_structs", e.span,
|
||||
"empty structs with braces are unstable");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
visit::walk_expr(self, e);
|
||||
@ -867,6 +880,12 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
|
||||
pattern.span,
|
||||
"box pattern syntax is experimental");
|
||||
}
|
||||
ast::PatStruct(_, ref fields, dotdot) => {
|
||||
if fields.is_empty() && !dotdot {
|
||||
self.gate_feature("braced_empty_structs", pattern.span,
|
||||
"empty structs with braces are unstable");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
visit::walk_pat(self, pattern)
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
// Empty struct defined with braces shouldn't add names into value namespace
|
||||
|
||||
#![feature(braced_empty_structs)]
|
||||
|
||||
struct Empty {}
|
||||
|
||||
fn main() {
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
// Empty struct defined with braces shouldn't add names into value namespace
|
||||
|
||||
#![feature(braced_empty_structs)]
|
||||
#![deny(warnings)]
|
||||
|
||||
struct Empty {}
|
||||
|
21
src/test/compile-fail/empty-struct-with-braces-3.rs
Normal file
21
src/test/compile-fail/empty-struct-with-braces-3.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Feature gate test for empty struct with braces
|
||||
|
||||
struct Empty {} //~ ERROR empty structs with braces are unstable
|
||||
|
||||
fn main() {
|
||||
let e = Empty {}; //~ ERROR empty structs with braces are unstable
|
||||
|
||||
match e {
|
||||
Empty {} => {} //~ ERROR empty structs with braces are unstable
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@
|
||||
// Empty struct defined with braces add names into type namespace
|
||||
// Empty struct defined without braces add names into both type and value namespaces
|
||||
|
||||
#![feature(braced_empty_structs)]
|
||||
|
||||
struct Empty1 {}
|
||||
struct Empty2;
|
||||
struct Empty3 {}
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
//`#[cfg]` on struct field permits empty unusable struct
|
||||
|
||||
#![feature(braced_empty_structs)]
|
||||
|
||||
struct S {
|
||||
#[cfg(untrue)]
|
||||
a: int,
|
||||
|
Loading…
Reference in New Issue
Block a user