]> git.lizzy.rs Git - rust.git/commitdiff
Future proof `#[no_link]`.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Tue, 18 Oct 2016 05:33:50 +0000 (05:33 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Wed, 19 Oct 2016 10:05:03 +0000 (10:05 +0000)
src/librustc_metadata/macro_import.rs
src/librustc_resolve/build_reduced_graph.rs
src/test/compile-fail-fulldeps/macro-crate-doesnt-resolve.rs
src/test/compile-fail-fulldeps/macro-crate-unknown-crate.rs [deleted file]
src/test/compile-fail-fulldeps/no-link-unknown-crate.rs [new file with mode: 0644]
src/test/compile-fail/no-link.rs

index 3b1b2a4cd27e432c13763072f7640cc4e2857d2c..41e14ea9f406f4386ef1e8f4e2840e7d4f48b31d 100644 (file)
@@ -52,6 +52,7 @@ fn load_crate(&mut self,
         // 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 @@ fn load_crate(&mut self,
                         }
                     }
                 }
+                "no_link" => no_link = true,
                 _ => used = false,
             }
             if used {
@@ -94,17 +96,22 @@ fn load_crate(&mut self,
             }
         }
 
-        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();
             }
         }
index e0abe8da82b9c26b9b256a28b6627e772e40be79..a5bc708b4f05a672dca91624bda01f6ca50978c5 100644 (file)
@@ -250,7 +250,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
                     self.define(parent, name, TypeNS, (module, sp, vis));
 
                     self.populate_module_if_necessary(module);
-                } else if custom_derive_crate {
+                } else {
                     // Define an empty module
                     let def = Def::Mod(self.definitions.local_def_id(item.id));
                     let module = ModuleS::new(Some(parent), ModuleKind::Def(def, name));
index 1fbde00a3dfdecf2b7377ad415cbd78d29a64bf0..f563a1f88d000acdb8e534629d25935c92a8e951 100644 (file)
@@ -14,6 +14,5 @@
 extern crate macro_crate_test;
 
 fn main() {
-    macro_crate_test::foo();
-    //~^ ERROR failed to resolve. Use of undeclared type or module `macro_crate_test`
+    macro_crate_test::foo(); //~ ERROR unresolved name
 }
diff --git a/src/test/compile-fail-fulldeps/macro-crate-unknown-crate.rs b/src/test/compile-fail-fulldeps/macro-crate-unknown-crate.rs
deleted file mode 100644 (file)
index 65657ee..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#[macro_use] #[no_link]
-extern crate doesnt_exist; //~ ERROR can't find crate
-
-fn main() {}
diff --git a/src/test/compile-fail-fulldeps/no-link-unknown-crate.rs b/src/test/compile-fail-fulldeps/no-link-unknown-crate.rs
new file mode 100644 (file)
index 0000000..8e4692b
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#[no_link]
+extern crate doesnt_exist; //~ ERROR can't find crate
+
+fn main() {}
index 957b6cda55311b79c927ee3ec5de589e5085cc92..8f6da99806b3b410581f8af8311ddfe2211fd1e1 100644 (file)
@@ -13,6 +13,6 @@
 
 fn main() {
     unsafe {
-        libc::abs(0);  //~ ERROR Use of undeclared type or module `libc`
+        libc::abs(0);  //~ ERROR unresolved name
     }
 }