Skip to content

Commit

Permalink
auto merge of #18994 : sfackler/rust/struct-variants-pt2, r=jakub-
Browse files Browse the repository at this point in the history
Struct variant field visibility is now inherited. Remove `pub` keywords
from declarations.

Closes #18641

[breaking-change]

r? @alexcrichton
  • Loading branch information
bors committed Nov 16, 2014
2 parents 321488b + 579c65d commit aad7547
Show file tree
Hide file tree
Showing 65 changed files with 60 additions and 114 deletions.
1 change: 0 additions & 1 deletion src/etc/generate-deriving-span-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
#![feature(struct_variant)]
extern crate rand;
{error_deriving}
Expand Down
13 changes: 12 additions & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,9 @@ pub struct MissingDoc {
/// Stack of IDs of struct definitions.
struct_def_stack: Vec<ast::NodeId>,

/// True if inside variant definition
in_variant: bool,

/// Stack of whether #[doc(hidden)] is set
/// at each level which has lint attributes.
doc_hidden_stack: Vec<bool>,
Expand All @@ -1411,6 +1414,7 @@ impl MissingDoc {
pub fn new() -> MissingDoc {
MissingDoc {
struct_def_stack: vec!(),
in_variant: false,
doc_hidden_stack: vec!(false),
}
}
Expand Down Expand Up @@ -1525,7 +1529,7 @@ impl LintPass for MissingDoc {

fn check_struct_field(&mut self, cx: &Context, sf: &ast::StructField) {
match sf.node.kind {
ast::NamedField(_, vis) if vis == ast::Public => {
ast::NamedField(_, vis) if vis == ast::Public || self.in_variant => {
let cur_struct_def = *self.struct_def_stack.last()
.expect("empty struct_def_stack");
self.check_missing_docs_attrs(cx, Some(cur_struct_def),
Expand All @@ -1539,6 +1543,13 @@ impl LintPass for MissingDoc {
fn check_variant(&mut self, cx: &Context, v: &ast::Variant, _: &ast::Generics) {
self.check_missing_docs_attrs(cx, Some(v.node.id), v.node.attrs.as_slice(),
v.span, "a variant");
assert!(!self.in_variant);
self.in_variant = true;
}

fn check_variant_post(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) {
assert!(self.in_variant);
self.in_variant = false;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
self.with_lint_attrs(v.node.attrs.as_slice(), |cx| {
run_lints!(cx, check_variant, v, g);
visit::walk_variant(cx, v, g);
run_lints!(cx, check_variant_post, v, g);
})
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub trait LintPass {
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
fn check_struct_field(&mut self, _: &Context, _: &ast::StructField) { }
fn check_variant(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) { }
fn check_variant_post(&mut self, _: &Context, _: &ast::Variant, _: &ast::Generics) { }
fn check_opt_lifetime_ref(&mut self, _: &Context, _: Span, _: &Option<ast::Lifetime>) { }
fn check_lifetime_ref(&mut self, _: &Context, _: &ast::Lifetime) { }
fn check_lifetime_decl(&mut self, _: &Context, _: &ast::LifetimeDef) { }
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ struct VisiblePrivateTypesVisitor<'a, 'tcx: 'a> {
tcx: &'a ty::ctxt<'tcx>,
exported_items: &'a ExportedItems,
public_items: &'a PublicItems,
in_variant: bool,
}

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

fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics) {
if self.exported_items.contains(&v.node.id) {
self.in_variant = true;
visit::walk_variant(self, v, g);
self.in_variant = false;
}
}

fn visit_struct_field(&mut self, s: &ast::StructField) {
match s.node.kind {
ast::NamedField(_, ast::Public) => {
ast::NamedField(_, vis) if vis == ast::Public || self.in_variant => {
visit::walk_struct_field(self, s);
}
_ => {}
Expand Down Expand Up @@ -1598,7 +1601,8 @@ pub fn check_crate(tcx: &ty::ctxt,
let mut visitor = VisiblePrivateTypesVisitor {
tcx: tcx,
exported_items: &exported_items,
public_items: &public_items
public_items: &public_items,
in_variant: false,
};
visit::walk_crate(&mut visitor, krate);
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ pub enum LastPrivate {
// and whether the import is in fact used for each.
// If the Option<PrivateDep> fields are None, it means there is no definition
// in that namespace.
LastImport{pub value_priv: Option<PrivateDep>,
pub value_used: ImportUse,
pub type_priv: Option<PrivateDep>,
pub type_used: ImportUse},
LastImport{value_priv: Option<PrivateDep>,
value_used: ImportUse,
type_priv: Option<PrivateDep>,
type_used: ImportUse},
}

#[deriving(Show)]
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/trans/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ pub enum Repr {
* otherwise it indicates the other case.
*/
RawNullablePointer {
pub nndiscr: Disr,
pub nnty: ty::t,
pub nullfields: Vec<ty::t>
nndiscr: Disr,
nnty: ty::t,
nullfields: Vec<ty::t>
},
/**
* Two cases distinguished by a nullable pointer: the case with discriminant
Expand All @@ -117,10 +117,10 @@ pub enum Repr {
* identity function.
*/
StructWrappedNullablePointer {
pub nonnull: Struct,
pub nndiscr: Disr,
pub ptrfield: PointerField,
pub nullfields: Vec<ty::t>,
nonnull: Struct,
nndiscr: Disr,
ptrfield: PointerField,
nullfields: Vec<ty::t>,
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,9 +1080,9 @@ impl Clean<Item> for ty::ImplOrTraitItem {
pub enum Type {
/// structs/enums/traits (anything that'd be an ast::TyPath)
ResolvedPath {
pub path: Path,
pub typarams: Option<Vec<TyParamBound>>,
pub did: ast::DefId,
path: Path,
typarams: Option<Vec<TyParamBound>>,
did: ast::DefId,
},
// I have no idea how to usefully use this.
TyParamBinder(ast::NodeId),
Expand All @@ -1105,9 +1105,9 @@ pub enum Type {
Unique(Box<Type>),
RawPointer(Mutability, Box<Type>),
BorrowedRef {
pub lifetime: Option<Lifetime>,
pub mutability: Mutability,
pub type_: Box<Type>,
lifetime: Option<Lifetime>,
mutability: Mutability,
type_: Box<Type>,
},
// region, raw, other boxes, mutable
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,8 +1293,8 @@ pub type Variant = Spanned<Variant_>;

#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum PathListItem_ {
PathListIdent { pub name: Ident, pub id: NodeId },
PathListMod { pub id: NodeId }
PathListIdent { name: Ident, id: NodeId },
PathListMod { id: NodeId }
}

impl PathListItem_ {
Expand Down
15 changes: 1 addition & 14 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::slice;
static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
("globs", Active),
("macro_rules", Active),
("struct_variant", Active),
("struct_variant", Accepted),
("asm", Active),
("managed_boxes", Removed),
("non_ascii_idents", Active),
Expand Down Expand Up @@ -184,19 +184,6 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
}
}
match i.node {
ast::ItemEnum(ref def, _) => {
for variant in def.variants.iter() {
match variant.node.kind {
ast::StructVariantKind(..) => {
self.gate_feature("struct_variant", variant.span,
"enum struct variants are \
experimental and possibly buggy");
}
_ => {}
}
}
}

ast::ItemForeignMod(ref foreign_module) => {
if attr::contains_name(i.attrs.as_slice(), "link_args") {
self.gate_feature("link_args", i.span,
Expand Down
12 changes: 8 additions & 4 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4612,7 +4612,7 @@ impl<'a> Parser<'a> {
is_tuple_like = false;
fields = Vec::new();
while self.token != token::CloseDelim(token::Brace) {
fields.push(self.parse_struct_decl_field());
fields.push(self.parse_struct_decl_field(true));
}
if fields.len() == 0 {
self.fatal(format!("unit-like struct definition should be \
Expand Down Expand Up @@ -4689,12 +4689,16 @@ impl<'a> Parser<'a> {
}

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

let attrs = self.parse_outer_attributes();

if self.eat_keyword(keywords::Pub) {
return self.parse_single_struct_field(Public, attrs);
if !allow_pub {
let span = self.last_span;
self.span_err(span, "`pub` is not allowed here");
}
return self.parse_single_struct_field(Public, attrs);
}

return self.parse_single_struct_field(Inherited, attrs);
Expand Down Expand Up @@ -5142,7 +5146,7 @@ impl<'a> Parser<'a> {
fn parse_struct_def(&mut self) -> P<StructDef> {
let mut fields: Vec<StructField> = Vec::new();
while self.token != token::CloseDelim(token::Brace) {
fields.push(self.parse_struct_decl_field());
fields.push(self.parse_struct_decl_field(false));
}
self.bump();

Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/deriving-primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(struct_variant)]

use std::num::FromPrimitive;
use std::int;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-Clone-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-Clone-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-Clone-tuple-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-Default-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-Hash-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-Hash-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-Hash-tuple-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-PartialEq-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-PartialEq-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;

#[deriving(PartialEq)]
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-PartialOrd-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;

#[deriving(PartialEq)]
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-PartialOrd-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;

#[deriving(PartialEq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(struct_variant)]
extern crate rand;

#[deriving(PartialEq)]
Expand Down
Loading

0 comments on commit aad7547

Please sign in to comment.