about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-10-10 12:57:34 -0700
committerAlex Crichton <alex@alexcrichton.com>2013-10-10 18:04:58 -0700
commitb70306158ff41706e08c691596087502ba40f635 (patch)
treeddd4423a7b803d445042b9ad99a7e97ce9d282c9 /src
parent34d123db4eb03c1b2378b6248ebea5f0f40f2a4f (diff)
downloadrust-b70306158ff41706e08c691596087502ba40f635.tar.gz
rust-b70306158ff41706e08c691596087502ba40f635.zip
Remove named extern blocks from the AST
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.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/front/config.rs1
-rw-r--r--src/librustc/metadata/creader.rs63
-rw-r--r--src/librustc/middle/resolve.rs26
-rw-r--r--src/libsyntax/ast.rs8
-rw-r--r--src/libsyntax/ast_map.rs8
-rw-r--r--src/libsyntax/fold.rs1
-rw-r--r--src/libsyntax/parse/parser.rs12
-rw-r--r--src/libsyntax/print/pprust.rs8
8 files changed, 40 insertions, 87 deletions
diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs
index becf5059f32..c11208b0d3e 100644
--- a/src/librustc/front/config.rs
+++ b/src/librustc/front/config.rs
@@ -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
diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs
index fd4f31c3dc7..6df083aca4f 100644
--- a/src/librustc/metadata/creader.rs
+++ b/src/librustc/metadata/creader.rs
@@ -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() {
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index deeeae7bec0..a6c22bd5742 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -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, _) => {
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 63c2f0e5191..08e1390a981 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -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],
diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs
index b3d5e03331c..83205ccc981 100644
--- a/src/libsyntax/ast_map.rs
+++ b/src/libsyntax/ast_map.rs
@@ -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, _) => {
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 3c601196db9..84ff98b0188 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -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()
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 9f1a436a4d5..e7c579d2f19 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -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 {
@@ -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
@@ -4169,7 +4167,7 @@ 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 {
@@ -4177,7 +4175,7 @@ impl Parser {
                     Some(self.parse_str())
                 }
                 else { None };
-                (ast::named, path, the_ident)
+                (true, path, the_ident)
             }
             _ => {
                 if must_be_named_mod {
@@ -4187,7 +4185,7 @@ impl Parser {
                                          self.this_token_to_str()));
                 }
 
-                (ast::anonymous, None,
+                (false, None,
                  special_idents::clownshoes_foreign_mod)
             }
         };
@@ -4195,14 +4193,14 @@ impl Parser {
         // 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,
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 74d5e1a6d27..607eb81102f 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -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);