auto merge of #9432 : alexcrichton/rust/correct-item-visibility, r=pcwalton

This fixes private statics and functions from being usable cross-crates, along
with some bad privacy error messages. This is a reopening of #8365 with all the
privacy checks in privacy.rs instead of resolve.rs (where they should be
anyway).

These maps of exported items will hopefully get used for generating
documentation by rustdoc

Closes #8592
This commit is contained in:
bors 2013-09-25 00:55:53 -07:00
commit 4531184614
164 changed files with 639 additions and 304 deletions

View File

@ -29,6 +29,8 @@ for t in os.listdir(run_pass):
if not ("xfail-test" in s or
"xfail-fast" in s or
"xfail-win32" in s):
if not "pub fn main" in s and "fn main" in s:
print("Warning: no public entry point in " + t)
stage2_tests.append(t)
f.close()

View File

@ -162,7 +162,7 @@ struct MutexArcInner<T> { priv lock: Mutex, priv failed: bool, priv data: T }
/// An Arc with mutable data protected by a blocking mutex.
#[no_freeze]
struct MutexArc<T> { priv x: UnsafeArc<MutexArcInner<T>> }
pub struct MutexArc<T> { priv x: UnsafeArc<MutexArcInner<T>> }
impl<T:Send> Clone for MutexArc<T> {
@ -343,7 +343,7 @@ struct RWArcInner<T> { priv lock: RWLock, priv failed: bool, priv data: T }
* Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested.
*/
#[no_freeze]
struct RWArc<T> {
pub struct RWArc<T> {
priv x: UnsafeArc<RWArcInner<T>>,
}

View File

@ -127,7 +127,7 @@ impl WorkMap {
}
}
struct Database {
pub struct Database {
db_filename: Path,
db_cache: TreeMap<~str, ~str>,
db_dirty: bool
@ -207,7 +207,7 @@ impl Drop for Database {
}
}
struct Logger {
pub struct Logger {
// FIXME #4432: Fill in
a: ()
}
@ -223,10 +223,10 @@ impl Logger {
}
}
type FreshnessMap = TreeMap<~str,extern fn(&str,&str)->bool>;
pub type FreshnessMap = TreeMap<~str,extern fn(&str,&str)->bool>;
#[deriving(Clone)]
struct Context {
pub struct Context {
db: RWArc<Database>,
logger: RWArc<Logger>,
cfg: Arc<json::Object>,
@ -239,13 +239,13 @@ struct Context {
freshness: Arc<FreshnessMap>
}
struct Prep<'self> {
pub struct Prep<'self> {
ctxt: &'self Context,
fn_name: &'self str,
declared_inputs: WorkMap,
}
struct Exec {
pub struct Exec {
discovered_inputs: WorkMap,
discovered_outputs: WorkMap
}

View File

@ -197,6 +197,7 @@ pub fn phase_2_configure_and_expand(sess: Session,
pub struct CrateAnalysis {
exp_map2: middle::resolve::ExportMap2,
exported_items: @middle::privacy::ExportedItems,
ty_cx: ty::ctxt,
maps: astencode::Maps,
reachable: @mut HashSet<ast::NodeId>
@ -258,8 +259,9 @@ pub fn phase_3_run_analysis_passes(sess: Session,
middle::check_const::check_crate(sess, crate, ast_map, def_map,
method_map, ty_cx));
time(time_passes, ~"privacy checking", ||
middle::privacy::check_crate(ty_cx, &method_map, crate));
let exported_items =
time(time_passes, ~"privacy checking", ||
middle::privacy::check_crate(ty_cx, &method_map, &exp_map2, crate));
time(time_passes, ~"effect checking", ||
middle::effect::check_crate(ty_cx, method_map, crate));
@ -301,6 +303,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
CrateAnalysis {
exp_map2: exp_map2,
exported_items: @exported_items,
ty_cx: ty_cx,
maps: astencode::Maps {
root_map: root_map,

View File

@ -27,7 +27,8 @@ use syntax::diagnostic::expect;
pub struct StaticMethodInfo {
ident: ast::Ident,
def_id: ast::DefId,
purity: ast::purity
purity: ast::purity,
vis: ast::visibility,
}
pub fn get_symbol(cstore: @mut cstore::CStore, def: ast::DefId) -> ~str {
@ -52,7 +53,8 @@ pub fn each_lang_item(cstore: @mut cstore::CStore,
/// Iterates over each child of the given item.
pub fn each_child_of_item(cstore: @mut cstore::CStore,
def_id: ast::DefId,
callback: &fn(decoder::DefLike, ast::Ident)) {
callback: &fn(decoder::DefLike, ast::Ident,
ast::visibility)) {
let crate_data = cstore::get_crate_data(cstore, def_id.crate);
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
cstore::get_crate_data(cstore, cnum)
@ -68,7 +70,8 @@ pub fn each_child_of_item(cstore: @mut cstore::CStore,
pub fn each_top_level_item_of_crate(cstore: @mut cstore::CStore,
cnum: ast::CrateNum,
callback: &fn(decoder::DefLike,
ast::Ident)) {
ast::Ident,
ast::visibility)) {
let crate_data = cstore::get_crate_data(cstore, cnum);
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
cstore::get_crate_data(cstore, cnum)

View File

@ -96,7 +96,7 @@ fn find_item(item_id: int, items: ebml::Doc) -> ebml::Doc {
// Looks up an item in the given metadata and returns an ebml doc pointing
// to the item data.
fn lookup_item(item_id: int, data: @~[u8]) -> ebml::Doc {
pub fn lookup_item(item_id: int, data: @~[u8]) -> ebml::Doc {
let items = reader::get_doc(reader::Doc(data), tag_items);
find_item(item_id, items)
}
@ -291,7 +291,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> ~[ast::DefId] {
return ids;
}
fn item_path(item_doc: ebml::Doc) -> ast_map::path {
pub fn item_path(item_doc: ebml::Doc) -> ast_map::path {
let path_doc = reader::get_doc(item_doc, tag_path);
let len_doc = reader::get_doc(path_doc, tag_path_len);
@ -332,7 +332,7 @@ fn item_name(intr: @ident_interner, item: ebml::Doc) -> ast::Ident {
}
}
fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
pub fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
-> DefLike {
let fam = item_family(item);
match fam {
@ -491,7 +491,7 @@ pub enum DefLike {
DlField
}
fn def_like_to_def(def_like: DefLike) -> ast::Def {
pub fn def_like_to_def(def_like: DefLike) -> ast::Def {
match def_like {
DlDef(def) => return def,
DlImpl(*) => fail!("found impl in def_like_to_def"),
@ -544,7 +544,8 @@ impl<'self> EachItemContext<'self> {
fn process_item_and_pop_name(&mut self,
doc: ebml::Doc,
def_id: ast::DefId,
old_len: uint)
old_len: uint,
vis: ast::visibility)
-> bool {
let def_like = item_to_def_like(doc, def_id, self.cdata.cnum);
match def_like {
@ -563,8 +564,6 @@ impl<'self> EachItemContext<'self> {
}
}
let vis = item_visibility(doc);
let mut continue = (self.callback)(*self.path_builder, def_like, vis);
let family = item_family(doc);
@ -653,9 +652,12 @@ impl<'self> EachItemContext<'self> {
self.push_name(token::ident_to_str(&child_name));
// Process this item.
let vis = item_visibility(child_item_doc);
continue = self.process_item_and_pop_name(child_item_doc,
child_def_id,
old_len);
old_len,
vis);
}
}
continue
@ -701,12 +703,13 @@ impl<'self> EachItemContext<'self> {
// Get the item.
match maybe_find_item(def_id.node, other_crates_items) {
None => {}
None => { self.pop_name(old_len); }
Some(reexported_item_doc) => {
continue = self.process_item_and_pop_name(
reexported_item_doc,
def_id,
old_len);
old_len,
ast::public);
}
}
@ -721,7 +724,8 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
cdata: Cmd,
item_doc: ebml::Doc,
get_crate_data: GetCrateDataCb,
callback: &fn(DefLike, ast::Ident)) {
callback: &fn(DefLike, ast::Ident,
ast::visibility)) {
// Iterate over all children.
let _ = do reader::tagged_docs(item_doc, tag_mod_child) |child_info_doc| {
let child_def_id = reader::with_doc_data(child_info_doc,
@ -746,7 +750,8 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
let def_like = item_to_def_like(child_item_doc,
child_def_id,
cdata.cnum);
callback(def_like, child_name);
let visibility = item_visibility(child_item_doc);
callback(def_like, child_name, visibility);
}
}
@ -788,7 +793,8 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
impl_method_def_id,
cdata.cnum);
callback(static_method_def_like,
static_method_name);
static_method_name,
item_visibility(impl_method_doc));
}
_ => {}
}
@ -831,7 +837,8 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
let def_like = item_to_def_like(child_item_doc,
child_def_id,
cdata.cnum);
callback(def_like, token::str_to_ident(name));
callback(def_like, token::str_to_ident(name),
item_visibility(child_item_doc));
}
}
@ -844,7 +851,7 @@ pub fn each_child_of_item(intr: @ident_interner,
cdata: Cmd,
id: ast::NodeId,
get_crate_data: GetCrateDataCb,
callback: &fn(DefLike, ast::Ident)) {
callback: &fn(DefLike, ast::Ident, ast::visibility)) {
// Find the item.
let root_doc = reader::Doc(cdata.data);
let items = reader::get_doc(root_doc, tag_items);
@ -864,7 +871,8 @@ pub fn each_child_of_item(intr: @ident_interner,
pub fn each_top_level_item_of_crate(intr: @ident_interner,
cdata: Cmd,
get_crate_data: GetCrateDataCb,
callback: &fn(DefLike, ast::Ident)) {
callback: &fn(DefLike, ast::Ident,
ast::visibility)) {
let root_doc = reader::Doc(cdata.data);
let misc_info_doc = reader::get_doc(root_doc, tag_misc_info);
let crate_items_doc = reader::get_doc(misc_info_doc,
@ -1161,7 +1169,8 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
static_impl_methods.push(StaticMethodInfo {
ident: item_name(intr, impl_method_doc),
def_id: item_def_id(impl_method_doc, cdata),
purity: purity
purity: purity,
vis: item_visibility(impl_method_doc),
});
}
_ => {}

View File

@ -16,9 +16,9 @@ use metadata::cstore;
use metadata::decoder;
use metadata::tyencode;
use middle::ty::{node_id_to_type, lookup_item_type};
use middle::astencode;
use middle::ty;
use middle::typeck;
use middle::astencode;
use middle;
use std::hashmap::{HashMap, HashSet};
@ -58,6 +58,7 @@ pub struct EncodeParams<'self> {
diag: @mut span_handler,
tcx: ty::ctxt,
reexports2: middle::resolve::ExportMap2,
exported_items: @middle::privacy::ExportedItems,
item_symbols: &'self HashMap<ast::NodeId, ~str>,
discrim_symbols: &'self HashMap<ast::NodeId, @str>,
non_inlineable_statics: &'self HashSet<ast::NodeId>,
@ -88,6 +89,7 @@ pub struct EncodeContext<'self> {
tcx: ty::ctxt,
stats: @mut Stats,
reexports2: middle::resolve::ExportMap2,
exported_items: @middle::privacy::ExportedItems,
item_symbols: &'self HashMap<ast::NodeId, ~str>,
discrim_symbols: &'self HashMap<ast::NodeId, @str>,
non_inlineable_statics: &'self HashSet<ast::NodeId>,
@ -881,7 +883,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
item: @item,
index: @mut ~[entry<i64>],
path: &[ast_map::path_elt]) {
path: &[ast_map::path_elt],
vis: ast::visibility) {
let tcx = ecx.tcx;
fn add_to_index_(item: @item, ebml_w: &writer::Encoder,
@ -912,6 +915,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
if !ecx.non_inlineable_statics.contains(&item.id) {
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item(item));
}
encode_visibility(ebml_w, vis);
ebml_w.end_tag();
}
item_fn(_, purity, _, ref generics, _) => {
@ -929,6 +933,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
} else {
encode_symbol(ecx, ebml_w, item.id);
}
encode_visibility(ebml_w, vis);
ebml_w.end_tag();
}
item_mod(ref m) => {
@ -955,7 +960,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
ebml_w.wr_str(def_to_str(local_def(foreign_item.id)));
ebml_w.end_tag();
}
encode_visibility(ebml_w, vis);
ebml_w.end_tag();
}
item_ty(*) => {
@ -967,6 +972,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_name(ecx, ebml_w, item.ident);
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
encode_region_param(ecx, ebml_w, item);
encode_visibility(ebml_w, vis);
ebml_w.end_tag();
}
item_enum(ref enum_definition, ref generics) => {
@ -987,6 +993,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
// Encode inherent implementations for this enumeration.
encode_inherent_implementations(ecx, ebml_w, def_id);
encode_visibility(ebml_w, vis);
ebml_w.end_tag();
encode_enum_variant_info(ecx,
@ -1018,6 +1025,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_attributes(ebml_w, item.attrs);
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
encode_region_param(ecx, ebml_w, item);
encode_visibility(ebml_w, vis);
/* Encode def_ids for each field and method
for methods, write all the stuff get_trait_method
@ -1264,7 +1272,12 @@ fn my_visit_item(i:@item, items: ast_map::map, ebml_w:&writer::Encoder,
let mut ebml_w = ebml_w.clone();
// See above
let ecx : &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
encode_info_for_item(ecx, &mut ebml_w, i, index, *pt);
let vis = if ecx.exported_items.contains(&i.id) {
ast::public
} else {
ast::inherited
};
encode_info_for_item(ecx, &mut ebml_w, i, index, *pt, vis);
}
_ => fail!("bad item")
}
@ -1727,6 +1740,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
diag,
tcx,
reexports2,
exported_items,
discrim_symbols,
cstore,
encode_inlined_item,
@ -1742,6 +1756,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
tcx: tcx,
stats: stats,
reexports2: reexports2,
exported_items: exported_items,
item_symbols: item_symbols,
discrim_symbols: discrim_symbols,
non_inlineable_statics: non_inlineable_statics,

View File

@ -150,7 +150,7 @@ fn make_rustpkg_target_lib_path(dir: &Path,
dir.push_rel(&Path(libdir()).push(target_triple.to_owned()))
}
fn get_or_default_sysroot() -> Path {
pub fn get_or_default_sysroot() -> Path {
match os::self_exe_path() {
option::Some(ref p) => (*p).pop(),
option::None => fail!("can't determine value for sysroot")

View File

@ -9,9 +9,13 @@
// except according to those terms.
//! A pass that checks to make sure private fields and methods aren't used
//! outside their scopes.
//! outside their scopes. This pass will also generate a set of exported items
//! which are available for use externally when compiled as a library.
use std::hashmap::HashSet;
use metadata::csearch;
use middle::resolve::ExportMap2;
use middle::ty::{ty_struct, ty_enum};
use middle::ty;
use middle::typeck::{method_map, method_origin, method_param};
@ -37,9 +41,23 @@ use syntax::visit;
use syntax::visit::Visitor;
use syntax::ast::{_mod,Expr,item,Block,Pat};
// This set is a set of all item nodes which can be used by external crates if
// we're building a library. The necessary qualifications for this are that all
// items leading down to the current item (excluding an `impl`) must be `pub`.
pub type ExportedItems = HashSet<NodeId>;
type Context<'self> = (&'self method_map, &'self ExportMap2);
struct PrivacyVisitor {
tcx: ty::ctxt,
privileged_items: @mut ~[NodeId],
// A set of all items which are re-exported to be used across crates
exported_items: ExportedItems,
// A flag as to whether the current path is public all the way down to the
// current point or not
path_all_public: bool,
}
impl PrivacyVisitor {
@ -265,15 +283,20 @@ impl PrivacyVisitor {
.last()
.identifier)));
}
} else if csearch::get_item_visibility(self.tcx.sess.cstore,
def_id) != public {
self.tcx.sess.span_err(span,
fmt!("function `%s` is private",
token::ident_to_str(
&path.segments
.last()
.identifier)));
//} else if csearch::get_item_visibility(self.tcx.sess.cstore,
// def_id) != public {
// self.tcx.sess.span_err(span,
// fmt!("function `%s` is private",
// token::ident_to_str(
// &path.segments
// .last()
// .identifier)));
}
// If this is a function from a non-local crate, then the
// privacy check is enforced during resolve. All public items
// will be tagged as such in the crate metadata and then usage
// of the private items will be blocked during resolve. Hence,
// if this isn't from the local crate, nothing to check.
}
_ => {}
}
@ -341,31 +364,78 @@ impl PrivacyVisitor {
}
}
impl<'self> Visitor<&'self method_map> for PrivacyVisitor {
impl<'self> Visitor<Context<'self>> for PrivacyVisitor {
fn visit_mod<'mm>(&mut self, the_module:&_mod, _:Span, _:NodeId,
method_map:&'mm method_map) {
fn visit_mod(&mut self, the_module:&_mod, _:Span, _:NodeId,
cx: Context<'self>) {
let n_added = self.add_privileged_items(the_module.items);
visit::walk_mod(self, the_module, method_map);
visit::walk_mod(self, the_module, cx);
do n_added.times {
ignore(self.privileged_items.pop());
}
}
fn visit_item<'mm>(&mut self, item:@item, method_map:&'mm method_map) {
fn visit_item(&mut self, item:@item, cx: Context<'self>) {
// Do not check privacy inside items with the resolve_unexported
// attribute. This is used for the test runner.
if !attr::contains_name(item.attrs, "!resolve_unexported") {
check_sane_privacy(self.tcx, item);
visit::walk_item(self, item, method_map);
// Do not check privacy inside items with the resolve_unexported
// attribute. This is used for the test runner.
if attr::contains_name(item.attrs, "!resolve_unexported") {
return;
}
// Disallow unnecessary visibility qualifiers
check_sane_privacy(self.tcx, item);
// Keep track of whether this item is available for export or not.
let orig_all_pub = self.path_all_public;
match item.node {
// impls/extern blocks do not break the "public chain" because they
// cannot have visibility qualifiers on them anyway
ast::item_impl(*) | ast::item_foreign_mod(*) => {}
// Private by default, hence we only retain the "public chain" if
// `pub` is explicitly listed.
_ => {
self.path_all_public = orig_all_pub && item.vis == ast::public;
}
}
debug2!("public path at {}: {}", item.id, self.path_all_public);
if self.path_all_public {
debug2!("all the way public {}", item.id);
self.exported_items.insert(item.id);
// All re-exported items in a module which is public should also be
// public (in terms of how they should get encoded)
match item.node {
ast::item_mod(*) => {
let (_, exp_map2) = cx;
match exp_map2.find(&item.id) {
Some(exports) => {
for export in exports.iter() {
if export.reexport && is_local(export.def_id) {
debug2!("found reexported {:?}", export);
let id = export.def_id.node;
self.exported_items.insert(id);
}
}
}
None => {}
}
}
_ => {}
}
}
visit::walk_item(self, item, cx);
self.path_all_public = orig_all_pub;
}
fn visit_block<'mm>(&mut self, block:&Block, method_map:&'mm method_map) {
fn visit_block(&mut self, block:&Block, cx: Context<'self>) {
// Gather up all the privileged items.
let mut n_added = 0;
@ -383,7 +453,7 @@ impl<'self> Visitor<&'self method_map> for PrivacyVisitor {
}
}
visit::walk_block(self, block, method_map);
visit::walk_block(self, block, cx);
do n_added.times {
ignore(self.privileged_items.pop());
@ -391,8 +461,8 @@ impl<'self> Visitor<&'self method_map> for PrivacyVisitor {
}
fn visit_expr<'mm>(&mut self, expr:@Expr, method_map:&'mm method_map) {
fn visit_expr(&mut self, expr:@Expr, cx: Context<'self>) {
let (method_map, _) = cx;
match expr.node {
ExprField(base, ident, _) => {
// Method calls are now a special syntactic form,
@ -499,11 +569,11 @@ impl<'self> Visitor<&'self method_map> for PrivacyVisitor {
_ => {}
}
visit::walk_expr(self, expr, method_map);
visit::walk_expr(self, expr, cx);
}
fn visit_pat<'mm>(&mut self, pattern:@Pat, method_map:&'mm method_map) {
fn visit_pat(&mut self, pattern:@Pat, cx: Context<'self>) {
match pattern.node {
PatStruct(_, ref fields, _) => {
@ -550,20 +620,24 @@ impl<'self> Visitor<&'self method_map> for PrivacyVisitor {
_ => {}
}
visit::walk_pat(self, pattern, method_map);
visit::walk_pat(self, pattern, cx);
}
}
pub fn check_crate<'mm>(tcx: ty::ctxt,
method_map: &'mm method_map,
crate: &ast::Crate) {
pub fn check_crate(tcx: ty::ctxt,
method_map: &method_map,
exp_map2: &ExportMap2,
crate: &ast::Crate) -> ExportedItems {
let privileged_items = @mut ~[];
let mut visitor = PrivacyVisitor {
tcx: tcx,
privileged_items: privileged_items,
exported_items: HashSet::new(),
path_all_public: true, // start out as public
};
visit::walk_crate(&mut visitor, crate, method_map);
visit::walk_crate(&mut visitor, crate, (method_map, exp_map2));
return visitor.exported_items;
}
/// Validates all of the visibility qualifers placed on the item given. This
@ -571,17 +645,45 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
/// anything. In theory these qualifiers wouldn't parse, but that may happen
/// later on down the road...
fn check_sane_privacy(tcx: ty::ctxt, item: @ast::item) {
let check_inherited = |sp: Span, vis: ast::visibility, note: &str| {
if vis != ast::inherited {
tcx.sess.span_err(sp, "unnecessary visibility qualifier");
if note.len() > 0 {
tcx.sess.span_note(sp, note);
}
}
};
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);
}
}
};
match item.node {
// implementations of traits don't need visibility qualifiers because
// that's controlled by having the trait in scope.
ast::item_impl(_, Some(*), _, ref methods) => {
check_inherited(item.span, item.vis,
"visibility qualifiers have no effect on trait impls");
for m in methods.iter() {
match m.vis {
ast::private | ast::public => {
tcx.sess.span_err(m.span, "unnecessary visibility")
}
ast::inherited => {}
}
check_inherited(m.span, m.vis, "");
}
}
ast::item_impl(_, _, _, ref methods) => {
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::item_foreign_mod(ref fm) => {
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");
}
}
@ -624,22 +726,18 @@ fn check_sane_privacy(tcx: ty::ctxt, item: @ast::item) {
for m in methods.iter() {
match *m {
ast::provided(ref m) => {
match m.vis {
ast::private | ast::public => {
tcx.sess.span_err(m.span, "unnecessary \
visibility");
}
ast::inherited => {}
}
check_inherited(m.span, m.vis,
"unnecessary visibility");
}
// this is warned about in the parser
ast::required(*) => {}
}
}
}
ast::item_impl(*) | ast::item_static(*) | ast::item_foreign_mod(*) |
ast::item_static(*) |
ast::item_fn(*) | ast::item_mod(*) | ast::item_ty(*) |
ast::item_mac(*) => {}
ast::item_mac(*) => {
check_not_priv(item.span, item.vis, "items are private by default");
}
}
}

View File

@ -1661,6 +1661,9 @@ impl Resolver {
ident: Ident,
new_parent: ReducedGraphParent) {
let privacy = visibility_to_privacy(visibility);
debug!("(building reduced graph for \
external crate) building external def, priv %?",
privacy);
match def {
DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) |
DefTy(def_id) => {
@ -1788,7 +1791,8 @@ impl Resolver {
fn build_reduced_graph_for_external_crate_def(@mut self,
root: @mut Module,
def_like: DefLike,
ident: Ident) {
ident: Ident,
visibility: visibility) {
match def_like {
DlDef(def) => {
// Add the new child item, if necessary.
@ -1798,11 +1802,12 @@ impl Resolver {
// eagerly.
do csearch::each_child_of_item(self.session.cstore,
def_id)
|def_like, child_ident| {
|def_like, child_ident, vis| {
self.build_reduced_graph_for_external_crate_def(
root,
def_like,
child_ident)
child_ident,
vis)
}
}
_ => {
@ -1813,7 +1818,7 @@ impl Resolver {
dummy_sp());
self.handle_external_def(def,
public,
visibility,
child_name_bindings,
self.session.str_of(ident),
ident,
@ -1897,10 +1902,11 @@ impl Resolver {
let def = DefFn(
static_method_info.def_id,
static_method_info.purity);
let p = visibility_to_privacy(
static_method_info.vis);
method_name_bindings.define_value(
Public,
def,
dummy_sp());
p, def, dummy_sp());
}
}
@ -1931,12 +1937,13 @@ impl Resolver {
};
do csearch::each_child_of_item(self.session.cstore, def_id)
|def_like, child_ident| {
|def_like, child_ident, visibility| {
debug!("(populating external module) ... found ident: %s",
token::ident_to_str(&child_ident));
self.build_reduced_graph_for_external_crate_def(module,
def_like,
child_ident)
child_ident,
visibility)
}
module.populated = true
}
@ -1956,10 +1963,11 @@ impl Resolver {
root: @mut Module) {
do csearch::each_top_level_item_of_crate(self.session.cstore,
root.def_id.unwrap().crate)
|def_like, ident| {
|def_like, ident, visibility| {
self.build_reduced_graph_for_external_crate_def(root,
def_like,
ident)
ident,
visibility)
}
}

View File

@ -3007,6 +3007,7 @@ pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::encode_
diag: diag,
tcx: cx.tcx,
reexports2: cx.exp_map2,
exported_items: cx.exported_items,
item_symbols: item_symbols,
discrim_symbols: discrim_symbols,
non_inlineable_statics: &cx.non_inlineable_statics,
@ -3100,6 +3101,7 @@ pub fn trans_crate(sess: session::Session,
llmod_id,
analysis.ty_cx,
analysis.exp_map2,
analysis.exported_items,
analysis.maps,
symbol_hasher,
link_meta,

View File

@ -16,6 +16,7 @@ use lib::llvm::{llvm, TargetData, TypeNames};
use lib::llvm::mk_target_data;
use metadata::common::LinkMeta;
use middle::astencode;
use middle::privacy;
use middle::resolve;
use middle::trans::adt;
use middle::trans::base;
@ -49,6 +50,7 @@ pub struct CrateContext {
intrinsics: HashMap<&'static str, ValueRef>,
item_vals: HashMap<ast::NodeId, ValueRef>,
exp_map2: resolve::ExportMap2,
exported_items: @privacy::ExportedItems,
reachable: @mut HashSet<ast::NodeId>,
item_symbols: HashMap<ast::NodeId, ~str>,
link_meta: LinkMeta,
@ -127,6 +129,7 @@ impl CrateContext {
name: &str,
tcx: ty::ctxt,
emap2: resolve::ExportMap2,
exported_items: @privacy::ExportedItems,
maps: astencode::Maps,
symbol_hasher: hash::State,
link_meta: LinkMeta,
@ -187,6 +190,7 @@ impl CrateContext {
intrinsics: intrinsics,
item_vals: HashMap::new(),
exp_map2: emap2,
exported_items: exported_items,
reachable: reachable,
item_symbols: HashMap::new(),
link_meta: link_meta,

View File

@ -702,7 +702,7 @@ impl AstBuilder for @ExtCtxt {
attrs: attrs,
id: ast::DUMMY_NODE_ID,
node: node,
vis: ast::public,
vis: ast::inherited,
span: span }
}

View File

@ -44,7 +44,6 @@ pub enum ObsoleteSyntax {
ObsoleteImplSyntax,
ObsoleteMutOwnedPointer,
ObsoleteMutVector,
ObsoleteImplVisibility,
ObsoleteRecordType,
ObsoleteRecordPattern,
ObsoletePostFnTySigil,
@ -60,9 +59,7 @@ pub enum ObsoleteSyntax {
ObsoleteNamedExternModule,
ObsoleteMultipleLocalDecl,
ObsoleteMutWithMultipleBindings,
ObsoleteExternVisibility,
ObsoleteUnsafeExternFn,
ObsoletePrivVisibility,
ObsoleteTraitFuncVisibility,
ObsoleteConstPointer,
ObsoleteEmptyImpl,
@ -162,11 +159,6 @@ impl ParserObsoleteMethods for Parser {
in a mutable location, like a mutable local variable or an \
`@mut` box"
),
ObsoleteImplVisibility => (
"visibility-qualified implementation",
"`pub` or `priv` goes on individual functions; remove the \
`pub` or `priv`"
),
ObsoleteRecordType => (
"structural record type",
"use a structure instead"
@ -234,20 +226,11 @@ impl ParserObsoleteMethods for Parser {
"use multiple local declarations instead of e.g. `let mut \
(x, y) = ...`."
),
ObsoleteExternVisibility => (
"`pub extern` or `priv extern`",
"place the `pub` or `priv` on the individual external items \
instead"
),
ObsoleteUnsafeExternFn => (
"unsafe external function",
"external functions are always unsafe; remove the `unsafe` \
keyword"
),
ObsoletePrivVisibility => (
"`priv` not necessary",
"an item without a visibility qualifier is private by default"
),
ObsoleteTraitFuncVisibility => (
"visibility not necessary",
"trait functions inherit the visibility of the trait itself"

View File

@ -922,7 +922,7 @@ impl Parser {
let attrs = p.parse_outer_attributes();
let lo = p.span.lo;
let vis = p.parse_non_priv_visibility();
let vis = p.parse_visibility();
let pur = p.parse_fn_purity();
// NB: at the moment, trait methods are public by default; this
// could change.
@ -3753,7 +3753,7 @@ impl Parser {
let attrs = self.parse_outer_attributes();
let lo = self.span.lo;
let visa = self.parse_non_priv_visibility();
let visa = self.parse_visibility();
let pur = self.parse_fn_purity();
let ident = self.parse_ident();
let generics = self.parse_generics();
@ -3801,7 +3801,7 @@ impl Parser {
// Parses two variants (with the region/type params always optional):
// impl<T> Foo { ... }
// impl<T> ToStr for ~[T] { ... }
fn parse_item_impl(&self, visibility: ast::visibility) -> item_info {
fn parse_item_impl(&self) -> item_info {
// First, parse type parameters if necessary.
let generics = self.parse_generics();
@ -3846,11 +3846,6 @@ impl Parser {
None
};
// Do not allow visibility to be specified.
if visibility != ast::inherited {
self.obsolete(*self.span, ObsoleteImplVisibility);
}
let mut meths = ~[];
if self.eat(&token::SEMI) {
self.obsolete(*self.span, ObsoleteEmptyImpl);
@ -4014,18 +4009,6 @@ impl Parser {
else { inherited }
}
// parse visibility, but emits an obsolete error if it's private
fn parse_non_priv_visibility(&self) -> visibility {
match self.parse_visibility() {
public => public,
inherited => inherited,
private => {
self.obsolete(*self.last_span, ObsoletePrivVisibility);
inherited
}
}
}
fn parse_staticness(&self) -> bool {
if self.eat_keyword(keywords::Static) {
self.obsolete(*self.last_span, ObsoleteStaticMethod);
@ -4218,7 +4201,7 @@ impl Parser {
// parse a function declaration from a foreign module
fn parse_item_foreign_fn(&self, attrs: ~[Attribute]) -> @foreign_item {
let lo = self.span.lo;
let vis = self.parse_non_priv_visibility();
let vis = self.parse_visibility();
// Parse obsolete purity.
let purity = self.parse_fn_purity();
@ -4354,11 +4337,6 @@ impl Parser {
self.obsolete(*self.last_span, ObsoleteNamedExternModule);
}
// Do not allow visibility to be specified.
if visibility != ast::inherited {
self.obsolete(*self.last_span, ObsoleteExternVisibility);
}
let abis = opt_abis.unwrap_or(AbiSet::C());
let (inner, next) = self.parse_inner_attrs_and_next();
@ -4369,7 +4347,7 @@ impl Parser {
self.last_span.hi,
ident,
item_foreign_mod(m),
public,
visibility,
maybe_append(attrs, Some(inner))));
}
@ -4616,7 +4594,7 @@ impl Parser {
let lo = self.span.lo;
let visibility = self.parse_non_priv_visibility();
let visibility = self.parse_visibility();
// must be a view item:
if self.eat_keyword(keywords::Use) {
@ -4724,8 +4702,7 @@ impl Parser {
}
if self.eat_keyword(keywords::Impl) {
// IMPL ITEM
let (ident, item_, extra_attrs) =
self.parse_item_impl(visibility);
let (ident, item_, extra_attrs) = self.parse_item_impl();
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs)));
@ -4748,7 +4725,7 @@ impl Parser {
maybe_whole!(iovi self, nt_item);
let lo = self.span.lo;
let visibility = self.parse_non_priv_visibility();
let visibility = self.parse_visibility();
if (self.is_keyword(keywords::Const) || self.is_keyword(keywords::Static)) {
// FOREIGN CONST ITEM

View File

@ -11,7 +11,7 @@
#[link (name = "issue2378a")];
#[crate_type = "lib"];
enum maybe<T> { just(T), nothing }
pub enum maybe<T> { just(T), nothing }
impl <T:Clone> Index<uint,T> for maybe<T> {
fn index(&self, _idx: &uint) -> T {

View File

@ -15,7 +15,7 @@ extern mod issue2378a;
use issue2378a::maybe;
struct two_maybes<T> {a: maybe<T>, b: maybe<T>}
pub struct two_maybes<T> {a: maybe<T>, b: maybe<T>}
impl<T:Clone> Index<uint,(T,T)> for two_maybes<T> {
fn index(&self, idx: &uint) -> (T, T) {

View File

@ -9,7 +9,7 @@
// except according to those terms.
// original problem
fn foo<T>() -> int {
pub fn foo<T>() -> int {
{
static foo: int = 2;
foo

View File

@ -1,5 +1,5 @@
#[packed]
struct S {
pub struct S {
a: u8,
b: u32
}

View File

@ -0,0 +1,57 @@
// 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.
#[crate_type = "lib"];
#[no_std];
static private: int = 0;
pub static public: int = 0;
pub struct A(());
impl A {
fn foo() {}
}
mod foo {
pub static a: int = 0;
pub fn b() {}
pub struct c;
pub enum d {}
pub struct A(());
impl A {
fn foo() {}
}
// these are public so the parent can reexport them.
pub static reexported_a: int = 0;
pub fn reexported_b() {}
pub struct reexported_c;
pub enum reexported_d {}
}
pub mod bar {
pub use e = foo::reexported_a;
pub use f = foo::reexported_b;
pub use g = foo::reexported_c;
pub use h = foo::reexported_d;
}
pub static a: int = 0;
pub fn b() {}
pub struct c;
pub enum d {}
static i: int = 0;
fn j() {}
struct k;
enum l {}

View File

@ -54,9 +54,9 @@ extern mod obsolete_name {
fn bar();
}
pub extern {
//~^ ERROR obsolete syntax: `pub extern`
pub fn bar();
trait A {
pub fn foo(); //~ ERROR: visibility not necessary
pub fn bar(); //~ ERROR: visibility not necessary
}
fn main() { }

View File

@ -0,0 +1,28 @@
// 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.
pub extern {
//~^ ERROR unnecessary visibility
pub fn bar();
}
trait A {
fn foo() {}
}
struct B;
pub impl B {} //~ ERROR: unnecessary visibility
pub impl A for B { //~ ERROR: unnecessary visibility
pub fn foo() {} //~ ERROR: unnecessary visibility
}
pub fn main() {}

View File

@ -0,0 +1,39 @@
// 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.
// aux-build:static_priv_by_default.rs
#[no_std];
extern mod static_priv_by_default;
mod child {
pub mod childs_child {
static private: int = 0;
pub static public: int = 0;
}
}
fn foo(_: int) {}
fn full_ref() {
foo(static_priv_by_default::private); //~ ERROR: unresolved name
foo(static_priv_by_default::public);
foo(child::childs_child::private); //~ ERROR: unresolved name
foo(child::childs_child::public);
}
fn medium_ref() {
use child::childs_child;
foo(childs_child::private); //~ ERROR: unresolved name
foo(childs_child::public);
}
fn main() {}

View File

@ -0,0 +1,29 @@
// 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.
// aux-build:static_priv_by_default.rs
extern mod static_priv_by_default;
mod child {
pub mod childs_child {
static private: int = 0;
pub static public: int = 0;
}
}
fn main() {
use static_priv_by_default::private; //~ ERROR: unresolved import
//~^ ERROR: failed to resolve
use static_priv_by_default::public;
use child::childs_child::private; //~ ERROR: unresolved import
//~^ ERROR: failed to resolve
use child::childs_child::public;
}

View File

@ -12,8 +12,3 @@ pub trait E {
pub fn foo(); //~ ERROR: obsolete syntax
}
trait F { pub fn foo(); } //~ ERROR: obsolete syntax
struct B;
impl E for B {
priv fn foo() {} //~ ERROR: obsolete syntax
}

View File

@ -1,16 +1,22 @@
// 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.
// xfail-fast
// aux-build:xc_private_method_lib.rs
extern mod xc_private_method_lib;
fn main() {
// normal method on struct
let _ = xc_private_method_lib::Struct{ x: 10 }.meth_struct(); //~ ERROR method `meth_struct` is private
// static method on struct
let _ = xc_private_method_lib::Struct::static_meth_struct(); //~ ERROR method `static_meth_struct` is private
let _ = xc_private_method_lib::Struct::static_meth_struct();
//~^ ERROR: unresolved name
// normal method on enum
let _ = xc_private_method_lib::Variant1(20).meth_enum(); //~ ERROR method `meth_enum` is private
// static method on enum
let _ = xc_private_method_lib::Enum::static_meth_enum(); //~ ERROR method `static_meth_enum` is private
let _ = xc_private_method_lib::Enum::static_meth_enum();
//~^ ERROR: unresolved name
}

View File

@ -0,0 +1,20 @@
// 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.
// xfail-fast
// aux-build:xc_private_method_lib.rs
extern mod xc_private_method_lib;
fn main() {
let _ = xc_private_method_lib::Struct{ x: 10 }.meth_struct(); //~ ERROR method `meth_struct` is private
let _ = xc_private_method_lib::Variant1(20).meth_enum(); //~ ERROR method `meth_enum` is private
}

View File

@ -0,0 +1,57 @@
// 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.
// aux-build:static_priv_by_default.rs
#[allow(unused_imports)];
#[no_std];
extern mod static_priv_by_default;
fn foo<T>() {}
#[start]
fn main(_: int, _: **u8, _: *u8) -> int {
// Actual public items should be public
static_priv_by_default::a;
static_priv_by_default::b;
static_priv_by_default::c;
foo::<static_priv_by_default::d>();
// publicly re-exported items should be available
static_priv_by_default::bar::e;
static_priv_by_default::bar::f;
static_priv_by_default::bar::g;
foo::<static_priv_by_default::bar::h>();
// private items at the top should be inaccessible
static_priv_by_default::i;
//~^ ERROR: unresolved name
static_priv_by_default::j;
//~^ ERROR: unresolved name
static_priv_by_default::k;
//~^ ERROR: unresolved name
foo::<static_priv_by_default::l>();
//~^ ERROR: use of undeclared type name
//~^^ ERROR: use of undeclared type name
// public items in a private mod should be inaccessible
static_priv_by_default::foo::a;
//~^ ERROR: unresolved name
static_priv_by_default::foo::b;
//~^ ERROR: unresolved name
static_priv_by_default::foo::c;
//~^ ERROR: unresolved name
foo::<static_priv_by_default::foo::d>();
//~^ ERROR: use of undeclared type name
//~^^ ERROR: use of undeclared type name
3
}

View File

@ -20,6 +20,6 @@ impl<T> Drop for Test<T> {
fn drop(&mut self) { }
}
fn main() {
pub fn main() {
assert_eq!(size_of::<int>(), size_of::<Test<int>>());
}

View File

@ -26,4 +26,4 @@ impl Foo {
fn check_id(&mut self, s: int) { fail!() }
}
fn main() { }
pub fn main() { }

View File

@ -43,5 +43,5 @@ fn match_mut_reg(v: &mut Option<int>) {
}
}
fn main() {
pub fn main() {
}

View File

@ -10,6 +10,6 @@
// Regression test for issue #7740
fn main() {
pub fn main() {
static A: &'static char = &'A';
}

View File

@ -26,7 +26,7 @@ fn noncopyable() -> noncopyable {
struct wrapper(noncopyable);
fn main() {
pub fn main() {
let x1 = wrapper(noncopyable());
let _x2 = *x1;
}

View File

@ -50,5 +50,5 @@ fn box_imm_recs(v: &Outer) {
borrow(v.f.g.h); // OK
}
fn main() {
pub fn main() {
}

View File

@ -27,7 +27,7 @@
// run-fail/borrowck-wg-autoderef-and-autoborrowvec-combined-fail-issue-6272.rs
fn main() {
pub fn main() {
let a = @mut 3i;
let b = @mut [a];
let c = @mut [3];

View File

@ -33,7 +33,7 @@ impl<T: Speak> Speak for Option<T> {
}
fn main() {
pub fn main() {
assert_eq!(3.hi(), ~"hello: 3");
assert_eq!(Some(Some(3)).hi(), ~"something!something!hello: 3");
assert_eq!(None::<int>.hi(), ~"hello - none");

View File

@ -26,7 +26,7 @@ fn foo<T: Foo>(val: T, chan: comm::Chan<T>) {
chan.send(val);
}
fn main() {
pub fn main() {
let (p,c) = comm::stream();
foo(31337, c);
assert!(p.recv() == 31337);

View File

@ -22,7 +22,7 @@ fn foo<T: Foo>(val: T, chan: comm::Chan<T>) {
chan.send(val);
}
fn main() {
pub fn main() {
let (p,c) = comm::stream();
foo(31337, c);
assert!(p.recv() == 31337);

View File

@ -18,4 +18,4 @@ struct X<T>(());
impl <T> Foo for X<T> { }
fn main() { }
pub fn main() { }

View File

@ -21,7 +21,7 @@ trait Foo : Send {
impl <T: Send> Foo for T { }
fn main() {
pub fn main() {
let (p,c) = comm::stream();
1193182.foo(c);
assert!(p.recv() == 1193182);

View File

@ -14,4 +14,4 @@ trait Foo : Send { }
impl Foo for int { }
fn main() { }
pub fn main() { }

View File

@ -15,4 +15,4 @@ trait Foo : Send { }
impl <T: Send> Foo for T { }
fn main() { }
pub fn main() { }

View File

@ -25,10 +25,10 @@ fn bar(t: @mut T) {
t.foo();
}
fn main() {
pub fn main() {
let s = @mut S { unused: 0 };
let s2 = s as @mut T;
s2.foo();
bar(s2);
bar(s as @mut T);
}
}

View File

@ -14,7 +14,7 @@ fn foo(blk: ~fn:Send()) {
blk();
}
fn main() {
pub fn main() {
let (p,c) = comm::stream();
do foo {
c.send(());

View File

@ -56,7 +56,7 @@ static am: bool = 2 > 1;
static an: bool = 2 > -2;
static ao: bool = 1.0 > -2.0;
fn main() {
pub fn main() {
assert_eq!(a, -1);
assert_eq!(a2, 6);
assert_approx_eq!(b, 5.7);

View File

@ -10,4 +10,4 @@ struct Bar {
static bar: Bar = Bar { i: 0, v: IntVal(0) };
fn main() {}
pub fn main() {}

View File

@ -12,4 +12,4 @@ trait Foo {
fn m(&self, _:int) { }
}
fn main() { }
pub fn main() { }

View File

@ -31,6 +31,6 @@ impl Y for int {
impl Z for int {}
fn main() {
pub fn main() {
assert_eq!(12.x(), 12);
}

View File

@ -15,7 +15,7 @@ enum E<T,U> {
C
}
fn main() {
pub fn main() {
let _ = A::<int, int>(1i).clone();
let _ = B(1i, 1.234).deep_clone();
}

View File

@ -11,6 +11,6 @@
#[deriving(Clone, DeepClone)]
struct S<T>(T, ());
fn main() {
pub fn main() {
let _ = S(1i, ()).clone().deep_clone();
}

View File

@ -31,4 +31,4 @@ struct S {
_nil: ()
}
fn main() {}
pub fn main() {}

View File

@ -35,7 +35,7 @@ struct ShortCircuit {
y: FailCmp
}
fn main() {
pub fn main() {
let a = ShortCircuit { x: 1, y: FailCmp };
let b = ShortCircuit { x: 2, y: FailCmp };

View File

@ -13,7 +13,7 @@ struct A<'self> {
x: &'self int
}
fn main() {
pub fn main() {
let a = A { x: &1 };
let b = A { x: &2 };

View File

@ -34,7 +34,7 @@ impl ToStr for Custom {
fn to_str(&self) -> ~str { ~"yay" }
}
fn main() {
pub fn main() {
assert_eq!(B1.to_str(), ~"B1");
assert_eq!(B2.to_str(), ~"B2");
assert_eq!(C1(3).to_str(), ~"C1(3)");

View File

@ -33,7 +33,7 @@ struct Lots {
j: (),
}
fn main() {
pub fn main() {
let lots: Lots = Zero::zero();
assert!(lots.is_zero());
}

View File

@ -12,7 +12,7 @@ enum Hero {
Spiderman = -4
}
fn main() {
pub fn main() {
let pet: Animal = Snake;
let hero: Hero = Superman;
assert!(pet as uint == 3);

View File

@ -15,7 +15,7 @@ enum Flopsy {
static BAR:uint = Bunny as uint;
static BAR2:uint = BAR;
fn main() {
pub fn main() {
let _v = [0, .. Bunny as uint];
let _v = [0, .. BAR];
let _v = [0, .. BAR2];

View File

@ -1,6 +1,6 @@
use std::io::println;
fn main() {
pub fn main() {
let v: ~[int] = ~[ 1, ..5 ];
println(v[0].to_str());
println(v[1].to_str());

View File

@ -12,7 +12,7 @@
extern fn f(x: uint) -> uint { x * 2 }
fn main() {
pub fn main() {
#[fixed_stack_segment];
let x = f(22);

View File

@ -19,7 +19,7 @@ extern fn uintvoidret(_x: uint) {}
extern fn uintuintuintuintret(x: uint, y: uint, z: uint) -> uint { x+y+z }
fn main() {
pub fn main() {
assert_eq!(voidret1, voidret1);
assert!(voidret1 != voidret2);

View File

@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
pub fn main() {
assert!(option_env!("__HOPEFULLY_DOESNT_EXIST__").is_none());
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
pub fn main() {
// Make sure that this view item is filtered out because otherwise it would
// trigger a compilation error
#[cfg(not_present)] use foo = bar;

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
pub fn main() {
let x = [1,..100];
let mut y = 0;
for i in x.iter() {

View File

@ -14,7 +14,7 @@ use std::hashmap::HashMap;
// outside the loop, breaks, then _picks back up_ and continues
// iterating with it.
fn main() {
pub fn main() {
let mut h = HashMap::new();
let kvs = [(1, 10), (2, 20), (3, 30)];
for &(k,v) in kvs.iter() {
@ -38,4 +38,4 @@ fn main() {
assert_eq!(x, 6);
assert_eq!(y, 60);
}
}

View File

@ -10,7 +10,7 @@
use std::hashmap::HashMap;
fn main() {
pub fn main() {
let mut h = HashMap::new();
let kvs = [(1, 10), (2, 20), (3, 30)];
for &(k,v) in kvs.iter() {
@ -24,4 +24,4 @@ fn main() {
}
assert_eq!(x, 6);
assert_eq!(y, 60);
}
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
pub fn main() {
let x = [1,..100];
let mut y = 0;
for (n,i) in x.iter().enumerate() {

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
pub fn main() {
let x = [1,..100];
let y = [2,..100];
let mut p = 0;

View File

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
pub fn main() {
let x = [1,..100];
let mut y = 0;
for i in x.iter() {
y += *i
}
assert!(y == 100);
}
}

View File

@ -11,10 +11,10 @@ fn foo(Foo {x, _}: Foo) -> *uint {
addr
}
fn main() {
pub fn main() {
let obj = ~1;
let objptr: *uint = &*obj;
let f = Foo {x: obj, y: ~2};
let xptr = foo(f);
assert_eq!(objptr, xptr);
}
}

View File

@ -13,7 +13,7 @@ fn checkval(~ref x: ~uint) -> uint {
*x
}
fn main() {
pub fn main() {
let obj = ~1;
let objptr: *uint = &*obj;
let xptr = getaddr(obj);

View File

@ -5,6 +5,6 @@ fn foo((x, _): (int, int)) -> int {
x
}
fn main() {
pub fn main() {
assert_eq!(foo((22, 23)), 22);
}

View File

@ -22,6 +22,6 @@ impl<T> vec_utils<T> for ~[T] {
}
}
fn main() {
pub fn main() {
assert_eq!(vec_utils::map_(&~[1,2,3], |&x| x+1), ~[2,3,4]);
}

View File

@ -12,7 +12,7 @@ mod x {
pub fn g() -> uint {14}
}
fn main(){
pub fn main(){
// should *not* shadow the module x:
let x = 9;
// use it to avoid warnings:

View File

@ -23,4 +23,4 @@ impl A for E {
fn b<F,G>(_x: F) -> F { fail!() } //~ ERROR in method `b`, type parameter 0 has 1 bound, but
}
fn main() {}
pub fn main() {}

View File

@ -18,4 +18,4 @@ impl HasNested {
}
}
fn main() {}
pub fn main() {}

View File

@ -10,7 +10,7 @@
use std::io;
fn main() {
pub fn main() {
let stdout = &io::stdout() as &io::WriterUtil;
stdout.write_line("Hello!");
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
pub fn main() {
let (port, chan) = stream();
do spawn {

View File

@ -21,7 +21,7 @@ impl Drop for NonCopyable {
}
}
fn main() {
pub fn main() {
let t = ~0;
let p = unsafe { transmute::<~int, *c_void>(t) };
let _z = NonCopyable(p);

View File

@ -37,7 +37,7 @@ fn print_name(x: &Debuggable)
println(fmt!("debug_name = %s", x.debug_name()));
}
fn main() {
pub fn main() {
let thing = Thing::new();
print_name(&thing as &Debuggable);
}

View File

@ -22,7 +22,7 @@ macro_rules! print_hd_tl (
})
)
fn main() {
pub fn main() {
print_hd_tl!(x, y, z, w)
}

View File

@ -39,6 +39,6 @@ impl Scheduler {
}
}
fn main() {
pub fn main() {
let _sched = Scheduler::new(~UvEventLoop::new() as ~EventLoop);
}

View File

@ -10,7 +10,7 @@
// Regression test for issue #5239
fn main() {
pub fn main() {
let _f: &fn(int) -> int = |ref x: int| { *x };
let foo = 10;
assert!(_f(foo) == 10);

View File

@ -20,6 +20,6 @@ impl FontTableTagConversions for FontTableTag {
}
}
fn main() {
pub fn main() {
5.tag_to_str();
}

View File

@ -10,7 +10,7 @@
struct A(bool);
fn main() {
pub fn main() {
let f = A;
f(true);
}

View File

@ -20,6 +20,6 @@ impl Fooable for uint {
}
}
fn main() {
pub fn main() {
2.yes();
}

View File

@ -21,4 +21,4 @@ fn gl_err_str(err: u32) -> ~str
}
}
fn main() {}
pub fn main() {}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
pub fn main() {
let box1 = @mut 42;
let _x = *(&mut *box1) == 42 || *(&mut *box1) == 31337;
}

View File

@ -10,7 +10,7 @@
#[allow(dead_assignment)];
fn main() {
pub fn main() {
let s: ~str = ~"foobar";
let mut t: &str = s;
t = t.slice(0, 3); // for master: str::view(t, 0, 3) maybe

View File

@ -1,3 +1,3 @@
fn foo<T: ::std::cmp::Eq>(_t: T) { }
fn main() { }
pub fn main() { }

View File

@ -19,7 +19,7 @@ failed to typecheck correctly.
struct X { vec: &'static [int] }
static V: &'static [X] = &[X { vec: &[1, 2, 3] }];
fn main() {
pub fn main() {
for &v in V.iter() {
println(fmt!("%?", v.vec));
}

View File

@ -39,7 +39,7 @@ impl<'self> Outer<'self> {
}
}
fn main() {
pub fn main() {
let inner = 5;
let outer = Outer::new(&inner as &Inner);
outer.inner.print();

View File

@ -12,7 +12,7 @@
use std::io;
fn main() {
pub fn main() {
return;
while io::stdin().read_line() != ~"quit" { };
}

View File

@ -10,6 +10,6 @@
struct T (&'static [int]);
static t : T = T (&'static [5, 4, 3]);
fn main () {
pub fn main () {
assert_eq!(t[0], 5);
}

View File

@ -21,7 +21,7 @@ impl<E> Graph<int, E> for HashMap<int, int> {
}
}
fn main() {
pub fn main() {
let g : ~HashMap<int, int> = ~HashMap::new();
let _g2 : ~Graph<int,int> = g as ~Graph<int,int>;
}

View File

@ -10,7 +10,7 @@
#[deny(type_limits)];
fn main() {
pub fn main() {
let i: uint = 0;
assert!(i <= 0xFFFF_FFFF_u);

View File

@ -2,7 +2,7 @@ fn run(f: &fn()) {
f()
}
fn main() {
pub fn main() {
let f: ~fn() = || ();
run(f);
}
}

View File

@ -13,7 +13,7 @@ fn swap(f: &fn(~[int]) -> ~[int]) -> ~[int] {
f(x)
}
fn main() {
pub fn main() {
let v = swap(|mut x| { x.push(4); x });
let w = do swap |mut x| { x.push(4); x };
assert_eq!(v, w);

View File

@ -15,4 +15,4 @@ impl Drop for A {
fn drop(&mut self) {}
}
fn main() {}
pub fn main() {}

View File

@ -13,7 +13,7 @@ impl Drop for A {
fn drop(&mut self) {}
}
fn main() {
pub fn main() {
let a = A { x: 0 };
let A { x: ref x } = a;

View File

@ -13,7 +13,7 @@ impl Drop for A {
fn drop(&mut self) {}
}
fn main() {
pub fn main() {
let a = A { x: 0 };
match a {

Some files were not shown because too many files have changed in this diff Show More