Skip to content

Commit e5fc0ca

Browse files
committed
auto merge of #9804 : alexcrichton/rust/always-anon-extern, r=brson
There's currently a fair amount of code which is being ignored on unnamed blocks (which are the default now), and I opted to leave it commented out for now. I intend on very soon revisiting on how we perform linking with extern crates in an effort to support static linking.
2 parents 0daced6 + b703061 commit e5fc0ca

File tree

8 files changed

+40
-87
lines changed

8 files changed

+40
-87
lines changed

src/librustc/front/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ fn fold_foreign_mod(cx: &Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
102102
}
103103
}.collect();
104104
ast::foreign_mod {
105-
sort: nm.sort,
106105
abis: nm.abis,
107106
view_items: filtered_view_items,
108107
items: filtered_items

src/librustc/metadata/creader.rs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -175,40 +175,43 @@ fn visit_item(e: &Env, i: @ast::item) {
175175
}
176176

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

183-
match fm.sort {
184-
ast::named => {
185-
let link_name = i.attrs.iter()
186-
.find(|at| "link_name" == at.name())
187-
.and_then(|at| at.value_str());
188-
189-
let foreign_name = match link_name {
190-
Some(nn) => {
191-
if nn.is_empty() {
192-
e.diag.span_fatal(
193-
i.span,
194-
"empty #[link_name] not allowed; use \
195-
#[nolink].");
196-
}
197-
nn
198-
}
199-
None => token::ident_to_str(&i.ident)
200-
};
201-
if !attr::contains_name(i.attrs, "nolink") {
202-
already_added =
203-
!cstore::add_used_library(cstore, foreign_name);
204-
}
205-
if !link_args.is_empty() && already_added {
206-
e.diag.span_fatal(i.span, ~"library '" + foreign_name +
207-
"' already added: can't specify link_args.");
208-
}
209-
}
210-
ast::anonymous => { /* do nothing */ }
211-
}
182+
// XXX: two whom it may concern, this was the old logic applied to the
183+
// ast's extern mod blocks which had names (we used to allow
184+
// "extern mod foo"). This code was never run for anonymous blocks,
185+
// and we now only have anonymous blocks. We're still in the midst
186+
// of figuring out what the exact operations we'd like to support
187+
// when linking external modules, but I wanted to leave this logic
188+
// here for the time beging to refer back to it
189+
190+
//let mut already_added = false;
191+
//let link_name = i.attrs.iter()
192+
// .find(|at| "link_name" == at.name())
193+
// .and_then(|at| at.value_str());
194+
195+
//let foreign_name = match link_name {
196+
// Some(nn) => {
197+
// if nn.is_empty() {
198+
// e.diag.span_fatal(
199+
// i.span,
200+
// "empty #[link_name] not allowed; use \
201+
// #[nolink].");
202+
// }
203+
// nn
204+
// }
205+
// None => token::ident_to_str(&i.ident)
206+
// };
207+
//if !attr::contains_name(i.attrs, "nolink") {
208+
// already_added =
209+
// !cstore::add_used_library(cstore, foreign_name);
210+
//}
211+
//if !link_args.is_empty() && already_added {
212+
// e.diag.span_fatal(i.span, ~"library '" + foreign_name +
213+
// "' already added: can't specify link_args.");
214+
//}
212215

213216
for m in link_args.iter() {
214217
match m.value_str() {

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,31 +1183,7 @@ impl Resolver {
11831183
ModuleReducedGraphParent(name_bindings.get_module())
11841184
}
11851185

1186-
item_foreign_mod(ref fm) => {
1187-
match fm.sort {
1188-
named => {
1189-
let (name_bindings, new_parent) =
1190-
self.add_child(ident, parent,
1191-
ForbidDuplicateModules, sp);
1192-
1193-
let parent_link = self.get_parent_link(new_parent,
1194-
ident);
1195-
let def_id = DefId { crate: 0, node: item.id };
1196-
name_bindings.define_module(parent_link,
1197-
Some(def_id),
1198-
ExternModuleKind,
1199-
false,
1200-
true,
1201-
sp);
1202-
1203-
ModuleReducedGraphParent(name_bindings.get_module())
1204-
}
1205-
1206-
// For anon foreign mods, the contents just go in the
1207-
// current scope
1208-
anonymous => parent
1209-
}
1210-
}
1186+
item_foreign_mod(*) => parent,
12111187

12121188
// These items live in the value namespace.
12131189
item_static(_, m, _) => {

src/libsyntax/ast.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -949,16 +949,8 @@ pub struct _mod {
949949
items: ~[@item],
950950
}
951951
952-
// Foreign mods can be named or anonymous
953-
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
954-
pub enum foreign_mod_sort {
955-
named,
956-
anonymous,
957-
}
958-
959952
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
960953
pub struct foreign_mod {
961-
sort: foreign_mod_sort,
962954
abis: AbiSet,
963955
view_items: ~[view_item],
964956
items: ~[@foreign_item],

src/libsyntax/ast_map.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,11 @@ impl Visitor<()> for Ctx {
294294
nm.abis,
295295
visibility,
296296
// FIXME (#2543)
297-
if nm.sort ==
298-
ast::named {
299-
let e = path_name(
300-
i.ident);
301-
self.extend(e)
302-
} else {
303297
// Anonymous extern
304298
// mods go in the
305299
// parent scope.
306300
@self.path.clone()
307-
}));
301+
));
308302
}
309303
}
310304
item_struct(struct_def, _) => {

src/libsyntax/fold.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ pub trait ast_fold {
289289

290290
fn fold_foreign_mod(&self, nm: &foreign_mod) -> foreign_mod {
291291
ast::foreign_mod {
292-
sort: nm.sort,
293292
abis: nm.abis,
294293
view_items: nm.view_items
295294
.iter()

src/libsyntax/parse/parser.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4128,7 +4128,6 @@ impl Parser {
41284128
// at this point, this is essentially a wrapper for
41294129
// parse_foreign_items.
41304130
fn parse_foreign_mod_items(&self,
4131-
sort: ast::foreign_mod_sort,
41324131
abis: AbiSet,
41334132
first_item_attrs: ~[Attribute])
41344133
-> foreign_mod {
@@ -4144,7 +4143,6 @@ impl Parser {
41444143
}
41454144
assert!(*self.token == token::RBRACE);
41464145
ast::foreign_mod {
4147-
sort: sort,
41484146
abis: abis,
41494147
view_items: view_items,
41504148
items: foreign_items
@@ -4169,15 +4167,15 @@ impl Parser {
41694167
self.this_token_to_str()));
41704168
}
41714169

4172-
let (sort, maybe_path, ident) = match *self.token {
4170+
let (named, maybe_path, ident) = match *self.token {
41734171
token::IDENT(*) => {
41744172
let the_ident = self.parse_ident();
41754173
let path = if *self.token == token::EQ {
41764174
self.bump();
41774175
Some(self.parse_str())
41784176
}
41794177
else { None };
4180-
(ast::named, path, the_ident)
4178+
(true, path, the_ident)
41814179
}
41824180
_ => {
41834181
if must_be_named_mod {
@@ -4187,22 +4185,22 @@ impl Parser {
41874185
self.this_token_to_str()));
41884186
}
41894187

4190-
(ast::anonymous, None,
4188+
(false, None,
41914189
special_idents::clownshoes_foreign_mod)
41924190
}
41934191
};
41944192

41954193
// extern mod foo { ... } or extern { ... }
41964194
if items_allowed && self.eat(&token::LBRACE) {
41974195
// `extern mod foo { ... }` is obsolete.
4198-
if sort == ast::named {
4196+
if named {
41994197
self.obsolete(*self.last_span, ObsoleteNamedExternModule);
42004198
}
42014199

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

42044202
let (inner, next) = self.parse_inner_attrs_and_next();
4205-
let m = self.parse_foreign_mod_items(sort, abis, next);
4203+
let m = self.parse_foreign_mod_items(abis, next);
42064204
self.expect(&token::RBRACE);
42074205

42084206
return iovi_item(self.mk_item(lo,

src/libsyntax/print/pprust.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,6 @@ pub fn print_item(s: @ps, item: &ast::item) {
539539
ast::item_foreign_mod(ref nmod) => {
540540
head(s, "extern");
541541
word_nbsp(s, nmod.abis.to_str());
542-
match nmod.sort {
543-
ast::named => {
544-
word_nbsp(s, "mod");
545-
print_ident(s, item.ident);
546-
nbsp(s);
547-
}
548-
ast::anonymous => {}
549-
}
550542
bopen(s);
551543
print_foreign_mod(s, nmod, item.attrs);
552544
bclose(s, item.span);

0 commit comments

Comments
 (0)