Skip to content

Commit 579c65d

Browse files
committed
Un-feature gate struct variants
Struct variant field visibility is now inherited. Remove `pub` keywords from declarations. Closes #18641 [breaking-change]
1 parent 7e43f41 commit 579c65d

File tree

65 files changed

+60
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+60
-114
lines changed

src/etc/generate-deriving-span-tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
3838
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
3939
40-
#![feature(struct_variant)]
4140
extern crate rand;
4241
4342
{error_deriving}

src/librustc/lint/builtin.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,9 @@ pub struct MissingDoc {
13991399
/// Stack of IDs of struct definitions.
14001400
struct_def_stack: Vec<ast::NodeId>,
14011401

1402+
/// True if inside variant definition
1403+
in_variant: bool,
1404+
14021405
/// Stack of whether #[doc(hidden)] is set
14031406
/// at each level which has lint attributes.
14041407
doc_hidden_stack: Vec<bool>,
@@ -1408,6 +1411,7 @@ impl MissingDoc {
14081411
pub fn new() -> MissingDoc {
14091412
MissingDoc {
14101413
struct_def_stack: vec!(),
1414+
in_variant: false,
14111415
doc_hidden_stack: vec!(false),
14121416
}
14131417
}
@@ -1522,7 +1526,7 @@ impl LintPass for MissingDoc {
15221526

15231527
fn check_struct_field(&mut self, cx: &Context, sf: &ast::StructField) {
15241528
match sf.node.kind {
1525-
ast::NamedField(_, vis) if vis == ast::Public => {
1529+
ast::NamedField(_, vis) if vis == ast::Public || self.in_variant => {
15261530
let cur_struct_def = *self.struct_def_stack.last()
15271531
.expect("empty struct_def_stack");
15281532
self.check_missing_docs_attrs(cx, Some(cur_struct_def),
@@ -1536,6 +1540,13 @@ impl LintPass for MissingDoc {
15361540
fn check_variant(&mut self, cx: &Context, v: &ast::Variant, _: &ast::Generics) {
15371541
self.check_missing_docs_attrs(cx, Some(v.node.id), v.node.attrs.as_slice(),
15381542
v.span, "a variant");
1543+
assert!(!self.in_variant);
1544+
self.in_variant = true;
1545+
}
1546+
1547+
fn check_variant_post(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) {
1548+
assert!(self.in_variant);
1549+
self.in_variant = false;
15391550
}
15401551
}
15411552

src/librustc/lint/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
665665
self.with_lint_attrs(v.node.attrs.as_slice(), |cx| {
666666
run_lints!(cx, check_variant, v, g);
667667
visit::walk_variant(cx, v, g);
668+
run_lints!(cx, check_variant_post, v, g);
668669
})
669670
}
670671

src/librustc/lint/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ pub trait LintPass {
149149
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
150150
fn check_struct_field(&mut self, _: &Context, _: &ast::StructField) { }
151151
fn check_variant(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) { }
152+
fn check_variant_post(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) { }
152153
fn check_opt_lifetime_ref(&mut self, _: &Context, _: Span, _: &Option<ast::Lifetime>) { }
153154
fn check_lifetime_ref(&mut self, _: &Context, _: &ast::Lifetime) { }
154155
fn check_lifetime_decl(&mut self, _: &Context, _: &ast::LifetimeDef) { }

src/librustc/middle/privacy.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ struct VisiblePrivateTypesVisitor<'a, 'tcx: 'a> {
12391239
tcx: &'a ty::ctxt<'tcx>,
12401240
exported_items: &'a ExportedItems,
12411241
public_items: &'a PublicItems,
1242+
in_variant: bool,
12421243
}
12431244

12441245
struct CheckTypeForPrivatenessVisitor<'a, 'b: 'a, 'tcx: 'b> {
@@ -1514,13 +1515,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
15141515

15151516
fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics) {
15161517
if self.exported_items.contains(&v.node.id) {
1518+
self.in_variant = true;
15171519
visit::walk_variant(self, v, g);
1520+
self.in_variant = false;
15181521
}
15191522
}
15201523

15211524
fn visit_struct_field(&mut self, s: &ast::StructField) {
15221525
match s.node.kind {
1523-
ast::NamedField(_, ast::Public) => {
1526+
ast::NamedField(_, vis) if vis == ast::Public || self.in_variant => {
15241527
visit::walk_struct_field(self, s);
15251528
}
15261529
_ => {}
@@ -1598,7 +1601,8 @@ pub fn check_crate(tcx: &ty::ctxt,
15981601
let mut visitor = VisiblePrivateTypesVisitor {
15991602
tcx: tcx,
16001603
exported_items: &exported_items,
1601-
public_items: &public_items
1604+
public_items: &public_items,
1605+
in_variant: false,
16021606
};
16031607
visit::walk_crate(&mut visitor, krate);
16041608
}

src/librustc/middle/resolve.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ pub enum LastPrivate {
102102
// and whether the import is in fact used for each.
103103
// If the Option<PrivateDep> fields are None, it means there is no definition
104104
// in that namespace.
105-
LastImport{pub value_priv: Option<PrivateDep>,
106-
pub value_used: ImportUse,
107-
pub type_priv: Option<PrivateDep>,
108-
pub type_used: ImportUse},
105+
LastImport{value_priv: Option<PrivateDep>,
106+
value_used: ImportUse,
107+
type_priv: Option<PrivateDep>,
108+
type_used: ImportUse},
109109
}
110110

111111
#[deriving(Show)]

src/librustc/middle/trans/adt.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ pub enum Repr {
101101
* otherwise it indicates the other case.
102102
*/
103103
RawNullablePointer {
104-
pub nndiscr: Disr,
105-
pub nnty: ty::t,
106-
pub nullfields: Vec<ty::t>
104+
nndiscr: Disr,
105+
nnty: ty::t,
106+
nullfields: Vec<ty::t>
107107
},
108108
/**
109109
* Two cases distinguished by a nullable pointer: the case with discriminant
@@ -117,10 +117,10 @@ pub enum Repr {
117117
* identity function.
118118
*/
119119
StructWrappedNullablePointer {
120-
pub nonnull: Struct,
121-
pub nndiscr: Disr,
122-
pub ptrfield: PointerField,
123-
pub nullfields: Vec<ty::t>,
120+
nonnull: Struct,
121+
nndiscr: Disr,
122+
ptrfield: PointerField,
123+
nullfields: Vec<ty::t>,
124124
}
125125
}
126126

src/librustdoc/clean/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,9 @@ impl Clean<Item> for ty::ImplOrTraitItem {
10851085
pub enum Type {
10861086
/// structs/enums/traits (anything that'd be an ast::TyPath)
10871087
ResolvedPath {
1088-
pub path: Path,
1089-
pub typarams: Option<Vec<TyParamBound>>,
1090-
pub did: ast::DefId,
1088+
path: Path,
1089+
typarams: Option<Vec<TyParamBound>>,
1090+
did: ast::DefId,
10911091
},
10921092
// I have no idea how to usefully use this.
10931093
TyParamBinder(ast::NodeId),
@@ -1110,9 +1110,9 @@ pub enum Type {
11101110
Unique(Box<Type>),
11111111
RawPointer(Mutability, Box<Type>),
11121112
BorrowedRef {
1113-
pub lifetime: Option<Lifetime>,
1114-
pub mutability: Mutability,
1115-
pub type_: Box<Type>,
1113+
lifetime: Option<Lifetime>,
1114+
mutability: Mutability,
1115+
type_: Box<Type>,
11161116
},
11171117
// region, raw, other boxes, mutable
11181118
}

src/libsyntax/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,8 +1292,8 @@ pub type Variant = Spanned<Variant_>;
12921292

12931293
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
12941294
pub enum PathListItem_ {
1295-
PathListIdent { pub name: Ident, pub id: NodeId },
1296-
PathListMod { pub id: NodeId }
1295+
PathListIdent { name: Ident, id: NodeId },
1296+
PathListMod { id: NodeId }
12971297
}
12981298

12991299
impl PathListItem_ {

src/libsyntax/feature_gate.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use std::slice;
3737
static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
3838
("globs", Active),
3939
("macro_rules", Active),
40-
("struct_variant", Active),
40+
("struct_variant", Accepted),
4141
("asm", Active),
4242
("managed_boxes", Removed),
4343
("non_ascii_idents", Active),
@@ -184,19 +184,6 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
184184
}
185185
}
186186
match i.node {
187-
ast::ItemEnum(ref def, _) => {
188-
for variant in def.variants.iter() {
189-
match variant.node.kind {
190-
ast::StructVariantKind(..) => {
191-
self.gate_feature("struct_variant", variant.span,
192-
"enum struct variants are \
193-
experimental and possibly buggy");
194-
}
195-
_ => {}
196-
}
197-
}
198-
}
199-
200187
ast::ItemForeignMod(ref foreign_module) => {
201188
if attr::contains_name(i.attrs.as_slice(), "link_args") {
202189
self.gate_feature("link_args", i.span,

src/libsyntax/parse/parser.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4648,7 +4648,7 @@ impl<'a> Parser<'a> {
46484648
is_tuple_like = false;
46494649
fields = Vec::new();
46504650
while self.token != token::CloseDelim(token::Brace) {
4651-
fields.push(self.parse_struct_decl_field());
4651+
fields.push(self.parse_struct_decl_field(true));
46524652
}
46534653
if fields.len() == 0 {
46544654
self.fatal(format!("unit-like struct definition should be \
@@ -4725,12 +4725,16 @@ impl<'a> Parser<'a> {
47254725
}
47264726

47274727
/// Parse an element of a struct definition
4728-
fn parse_struct_decl_field(&mut self) -> StructField {
4728+
fn parse_struct_decl_field(&mut self, allow_pub: bool) -> StructField {
47294729

47304730
let attrs = self.parse_outer_attributes();
47314731

47324732
if self.eat_keyword(keywords::Pub) {
4733-
return self.parse_single_struct_field(Public, attrs);
4733+
if !allow_pub {
4734+
let span = self.last_span;
4735+
self.span_err(span, "`pub` is not allowed here");
4736+
}
4737+
return self.parse_single_struct_field(Public, attrs);
47344738
}
47354739

47364740
return self.parse_single_struct_field(Inherited, attrs);
@@ -5178,7 +5182,7 @@ impl<'a> Parser<'a> {
51785182
fn parse_struct_def(&mut self) -> P<StructDef> {
51795183
let mut fields: Vec<StructField> = Vec::new();
51805184
while self.token != token::CloseDelim(token::Brace) {
5181-
fields.push(self.parse_struct_decl_field());
5185+
fields.push(self.parse_struct_decl_field(false));
51825186
}
51835187
self.bump();
51845188

src/test/compile-fail/deriving-primitive.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(struct_variant)]
12-
1311
use std::num::FromPrimitive;
1412
use std::int;
1513

src/test/compile-fail/deriving-span-Clone-enum-struct-variant.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-Clone-enum.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-Clone-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-Clone-tuple-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-Default-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-Default-tuple-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-Hash-enum-struct-variant.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-Hash-enum.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-Hash-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-Hash-tuple-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-PartialEq-enum-struct-variant.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-PartialEq-enum.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-PartialEq-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-PartialEq-tuple-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615

src/test/compile-fail/deriving-span-PartialOrd-enum-struct-variant.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615
#[deriving(PartialEq)]

src/test/compile-fail/deriving-span-PartialOrd-enum.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615
#[deriving(PartialEq)]

src/test/compile-fail/deriving-span-PartialOrd-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615
#[deriving(PartialEq)]

src/test/compile-fail/deriving-span-PartialOrd-tuple-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
1212

13-
#![feature(struct_variant)]
1413
extern crate rand;
1514

1615
#[deriving(PartialEq)]

0 commit comments

Comments
 (0)