about summary refs log tree commit diff
path: root/src/librustc_metadata
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-10-21 01:48:31 -0700
committerGitHub <noreply@github.com>2016-10-21 01:48:31 -0700
commitda5b6467c33f7f86b4964b08b37726f7611a8f0c (patch)
treebda505a46fc98c456aa2012b41af936d99fb1a79 /src/librustc_metadata
parente4708273b5401cd572d19f8836e121ce39dc2767 (diff)
parentb283aaf0ff74db93162b402e627f3b4ed7fb7d4e (diff)
downloadrust-da5b6467c33f7f86b4964b08b37726f7611a8f0c.tar.gz
rust-da5b6467c33f7f86b4964b08b37726f7611a8f0c.zip
Auto merge of #37247 - jseyfried:future_proof_no_link, r=nrc
macros: Future proof `#[no_link]`

This PR future proofs `#[no_link]` for macro modularization (cc #35896).

First, we resolve all `#[no_link] extern crate`s. `#[no_link]` crates without `#[macro_use]` or `#[macro_reexport]` are not resolved today, this is a [breaking-change]. For example,
```rust
```
Any breakage can be fixed by simply removing the `#[no_link] extern crate`.

Second, `#[no_link] extern crate`s will define an empty module in type namespace to eventually allow importing the crate's macros with `use`. This is a [breaking-change], for example:
```rust
mod syntax {} //< This becomes a duplicate error.
```

r? @nrc
Diffstat (limited to 'src/librustc_metadata')
-rw-r--r--src/librustc_metadata/macro_import.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/librustc_metadata/macro_import.rs b/src/librustc_metadata/macro_import.rs
index 3b1b2a4cd27..41e14ea9f40 100644
--- a/src/librustc_metadata/macro_import.rs
+++ b/src/librustc_metadata/macro_import.rs
@@ -52,6 +52,7 @@ impl<'a> CrateLoader<'a> {
         // Parse the attributes relating to macros.
         let mut import = ImportSelection::Some(FnvHashMap());
         let mut reexport = FnvHashMap();
+        let mut no_link = false;
 
         for attr in &extern_crate.attrs {
             let mut used = true;
@@ -87,6 +88,7 @@ impl<'a> CrateLoader<'a> {
                         }
                     }
                 }
+                "no_link" => no_link = true,
                 _ => used = false,
             }
             if used {
@@ -94,17 +96,22 @@ impl<'a> CrateLoader<'a> {
             }
         }
 
-        self.load_macros(extern_crate, allows_macros, import, reexport)
+        self.load_macros(extern_crate, allows_macros, import, reexport, no_link)
     }
 
     fn load_macros<'b>(&mut self,
                        vi: &ast::Item,
                        allows_macros: bool,
                        import: ImportSelection,
-                       reexport: MacroSelection)
+                       reexport: MacroSelection,
+                       no_link: bool)
                        -> Vec<LoadedMacro> {
         if let ImportSelection::Some(ref sel) = import {
             if sel.is_empty() && reexport.is_empty() {
+                // Make sure we can read macros from `#[no_link]` crates.
+                if no_link {
+                    self.creader.read_macros(vi);
+                }
                 return Vec::new();
             }
         }