From 49472ec4c9d6564f8ec22d689ccd61528d2dc553 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 30 Jan 2013 17:20:02 -0800 Subject: [PATCH] librustc: Remove legacy exports from the language. r=brson --- src/librustc/metadata/encoder.rs | 5 +- src/librustc/middle/privacy.rs | 17 +- src/librustc/middle/resolve.rs | 237 +++------------------- src/librustc/middle/trans/monomorphize.rs | 4 - src/librustc/middle/ty.rs | 2 +- src/librustc/middle/typeck/mod.rs | 1 - src/libsyntax/ast.rs | 1 - src/libsyntax/ast_map.rs | 24 --- src/libsyntax/ast_util.rs | 100 ++------- src/libsyntax/parse/parser.rs | 26 +-- src/libsyntax/parse/token.rs | 2 +- src/libsyntax/print/pprust.rs | 29 ++- src/test/auxiliary/issue-2526.rs | 6 +- src/test/auxiliary/issue2170lib.rs | 8 +- 14 files changed, 75 insertions(+), 387 deletions(-) diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 6e7e504eb46..ebedc341319 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -331,12 +331,11 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder, item_impl(*) | item_struct(*) => { let (ident, did) = (item.ident, item.id); debug!("(encoding info for module) ... encoding impl %s \ - (%?/%?), exported? %?", + (%?/%?)", ecx.tcx.sess.str_of(ident), did, ast_map::node_id_to_str(ecx.tcx.items, did, ecx.tcx - .sess.parse_sess.interner), - ast_util::is_exported(ident, md)); + .sess.parse_sess.interner)); ebml_w.start_tag(tag_mod_impl); ebml_w.wr_str(def_to_str(local_def(did))); diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 1c92526d3d3..eb90acb2d36 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -29,8 +29,8 @@ use syntax::ast::{provided, required}; use syntax::ast; use syntax::ast_map::{node_item, node_method}; use syntax::ast_map; -use syntax::ast_util::{Private, Public, has_legacy_export_attr, is_local}; -use syntax::ast_util::{visibility_to_privacy}; +use syntax::ast_util::{Private, Public, is_local}; +use syntax::ast_util::{variant_visibility_to_privacy, visibility_to_privacy}; use syntax::codemap::span; use syntax::visit; @@ -38,7 +38,6 @@ pub fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) { let privileged_items = @DVec(); - let legacy_exports = has_legacy_export_attr(crate.node.attrs); // Adds structs that are privileged to this scope. let add_privileged_items: @fn(&[@ast::item]) -> uint = |items| { @@ -65,20 +64,20 @@ pub fn check_crate(tcx: ty::ctxt, |it| { it.vis }, ~"unbound enum parent when checking \ dereference of enum type"); - visibility_to_privacy(parent_vis, legacy_exports) + visibility_to_privacy(parent_vis) } else { // WRONG Public }; debug!("parental_privacy = %?", parental_privacy); - debug!("vis = %?, priv = %?, legacy_exports = %?", + debug!("vis = %?, priv = %?", variant_info.vis, - visibility_to_privacy(variant_info.vis, legacy_exports), - legacy_exports); + visibility_to_privacy(variant_info.vis)) // inherited => privacy of the enum item - if visibility_to_privacy(variant_info.vis, - parental_privacy == Public) == Private { + if variant_visibility_to_privacy(variant_info.vis, + parental_privacy == Public) + == Private { tcx.sess.span_err(span, ~"can only dereference enums \ with a single, public variant"); diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 68ba50bfac5..3c1b7b3c1f9 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -54,14 +54,14 @@ use syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i}; use syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, ty_param, ty_path}; use syntax::ast::{ty_str, ty_u, ty_u16, ty_u32, ty_u64, ty_u8, ty_uint}; use syntax::ast::{type_value_ns, ty_param_bound, unnamed_field}; -use syntax::ast::{variant, view_item, view_item_export, view_item_import}; +use syntax::ast::{variant, view_item, view_item_import}; use syntax::ast::{view_item_use, view_path_glob, view_path_list}; use syntax::ast::{view_path_simple, visibility, anonymous, named, not}; use syntax::ast::{unsafe_fn}; use syntax::ast_util::{def_id_of_def, dummy_sp, local_def}; use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method}; -use syntax::ast_util::{Privacy, Public, Private, visibility_to_privacy}; -use syntax::ast_util::has_legacy_export_attr; +use syntax::ast_util::{Privacy, Public, Private}; +use syntax::ast_util::{variant_visibility_to_privacy, visibility_to_privacy}; use syntax::attr::{attr_metas, contains_name, attrs_contains_name}; use syntax::parse::token::ident_interner; use syntax::parse::token::special_idents; @@ -469,13 +469,6 @@ pub struct Module { exported_names: HashMap, - // XXX: This is a transition measure to let us switch export-evaluation - // logic when compiling modules that have transitioned to listing their - // pub/priv qualifications on items, explicitly, rather than using the - // old export rule. - - legacy_exports: bool, - // The status of resolving each import in this module. import_resolutions: HashMap, @@ -488,8 +481,7 @@ pub struct Module { pub fn Module(parent_link: ParentLink, def_id: Option, - kind: ModuleKind, - legacy_exports: bool) + kind: ModuleKind) -> Module { Module { parent_link: parent_link, @@ -499,7 +491,6 @@ pub fn Module(parent_link: ParentLink, imports: DVec(), anonymous_children: HashMap(), exported_names: HashMap(), - legacy_exports: legacy_exports, import_resolutions: HashMap(), glob_count: 0, resolved_import_count: 0 @@ -553,10 +544,9 @@ pub impl NameBindings { parent_link: ParentLink, def_id: Option, kind: ModuleKind, - legacy_exports: bool, sp: span) { // Merges the module with the existing type def or creates a new one. - let module_ = @Module(parent_link, def_id, kind, legacy_exports); + let module_ = @Module(parent_link, def_id, kind); match self.type_def { None => { self.type_def = Some(TypeNsDef { @@ -760,7 +750,6 @@ pub fn Resolver(session: Session, NoParentLink, Some(def_id { crate: 0, node: 0 }), NormalModuleKind, - has_legacy_export_attr(crate.node.attrs), crate.span); let current_module = (*graph_root).get_module(); @@ -1076,14 +1065,10 @@ pub impl Resolver { &&visitor: vt) { let ident = item.ident; let sp = item.span; - let legacy = match parent { - ModuleReducedGraphParent(m) => m.legacy_exports - }; - let privacy = visibility_to_privacy(item.vis, legacy); + let privacy = visibility_to_privacy(item.vis); match /*bad*/copy item.node { item_mod(module_) => { - let legacy = has_legacy_export_attr(item.attrs); let (name_bindings, new_parent) = self.add_child(ident, parent, ForbidDuplicateModules, sp); @@ -1093,7 +1078,6 @@ pub impl Resolver { parent_link, Some(def_id), NormalModuleKind, - legacy, sp); let new_parent = @@ -1103,7 +1087,6 @@ pub impl Resolver { } item_foreign_mod(fm) => { - let legacy = has_legacy_export_attr(item.attrs); let new_parent = match fm.sort { named => { let (name_bindings, new_parent) = @@ -1117,7 +1100,6 @@ pub impl Resolver { parent_link, Some(def_id), ExternModuleKind, - legacy, sp); ModuleReducedGraphParent(name_bindings.get_module()) @@ -1168,9 +1150,10 @@ pub impl Resolver { self.build_reduced_graph_for_variant(*variant, local_def(item.id), // inherited => privacy of the enum item - visibility_to_privacy(variant.node.vis, - privacy == Public), - new_parent, visitor); + variant_visibility_to_privacy(variant.node.vis, + privacy == Public), + new_parent, + visitor); } } @@ -1238,7 +1221,6 @@ pub impl Resolver { parent_link, Some(def_id), TraitModuleKind, - false, sp); let new_parent = ModuleReducedGraphParent( @@ -1301,7 +1283,6 @@ pub impl Resolver { parent_link, Some(local_def(item.id)), TraitModuleKind, - false, sp); module_parent_opt = Some(ModuleReducedGraphParent( name_bindings.get_module())); @@ -1408,11 +1389,7 @@ pub impl Resolver { fn build_reduced_graph_for_view_item(view_item: @view_item, parent: ReducedGraphParent, &&_visitor: vt) { - - let legacy = match parent { - ModuleReducedGraphParent(m) => m.legacy_exports - }; - let privacy = visibility_to_privacy(view_item.vis, legacy); + let privacy = visibility_to_privacy(view_item.vis); match /*bad*/copy view_item.node { view_item_import(view_paths) => { for view_paths.each |view_path| { @@ -1484,64 +1461,6 @@ pub impl Resolver { } } - view_item_export(view_paths) => { - let module_ = self.get_module_from_parent(parent); - for view_paths.each |view_path| { - match view_path.node { - view_path_simple(ident, full_path, _, ident_id) => { - let last_ident = full_path.idents.last(); - if last_ident != ident { - self.session.span_err(view_item.span, - ~"cannot export under \ - a new name"); - } - if full_path.idents.len() != 1u { - self.session.span_err( - view_item.span, - ~"cannot export an item \ - that is not in this \ - module"); - } - - module_.exported_names.insert(ident, ident_id); - } - - view_path_glob(*) => { - self.session.span_err(view_item.span, - ~"export globs are \ - unsupported"); - } - - view_path_list(path, ref path_list_idents, _) => { - if path.idents.len() == 1u && - (*path_list_idents).len() == 0 { - - self.session.span_warn(view_item.span, - ~"this syntax for \ - exporting no \ - variants is \ - unsupported; export \ - variants \ - individually"); - } else { - if path.idents.len() != 0 { - self.session.span_err(view_item.span, - ~"cannot export an \ - item that is not \ - in this module"); - } - - for path_list_idents.each |path_list_ident| { - let ident = path_list_ident.node.name; - let id = path_list_ident.node.id; - module_.exported_names.insert(ident, id); - } - } - } - } - } - } - view_item_use(name, _, node_id) => { match find_use_stmt_cnum(self.session.cstore, node_id) { Some(crate_id) => { @@ -1553,12 +1472,11 @@ pub impl Resolver { let parent_link = ModuleParentLink (self.get_module_from_parent(new_parent), name); - (*child_name_bindings).define_module(privacy, - parent_link, - Some(def_id), - NormalModuleKind, - false, - view_item.span); + child_name_bindings.define_module(privacy, + parent_link, + Some(def_id), + NormalModuleKind, + view_item.span); self.build_reduced_graph_for_external_crate ((*child_name_bindings).get_module()); } @@ -1616,8 +1534,7 @@ pub impl Resolver { let parent_module = self.get_module_from_parent(parent); let new_module = @Module(BlockParentLink(parent_module, block_id), None, - AnonymousModuleKind, - false); + AnonymousModuleKind); parent_module.anonymous_children.insert(block_id, new_module); new_parent = ModuleReducedGraphParent(new_module); } else { @@ -1652,7 +1569,6 @@ pub impl Resolver { parent_link, Some(def_id), NormalModuleKind, - false, dummy_sp()); modules.insert(def_id, child_name_bindings.get_module()); @@ -1779,12 +1695,11 @@ pub impl Resolver { *ident_str); let parent_link = self.get_parent_link(new_parent, ident); - (*child_name_bindings).define_module(Public, - parent_link, - None, - NormalModuleKind, - false, - dummy_sp()); + child_name_bindings.define_module(Public, + parent_link, + None, + NormalModuleKind, + dummy_sp()); } Some(copy type_ns_def) if type_ns_def.module_def.is_none() => { @@ -1793,12 +1708,11 @@ pub impl Resolver { *ident_str); let parent_link = self.get_parent_link(new_parent, ident); - (*child_name_bindings).define_module(Public, - parent_link, - None, - NormalModuleKind, - false, - dummy_sp()); + child_name_bindings.define_module(Public, + parent_link, + None, + NormalModuleKind, + dummy_sp()); } _ => {} // Fall through. } @@ -1865,7 +1779,6 @@ pub impl Resolver { parent_link, Some(def), NormalModuleKind, - false, dummy_sp()); type_module = child_name_bindings. @@ -2110,7 +2023,6 @@ pub impl Resolver { // First, resolve the module path for the directive, if necessary. match self.resolve_module_path_for_import(module_, module_path, - NoXray, DontUseLexicalScope, import_directive.span) { @@ -2196,12 +2108,6 @@ pub impl Resolver { self.session.str_of(source), self.module_to_str(module_)); - if !self.name_is_exported(containing_module, source) { - debug!("(resolving single import) name `%s` is unexported", - self.session.str_of(source)); - return Failed; - } - // We need to resolve both namespaces for this to succeed. // // XXX: See if there's some way of handling namespaces in a more @@ -2392,12 +2298,6 @@ pub impl Resolver { self.session.str_of(source), self.module_to_str(module_)); - if !self.name_is_exported(containing_module, source) { - debug!("(resolving single import) name `%s` is unexported", - self.session.str_of(source)); - return Failed; - } - // We need to resolve the module namespace for this to succeed. let mut module_result = UnknownResult; @@ -2538,12 +2438,6 @@ pub impl Resolver { for containing_module.import_resolutions.each |ident, target_import_resolution| { - if !self.name_is_exported(containing_module, ident) { - debug!("(resolving glob import) name `%s` is unexported", - self.session.str_of(ident)); - loop; - } - debug!("(resolving glob import) writing module resolution \ %? into `%s`", is_none(&target_import_resolution.type_target), @@ -2592,12 +2486,6 @@ pub impl Resolver { // Add all children from the containing module. for containing_module.children.each |ident, name_bindings| { - if !self.name_is_exported(containing_module, ident) { - debug!("(resolving glob import) name `%s` is unexported", - self.session.str_of(ident)); - loop; - } - let mut dest_import_resolution; match module_.import_resolutions.find(ident) { None => { @@ -2639,7 +2527,6 @@ pub impl Resolver { fn resolve_module_path_from_root(module_: @Module, module_path: @DVec, index: uint, - xray: XrayFlag, span: span) -> ResolveResult<@Module> { let mut search_module = module_; @@ -2655,7 +2542,6 @@ pub impl Resolver { match self.resolve_name_in_module(search_module, name, TypeNS, - xray, false) { Failed => { self.session.span_err(span, ~"unresolved name"); @@ -2712,7 +2598,6 @@ pub impl Resolver { */ fn resolve_module_path_for_import(module_: @Module, module_path: @DVec, - xray: XrayFlag, use_lexical_scope: UseLexicalScopeFlag, span: span) -> ResolveResult<@Module> { @@ -2787,7 +2672,6 @@ pub impl Resolver { return self.resolve_module_path_from_root(search_module, module_path, start_index, - xray, span); } @@ -2884,7 +2768,6 @@ pub impl Resolver { match self.resolve_name_in_module(search_module, name, namespace, - Xray, false) { Failed => { // Continue up the search chain. @@ -3030,12 +2913,6 @@ pub impl Resolver { return Success(PrefixFound(containing_module, i)); } - fn name_is_exported(module_: @Module, name: ident) -> bool { - return !module_.legacy_exports || - module_.exported_names.size() == 0 || - module_.exported_names.contains_key(name); - } - /** * Attempts to resolve the supplied name in the given module for the * given namespace. If successful, returns the target corresponding to @@ -3044,19 +2921,12 @@ pub impl Resolver { fn resolve_name_in_module(module_: @Module, name: ident, namespace: Namespace, - xray: XrayFlag, allow_globs: bool) -> ResolveResult { debug!("(resolving name in module) resolving `%s` in `%s`", self.session.str_of(name), self.module_to_str(module_)); - if xray == NoXray && !self.name_is_exported(module_, name) { - debug!("(resolving name in module) name `%s` is unexported", - self.session.str_of(name)); - return Failed; - } - // First, check the direct children of the module. match module_.children.find(name) { Some(name_bindings) @@ -3358,11 +3228,7 @@ pub impl Resolver { fn record_exports_for_module(module_: @Module) { let mut exports2 = ~[]; - if module_.legacy_exports { - self.add_exports_for_legacy_module(&mut exports2, module_); - } else { - self.add_exports_for_module(&mut exports2, module_); - } + self.add_exports_for_module(&mut exports2, module_); match copy module_.def_id { Some(def_id) => { self.export_map2.insert(def_id.node, move exports2); @@ -3440,44 +3306,6 @@ pub impl Resolver { } } - fn add_exports_for_legacy_module(exports2: &mut ~[Export2], - module_: @Module) { - for module_.exported_names.each |name, _exp_node_id| { - for self.namespaces.each |namespace| { - match self.resolve_definition_of_name_in_module(module_, - name, - *namespace, - Xray) { - NoNameDefinition => { - // Nothing to do. - } - ChildNameDefinition(target_def) => { - debug!("(computing exports) legacy export '%s' \ - for %?", - self.session.str_of(name), - module_.def_id); - exports2.push(Export2 { - reexport: false, - name: self.session.str_of(name), - def_id: def_id_of_def(target_def) - }); - } - ImportNameDefinition(target_def) => { - debug!("(computing exports) legacy reexport '%s' for \ - %?", - self.session.str_of(name), - module_.def_id); - exports2.push(Export2 { - reexport: true, - name: self.session.str_of(name), - def_id: def_id_of_def(target_def) - }); - } - } - } - } - } - // AST resolution // // We maintain a list of value ribs and type ribs. @@ -4730,13 +4558,6 @@ pub impl Resolver { xray: XrayFlag) -> NameDefinition { - if xray == NoXray && !self.name_is_exported(containing_module, name) { - debug!("(resolving definition of name in module) name `%s` is \ - unexported", - self.session.str_of(name)); - return NoNameDefinition; - } - // First, search children. match containing_module.children.find(name) { Some(child_name_bindings) => { @@ -4816,7 +4637,6 @@ pub impl Resolver { let mut containing_module; match self.resolve_module_path_for_import(self.current_module, module_path_idents, - xray, UseLexicalScope, path.span) { Failed => { @@ -4864,7 +4684,6 @@ pub impl Resolver { match self.resolve_module_path_from_root(root_module, module_path_idents, 0, - xray, path.span) { Failed => { diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index d7deb2a4da7..60b4057d448 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -111,9 +111,6 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, ast_map::node_stmt(*) => { ccx.tcx.sess.bug(~"Can't monomorphize a stmt") } - ast_map::node_export(*) => { - ccx.tcx.sess.bug(~"Can't monomorphize an export") - } ast_map::node_arg(*) => ccx.tcx.sess.bug(~"Can't monomorphize an arg"), ast_map::node_block(*) => { ccx.tcx.sess.bug(~"Can't monomorphize a block") @@ -255,7 +252,6 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, ast_map::node_expr(*) | ast_map::node_stmt(*) | ast_map::node_trait_method(*) | - ast_map::node_export(*) | ast_map::node_arg(*) | ast_map::node_block(*) | ast_map::node_local(*) => { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 2b350706afb..2dd70f2f57d 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3756,7 +3756,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path { ast_map::node_stmt(*) | ast_map::node_expr(*) | ast_map::node_arg(*) | ast_map::node_local(*) | - ast_map::node_export(*) | ast_map::node_block(*) => { + ast_map::node_block(*) => { cx.sess.bug(fmt!("cannot find item_path for node %?", node)); } } diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index bc84b957865..ae57cd90bd7 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -72,7 +72,6 @@ use std::map; use std::smallintmap; use syntax::ast::{provided, required, spanned}; use syntax::ast_map::node_id_to_str; -use syntax::ast_util::{has_legacy_export_attr}; use syntax::ast_util::{local_def, respan, split_trait_methods}; use syntax::codemap::span; use syntax::print::pprust::*; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 8736074a5c4..0b250c2e421 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1504,7 +1504,6 @@ pub struct view_item { pub enum view_item_ { view_item_use(ident, ~[@meta_item], node_id), view_item_import(~[@view_path]), - view_item_export(~[@view_path]) } // Meta-data associated with an item diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 773e3754e26..a96829ed063 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -96,7 +96,6 @@ pub enum ast_node { node_variant(variant, @item, @path), node_expr(@expr), node_stmt(@stmt), - node_export(@view_path, @path), // Locals are numbered, because the alias analysis needs to know in which // order they are introduced. node_arg(arg, uint), @@ -128,7 +127,6 @@ pub fn mk_ast_map_visitor() -> vt { visit_fn: map_fn, visit_local: map_local, visit_arm: map_arm, - visit_view_item: map_view_item, visit_block: map_block, .. *visit::default_visitor() }); @@ -324,23 +322,6 @@ pub fn map_struct_def(struct_def: @ast::struct_def, parent_node: ast_node, } } -pub fn map_view_item(vi: @view_item, cx: ctx, _v: vt) { - match vi.node { - view_item_export(vps) => for vps.each |vp| { - let (id, name) = match vp.node { - view_path_simple(nm, _, _, id) => { - (id, /* FIXME (#2543) */ copy nm) - } - view_path_glob(pth, id) | view_path_list(pth, _, id) => { - (id, path_to_ident(pth)) - } - }; - cx.map.insert(id, node_export(*vp, extend(cx, name))); - }, - _ => () - } -} - pub fn map_expr(ex: @expr, cx: ctx, v: vt) { cx.map.insert(ex.id, node_expr(ex)); visit::visit_expr(ex, cx, v); @@ -396,11 +377,6 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { fmt!("stmt %s (id=%?)", pprust::stmt_to_str(*stmt, itr), id) } - // FIXMEs are as per #2410 - Some(node_export(_, path)) => { - fmt!("export %s (id=%?)", // add more info here - path_to_str(*path, itr), id) - } Some(node_arg(_, _)) => { // add more info here fmt!("arg (id=%?)", id) } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index ac0a54c582c..7b742019f0e 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -215,64 +215,6 @@ pub pure fn float_ty_to_str(t: float_ty) -> ~str { match t { ty_f => ~"f", ty_f32 => ~"f32", ty_f64 => ~"f64" } } -pub fn is_exported(i: ident, m: _mod) -> bool { - let mut local = false; - let mut parent_enum : Option = None; - for m.items.each |it| { - if it.ident == i { local = true; } - match it.node { - item_enum(ref enum_definition, _) => - for (*enum_definition).variants.each |v| { - if v.node.name == i { - local = true; - parent_enum = Some(/* FIXME (#2543) */ copy it.ident); - } - }, - _ => () - } - if local { break; } - } - let mut has_explicit_exports = false; - for m.view_items.each |vi| { - match vi.node { - view_item_export(vps) => { - has_explicit_exports = true; - for vps.each |vp| { - match vp.node { - ast::view_path_simple(id, _, _, _) => { - if id == i { return true; } - match parent_enum { - Some(parent_enum_id) => { - if id == parent_enum_id { return true; } - } - _ => () - } - } - - ast::view_path_list(path, ref ids, _) => { - if vec::len(path.idents) == 1u { - if i == path.idents[0] { return true; } - for (*ids).each |id| { - if id.node.name == i { return true; } - } - } else { - fail ~"export of path-qualified list"; - } - } - - _ => () - } - } - } - _ => () - } - } - // If there are no declared exports then - // everything not imported is exported - // even if it's local (since it's explicit) - return !has_explicit_exports && local; -} - pub pure fn is_call_expr(e: @expr) -> bool { match e.node { expr_call(_, _, _) => true, _ => false } } @@ -476,7 +418,7 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { visit_view_item: fn@(vi: @view_item) { match vi.node { view_item_use(_, _, id) => vfn(id), - view_item_import(vps) | view_item_export(vps) => { + view_item_import(vps) => { for vec::each(vps) |vp| { match vp.node { view_path_simple(_, _, _, id) => vfn(id), @@ -662,46 +604,32 @@ pub fn struct_def_is_tuple_like(struct_def: @ast::struct_def) -> bool { struct_def.ctor_id.is_some() } +pub fn visibility_to_privacy(visibility: visibility) -> Privacy { + match visibility { + public => Public, + inherited | private => Private + } +} -pub fn visibility_to_privacy(visibility: visibility, - legacy_exports: bool) -> Privacy { - if legacy_exports { +pub fn variant_visibility_to_privacy(visibility: visibility, + enclosing_is_public: bool) + -> Privacy { + if enclosing_is_public { match visibility { - inherited | public => Public, + public | inherited => Public, private => Private } } else { - match visibility { - public => Public, - inherited | private => Private - } + visibility_to_privacy(visibility) } } +#[deriving_eq] pub enum Privacy { Private, Public } -pub impl Privacy : cmp::Eq { - pure fn eq(&self, other: &Privacy) -> bool { - ((*self) as uint) == ((*other) as uint) - } - pure fn ne(&self, other: &Privacy) -> bool { !(*self).eq(other) } -} - -pub fn has_legacy_export_attr(attrs: &[attribute]) -> bool { - for attrs.each |attribute| { - match attribute.node.value.node { - meta_word(ref w) if (*w) == ~"legacy_exports" => { - return true; - } - _ => {} - } - } - return false; -} - // Local Variables: // mode: rust // fill-column: 78; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 25fd13a5999..d41fedebde3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -50,7 +50,7 @@ use ast::{ty_field, ty_fixed_length_vec, ty_fn, ty_infer, ty_mac, ty_method}; use ast::{ty_nil, ty_param, ty_param_bound, ty_path, ty_ptr, ty_rec, ty_rptr}; use ast::{ty_tup, ty_u32, ty_uniq, ty_vec, type_value_ns, uniq}; use ast::{unnamed_field, unsafe_blk, unsafe_fn, variant, view_item}; -use ast::{view_item_, view_item_export, view_item_import, view_item_use}; +use ast::{view_item_, view_item_import, view_item_use}; use ast::{view_path, view_path_glob, view_path_list, view_path_simple}; use ast::{visibility, vstore, vstore_box, vstore_fixed, vstore_slice}; use ast::{vstore_uniq}; @@ -88,6 +88,7 @@ use core::vec::push; use core::vec; use std::map::HashMap; +#[deriving_eq] enum restriction { UNRESTRICTED, RESTRICT_STMT_EXPR, @@ -3735,15 +3736,6 @@ pub impl Parser { vis: visibility, span: mk_sp(lo, self.last_span.hi) }); - } else if self.eat_keyword(~"export") { - let view_paths = self.parse_view_paths(); - self.expect(token::SEMI); - return iovi_view_item(@ast::view_item { - node: view_item_export(view_paths), - attrs: attrs, - vis: visibility, - span: mk_sp(lo, self.last_span.hi) - }); } else if macros_allowed && !self.is_any_keyword(copy self.token) && self.look_ahead(1) == token::NOT && (is_plain_ident(self.look_ahead(2)) @@ -3916,7 +3908,6 @@ pub impl Parser { next_tok = self.look_ahead(2); }; self.token_is_keyword(~"use", tok) - || self.token_is_keyword(~"export", tok) || (self.token_is_keyword(~"extern", tok) && self.token_is_keyword(~"mod", next_tok)) } @@ -3925,8 +3916,6 @@ pub impl Parser { let lo = self.span.lo; let node = if self.eat_keyword(~"use") { self.parse_use() - } else if self.eat_keyword(~"export") { - view_item_export(self.parse_view_paths()) } else if self.eat_keyword(~"extern") { self.expect_keyword(~"mod"); let ident = self.parse_ident(); @@ -3979,8 +3968,8 @@ pub impl Parser { if restricted_to_imports { match view_item.node { view_item_import(_) => {} - view_item_export(_) | view_item_use(*) => - self.fatal(~"exports and \"extern mod\" \ + view_item_use(*) => + self.fatal(~"\"extern mod\" \ declarations are not \ allowed here") } @@ -4025,13 +4014,6 @@ pub impl Parser { } } -impl restriction : cmp::Eq { - pure fn eq(&self, other: &restriction) -> bool { - ((*self) as uint) == ((*other) as uint) - } - pure fn ne(&self, other: &restriction) -> bool { !(*self).eq(other) } -} - // // Local Variables: // mode: rust diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 30d2489a5ee..2093b5caebd 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -486,7 +486,7 @@ pub fn strict_keyword_table() -> HashMap<~str, ()> { ~"break", ~"const", ~"copy", ~"do", ~"drop", - ~"else", ~"enum", ~"export", ~"extern", + ~"else", ~"enum", ~"extern", ~"fail", ~"false", ~"fn", ~"for", ~"if", ~"impl", ~"let", ~"log", ~"loop", diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index a0243215e69..7f03158a4df 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1865,25 +1865,20 @@ pub fn print_view_item(s: ps, item: @ast::view_item) { print_outer_attributes(s, item.attrs); print_visibility(s, item.vis); match item.node { - ast::view_item_use(id, mta, _) => { - head(s, ~"extern mod"); - print_ident(s, id); - if !mta.is_empty() { - popen(s); - commasep(s, consistent, mta, print_meta_item); - pclose(s); + ast::view_item_use(id, mta, _) => { + head(s, ~"extern mod"); + print_ident(s, id); + if !mta.is_empty() { + popen(s); + commasep(s, consistent, mta, print_meta_item); + pclose(s); + } } - } - ast::view_item_import(vps) => { - head(s, ~"use"); - print_view_paths(s, vps); - } - - ast::view_item_export(vps) => { - head(s, ~"export"); - print_view_paths(s, vps); - } + ast::view_item_import(vps) => { + head(s, ~"use"); + print_view_paths(s, vps); + } } word(s.s, ~";"); end(s); // end inner head-block diff --git a/src/test/auxiliary/issue-2526.rs b/src/test/auxiliary/issue-2526.rs index fc5cf127518..4e07de771e5 100644 --- a/src/test/auxiliary/issue-2526.rs +++ b/src/test/auxiliary/issue-2526.rs @@ -15,8 +15,6 @@ extern mod std; -export context; - struct arc_destruct { _data: int, } @@ -55,8 +53,8 @@ fn context_res() -> context_res { } } -type context = arc_destruct; +pub type context = arc_destruct; -impl context { +pub impl context { fn socket() { } } diff --git a/src/test/auxiliary/issue2170lib.rs b/src/test/auxiliary/issue2170lib.rs index 7a676b0b5a6..bf5a6643204 100644 --- a/src/test/auxiliary/issue2170lib.rs +++ b/src/test/auxiliary/issue2170lib.rs @@ -8,22 +8,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -export rsrc; - fn foo(_x: i32) { } -struct rsrc { +pub struct rsrc { x: i32, } -impl rsrc : Drop { +pub impl rsrc : Drop { fn finalize(&self) { foo(self.x); } } -fn rsrc(x: i32) -> rsrc { +pub fn rsrc(x: i32) -> rsrc { rsrc { x: x }