Skip to content

Remove named extern blocks from the AST #9804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/librustc/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ fn fold_foreign_mod(cx: &Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
}
}.collect();
ast::foreign_mod {
sort: nm.sort,
abis: nm.abis,
view_items: filtered_view_items,
items: filtered_items
Expand Down
63 changes: 33 additions & 30 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,40 +175,43 @@ fn visit_item(e: &Env, i: @ast::item) {
}

let cstore = e.cstore;
let mut already_added = false;
let link_args = i.attrs.iter()
.filter_map(|at| if "link_args" == at.name() {Some(at)} else {None})
.collect::<~[&ast::Attribute]>();

match fm.sort {
ast::named => {
let link_name = i.attrs.iter()
.find(|at| "link_name" == at.name())
.and_then(|at| at.value_str());

let foreign_name = match link_name {
Some(nn) => {
if nn.is_empty() {
e.diag.span_fatal(
i.span,
"empty #[link_name] not allowed; use \
#[nolink].");
}
nn
}
None => token::ident_to_str(&i.ident)
};
if !attr::contains_name(i.attrs, "nolink") {
already_added =
!cstore::add_used_library(cstore, foreign_name);
}
if !link_args.is_empty() && already_added {
e.diag.span_fatal(i.span, ~"library '" + foreign_name +
"' already added: can't specify link_args.");
}
}
ast::anonymous => { /* do nothing */ }
}
// XXX: two whom it may concern, this was the old logic applied to the
// ast's extern mod blocks which had names (we used to allow
// "extern mod foo"). This code was never run for anonymous blocks,
// and we now only have anonymous blocks. We're still in the midst
// of figuring out what the exact operations we'd like to support
// when linking external modules, but I wanted to leave this logic
// here for the time beging to refer back to it

//let mut already_added = false;
//let link_name = i.attrs.iter()
// .find(|at| "link_name" == at.name())
// .and_then(|at| at.value_str());

//let foreign_name = match link_name {
// Some(nn) => {
// if nn.is_empty() {
// e.diag.span_fatal(
// i.span,
// "empty #[link_name] not allowed; use \
// #[nolink].");
// }
// nn
// }
// None => token::ident_to_str(&i.ident)
// };
//if !attr::contains_name(i.attrs, "nolink") {
// already_added =
// !cstore::add_used_library(cstore, foreign_name);
//}
//if !link_args.is_empty() && already_added {
// e.diag.span_fatal(i.span, ~"library '" + foreign_name +
// "' already added: can't specify link_args.");
//}

for m in link_args.iter() {
match m.value_str() {
Expand Down
26 changes: 1 addition & 25 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,31 +1183,7 @@ impl Resolver {
ModuleReducedGraphParent(name_bindings.get_module())
}

item_foreign_mod(ref fm) => {
match fm.sort {
named => {
let (name_bindings, new_parent) =
self.add_child(ident, parent,
ForbidDuplicateModules, sp);

let parent_link = self.get_parent_link(new_parent,
ident);
let def_id = DefId { crate: 0, node: item.id };
name_bindings.define_module(parent_link,
Some(def_id),
ExternModuleKind,
false,
true,
sp);

ModuleReducedGraphParent(name_bindings.get_module())
}

// For anon foreign mods, the contents just go in the
// current scope
anonymous => parent
}
}
item_foreign_mod(*) => parent,

// These items live in the value namespace.
item_static(_, m, _) => {
Expand Down
8 changes: 0 additions & 8 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,16 +949,8 @@ pub struct _mod {
items: ~[@item],
}

// Foreign mods can be named or anonymous
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
pub enum foreign_mod_sort {
named,
anonymous,
}

#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
pub struct foreign_mod {
sort: foreign_mod_sort,
abis: AbiSet,
view_items: ~[view_item],
items: ~[@foreign_item],
Expand Down
8 changes: 1 addition & 7 deletions src/libsyntax/ast_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,11 @@ impl Visitor<()> for Ctx {
nm.abis,
visibility,
// FIXME (#2543)
if nm.sort ==
ast::named {
let e = path_name(
i.ident);
self.extend(e)
} else {
// Anonymous extern
// mods go in the
// parent scope.
@self.path.clone()
}));
));
}
}
item_struct(struct_def, _) => {
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ pub trait ast_fold {

fn fold_foreign_mod(&self, nm: &foreign_mod) -> foreign_mod {
ast::foreign_mod {
sort: nm.sort,
abis: nm.abis,
view_items: nm.view_items
.iter()
Expand Down
12 changes: 5 additions & 7 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4128,7 +4128,6 @@ impl Parser {
// at this point, this is essentially a wrapper for
// parse_foreign_items.
fn parse_foreign_mod_items(&self,
sort: ast::foreign_mod_sort,
abis: AbiSet,
first_item_attrs: ~[Attribute])
-> foreign_mod {
Expand All @@ -4144,7 +4143,6 @@ impl Parser {
}
assert!(*self.token == token::RBRACE);
ast::foreign_mod {
sort: sort,
abis: abis,
view_items: view_items,
items: foreign_items
Expand All @@ -4169,15 +4167,15 @@ impl Parser {
self.this_token_to_str()));
}

let (sort, maybe_path, ident) = match *self.token {
let (named, maybe_path, ident) = match *self.token {
token::IDENT(*) => {
let the_ident = self.parse_ident();
let path = if *self.token == token::EQ {
self.bump();
Some(self.parse_str())
}
else { None };
(ast::named, path, the_ident)
(true, path, the_ident)
}
_ => {
if must_be_named_mod {
Expand All @@ -4187,22 +4185,22 @@ impl Parser {
self.this_token_to_str()));
}

(ast::anonymous, None,
(false, None,
special_idents::clownshoes_foreign_mod)
}
};

// extern mod foo { ... } or extern { ... }
if items_allowed && self.eat(&token::LBRACE) {
// `extern mod foo { ... }` is obsolete.
if sort == ast::named {
if named {
self.obsolete(*self.last_span, ObsoleteNamedExternModule);
}

let abis = opt_abis.unwrap_or(AbiSet::C());

let (inner, next) = self.parse_inner_attrs_and_next();
let m = self.parse_foreign_mod_items(sort, abis, next);
let m = self.parse_foreign_mod_items(abis, next);
self.expect(&token::RBRACE);

return iovi_item(self.mk_item(lo,
Expand Down
8 changes: 0 additions & 8 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,6 @@ pub fn print_item(s: @ps, item: &ast::item) {
ast::item_foreign_mod(ref nmod) => {
head(s, "extern");
word_nbsp(s, nmod.abis.to_str());
match nmod.sort {
ast::named => {
word_nbsp(s, "mod");
print_ident(s, item.ident);
nbsp(s);
}
ast::anonymous => {}
}
bopen(s);
print_foreign_mod(s, nmod, item.attrs);
bclose(s, item.span);
Expand Down