Skip to content

Commit

Permalink
Future proof #[no_link].
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Oct 19, 2016
1 parent 0c42987 commit b283aaf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/librustc_metadata/macro_import.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -87,24 +88,30 @@ impl<'a> CrateLoader<'a> {
}
}
}
"no_link" => no_link = true,
_ => used = false,
}
if used {
attr::mark_used(attr);
}
}

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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -250,7 +250,7 @@ impl<'b> Resolver<'b> {
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));
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail-fulldeps/macro-crate-doesnt-resolve.rs
Expand Up @@ -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
}
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[macro_use] #[no_link]
#[no_link]
extern crate doesnt_exist; //~ ERROR can't find crate

fn main() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/no-link.rs
Expand Up @@ -13,6 +13,6 @@ extern crate libc;

fn main() {
unsafe {
libc::abs(0); //~ ERROR Use of undeclared type or module `libc`
libc::abs(0); //~ ERROR unresolved name
}
}

0 comments on commit b283aaf

Please sign in to comment.