field: int
}
-// Declare a public enum with public and private variants
+// Declare a public enum with two public variants
pub enum State {
PubliclyAccessibleState,
- priv PrivatelyAccessibleState
+ PubliclyAccessibleState2,
}
~~~~
Trait, // I
Struct, // S
PublicField, // g
- PrivateField, // j
InheritedField // N
}
'I' => Trait,
'S' => Struct,
'g' => PublicField,
- 'j' => PrivateField,
'N' => InheritedField,
c => fail!("unexpected family char: {}", c)
}
Some(visibility_doc) => {
match reader::doc_as_u8(visibility_doc) as char {
'y' => ast::Public,
- 'n' => ast::Private,
'i' => ast::Inherited,
_ => fail!("unknown visibility character")
}
Trait => DlDef(ast::DefTrait(did)),
Enum => DlDef(ast::DefTy(did)),
Impl => DlImpl(did),
- PublicField | PrivateField | InheritedField => DlField,
+ PublicField | InheritedField => DlField,
}
}
fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
match family {
PublicField => ast::Public,
- PrivateField => ast::Private,
InheritedField => ast::Inherited,
_ => fail!()
}
let mut result = Vec::new();
reader::tagged_docs(item, tag_item_field, |an_item| {
let f = item_family(an_item);
- if f == PublicField || f == PrivateField || f == InheritedField {
+ if f == PublicField || f == InheritedField {
// FIXME #6993: name should be of type Name, not Ident
let name = item_name(&*intr, an_item);
let did = item_def_id(an_item, cdata);
visibility: Visibility) {
encode_family(ebml_w, match visibility {
Public => 'g',
- Private => 'j',
Inherited => 'N'
});
}
ebml_w.start_tag(tag_items_data_item_visibility);
let ch = match visibility {
Public => 'y',
- Private => 'n',
Inherited => 'i',
};
ebml_w.wr_str(str::from_char(ch));
// they inherit privacy
ast::ItemEnum(ref def, _) => {
for variant in def.variants.iter() {
- // If variants are private, then their logical "parent" is
- // the enclosing module because everyone in the enclosing
- // module can still use the private variant
- if variant.node.vis == ast::Private {
- self.parents.insert(variant.node.id, self.curparent);
-
- // Otherwise, if the variant is public, then the parent is
- // considered the enclosing enum because the enum will
- // dictate the privacy visibility of this variant instead.
- } else {
- self.parents.insert(variant.node.id, item.id);
- }
+ // The parent is considered the enclosing enum because the
+ // enum will dictate the privacy visibility of this variant
+ // instead.
+ self.parents.insert(variant.node.id, item.id);
}
}
// public all variants are public unless they're explicitly priv
ast::ItemEnum(ref def, _) if public_first => {
for variant in def.variants.iter() {
- if variant.node.vis != ast::Private {
- self.exported_items.insert(variant.node.id);
- }
+ self.exported_items.insert(variant.node.id);
}
}
Some(ast_map::NodeForeignItem(_)) => {
self.tcx.map.get_foreign_vis(closest_private_id)
}
- Some(ast_map::NodeVariant(ref v)) => {
- // sadly enum variants still inherit visibility, so only
- // break out of this is explicitly private
- if v.node.vis == ast::Private { break }
+ Some(ast_map::NodeVariant(..)) => {
ast::Public // need to move up a level (to the enum)
}
_ => ast::Public,
fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
match i.vis {
ast::Inherited => {}
- ast::Private => {
- self.tcx.sess.span_err(i.span, "unnecessary visibility \
- qualifier");
- }
ast::Public => {
if self.in_fn {
self.tcx.sess.span_err(i.span, "unnecessary `pub`, imports \
}
}
};
- let check_not_priv = |sp: Span, vis: ast::Visibility, note: &str| {
- if vis == ast::Private {
- tcx.sess.span_err(sp, "unnecessary `priv` qualifier");
- if note.len() > 0 {
- tcx.sess.span_note(sp, note);
- }
- }
- };
- let check_struct = |def: &@ast::StructDef| {
- for f in def.fields.iter() {
- match f.node.kind {
- ast::NamedField(_, ast::Private) => {
- tcx.sess.span_err(f.span, "unnecessary `priv` \
- visibility");
- }
- ast::NamedField(..) | ast::UnnamedField(..) => {}
- }
- }
- };
match item.node {
// implementations of traits don't need visibility qualifiers because
// that's controlled by having the trait in scope.
}
}
- ast::ItemImpl(_, _, _, ref methods) => {
+ ast::ItemImpl(..) => {
check_inherited(item.span, item.vis,
"place qualifiers on individual methods instead");
- for i in methods.iter() {
- check_not_priv(i.span, i.vis, "functions are private by \
- default");
- }
}
- ast::ItemForeignMod(ref fm) => {
+ ast::ItemForeignMod(..) => {
check_inherited(item.span, item.vis,
"place qualifiers on individual functions \
instead");
- for i in fm.items.iter() {
- check_not_priv(i.span, i.vis, "functions are private by \
- default");
- }
}
ast::ItemEnum(ref def, _) => {
visibility");
}
}
- ast::Private => {
- if item.vis != ast::Public {
- tcx.sess.span_err(v.span, "unnecessary `priv` \
- visibility");
- }
- }
ast::Inherited => {}
}
-
- match v.node.kind {
- ast::StructVariantKind(ref s) => check_struct(s),
- ast::TupleVariantKind(..) => {}
- }
}
}
- ast::ItemStruct(ref def, _) => check_struct(def),
-
ast::ItemTrait(_, _, ref methods) => {
for m in methods.iter() {
match *m {
}
}
- ast::ItemStatic(..) |
+ ast::ItemStatic(..) | ast::ItemStruct(..) |
ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemTy(..) |
- ast::ItemMac(..) => {
- check_not_priv(item.span, item.vis, "items are private by \
- default");
- }
+ ast::ItemMac(..) => {}
}
}
variant: &Variant,
item_id: DefId,
parent: ReducedGraphParent,
- parent_public: bool) {
+ is_public: bool) {
let ident = variant.node.name;
- // FIXME: this is unfortunate to have to do this privacy calculation
- // here. This should be living in middle::privacy, but it's
- // necessary to keep around in some form becaues of glob imports...
- let is_public = parent_public && variant.node.vis != ast::Private;
match variant.node.kind {
TupleVariantKind(_) => {
// We assume the parent is visible, or else we wouldn't have seen
// it. Also variants are public-by-default if the parent was also
// public.
- let is_public = vis != ast::Private;
if is_struct {
- child_name_bindings.define_type(def, DUMMY_SP, is_public);
+ child_name_bindings.define_type(def, DUMMY_SP, true);
self.structs.insert(variant_id);
} else {
- child_name_bindings.define_value(def, DUMMY_SP, is_public);
+ child_name_bindings.define_value(def, DUMMY_SP, true);
}
}
DefFn(..) | DefStaticMethod(..) | DefStatic(..) => {
Module {
name : name,
id: 0,
- vis: ast::Private,
+ vis: ast::Inherited,
where: syntax::codemap::DUMMY_SP,
attrs : Vec::new(),
structs : Vec::new(),
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.get() {
Some(ast::Public) => write!(f.buf, "pub "),
- Some(ast::Private) => write!(f.buf, "priv "),
Some(ast::Inherited) | None => Ok(())
}
}
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
pub enum Visibility {
Public,
- Private,
Inherited,
}
pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
match self {
&Inherited => parent_visibility,
- &Public | &Private => *self
+ &Public => *self
}
}
}
use ast::{MatchSeq, MatchTok, Method, MutTy, BiMul, Mutability};
use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatEnum};
use ast::{PatIdent, PatLit, PatRange, PatRegion, PatStruct};
-use ast::{PatTup, PatUniq, PatWild, PatWildMulti, Private};
+use ast::{PatTup, PatUniq, PatWild, PatWildMulti};
use ast::{BiRem, Required};
use ast::{RetStyle, Return, BiShl, BiShr, Stmt, StmtDecl};
use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField};
let attrs = self.parse_outer_attributes();
- if self.eat_keyword(keywords::Priv) {
- return self.parse_single_struct_field(Private, attrs);
- }
-
if self.eat_keyword(keywords::Pub) {
return self.parse_single_struct_field(Public, attrs);
}
// parse visiility: PUB, PRIV, or nothing
fn parse_visibility(&mut self) -> Visibility {
if self.eat_keyword(keywords::Pub) { Public }
- else if self.eat_keyword(keywords::Priv) { Private }
else { Inherited }
}
pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> ~str {
match vis {
- ast::Private => format!("priv {}", s),
ast::Public => format!("pub {}", s),
ast::Inherited => s.to_owned()
}
pub fn print_visibility(&mut self, vis: ast::Visibility) -> IoResult<()> {
match vis {
- ast::Private => self.word_nbsp("priv"),
ast::Public => self.word_nbsp("pub"),
ast::Inherited => Ok(())
}
+++ /dev/null
-// Copyright 2012 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.
-
-mod super_sekrit {
- pub enum sooper_sekrit {
- quux, priv baz
- }
-}
+++ /dev/null
-// Copyright 2014 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.
-
-pub enum Foo {
- Bar,
- priv Baz,
-}
--- /dev/null
+// Copyright 2012 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.
+
+mod super_sekrit {
+ pub enum sooper_sekrit {
+ quux, baz
+ }
+}
// except according to those terms.
struct cat {
- priv meows : uint,
+ meows : uint,
how_hungry : int,
}
}
struct cat {
- priv meows : uint,
+ meows : uint,
how_hungry : int,
name : ~str,
// except according to those terms.
struct cat {
- priv meows : uint,
+ meows : uint,
}
impl cat {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use zoo::{duck, goose}; //~ ERROR: variant `goose` is private
+use zoo::{duck, goose};
mod zoo {
pub enum bird {
pub duck, //~ ERROR: unnecessary `pub` visibility
- priv goose
+ goose
}
}
// except according to those terms.
pub extern crate std; //~ ERROR: `pub` visibility is not allowed
-priv extern crate std; //~ ERROR: unnecessary visibility qualifier
extern crate std;
pub use std::bool;
-priv use std::bool; //~ ERROR: unnecessary visibility qualifier
use std::bool;
fn main() {
pub use std::bool; //~ ERROR: imports in functions are never reachable
- priv use std::bool; //~ ERROR: unnecessary visibility qualifier
use std::bool;
}
pub a: int, //~ ERROR: missing documentation
b: int
},
-
- priv PubBazB
}
/// dox
pub a: int,
b: int
},
- priv PubBaz2B
}
#[allow(missing_doc)]
pub a: int,
b: int
},
- priv PubBaz3B
}
#[doc(hidden)]
pub x: Private<int>, //~ ERROR private type in exported type signature
y: Private<int>
},
-
- priv Baz3(Private<int>),
- priv Baz4 {
- x: Private<int>,
- }
}
enum Qux {
impl B for int { fn foo() -> int { 3 } }
pub enum Enum {
- priv Priv,
Pub
}
}
fn test() {
- self::Priv;
self::Pub;
unsafe {
epriv();
//~^ NOTE: trait `B` is private
::lol();
- ::bar::Priv; //~ ERROR: variant `Priv` is private
::bar::Pub;
unsafe {
mod kitties {
pub struct cat {
- priv meows : uint,
+ meows : uint,
how_hungry : int,
}
+++ /dev/null
-// Copyright 2014 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.
-
-// aux-build:private_variant_xc.rs
-
-extern crate private_variant_xc;
-
-pub fn main() {
- let _ = private_variant_xc::Bar;
- let _ = private_variant_xc::Baz; //~ ERROR variant `Baz` is private
-}
+++ /dev/null
-// Copyright 2012 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.
-
-mod a {
- pub enum Waffle {
- Belgian,
- Brussels,
- priv Liege
- }
-}
-
-fn main() {
- let x = a::Liege; //~ ERROR variant `Liege` is private
-}
+++ /dev/null
-// Copyright 2012-2014 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.
-
-// aux-build:private_variant_1.rs
-
-extern crate private_variant_1;
-
-fn main() {
- let _x = private_variant_1::super_sekrit::baz; //~ ERROR is private
-}
+++ /dev/null
-// Copyright 2013 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.
-
-struct sss {
- bar: int,
- priv {
- //~^ ERROR expected ident
- foo: ()
- }
-}
}
struct D {
- priv foo: int, //~ ERROR: visibility has no effect
+ pub foo: int, //~ ERROR: visibility has no effect
}
pub fn foo() {} //~ ERROR: visibility has no effect
pub mod bar {} //~ ERROR: visibility has no effect
--- /dev/null
+// Copyright 2012-2014 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.
+
+// aux-build:unreachable-variant.rs
+
+extern crate other = "unreachable-variant";
+
+fn main() {
+ let _x = other::super_sekrit::baz; //~ ERROR is private
+}
// except according to those terms.
struct A { pub i: int }
-struct B { priv i: int } //~ ERROR: unnecessary `priv`
pub enum C { pub Variant } //~ ERROR: unnecessary `pub`
-enum D { priv Variant2 } //~ ERROR: unnecessary `priv`
pub trait E {
pub fn foo() {} //~ ERROR: unnecessary visibility