@@ -67,16 +67,12 @@ fn dump_crates(cstore: &CStore) {
6767 } )
6868}
6969
70- fn should_link ( i : & ast:: Item ) -> bool {
71- !attr:: contains_name ( & i. attrs , "no_link" )
72- }
73-
7470#[ derive( Debug ) ]
7571struct ExternCrateInfo {
7672 ident : String ,
7773 name : String ,
7874 id : ast:: NodeId ,
79- should_link : bool ,
75+ dep_kind : DepKind ,
8076}
8177
8278fn register_native_lib ( sess : & Session ,
@@ -168,7 +164,11 @@ impl<'a> CrateLoader<'a> {
168164 ident : i. ident . to_string ( ) ,
169165 name : name,
170166 id : i. id ,
171- should_link : should_link ( i) ,
167+ dep_kind : if attr:: contains_name ( & i. attrs , "no_link" ) {
168+ DepKind :: MacrosOnly
169+ } else {
170+ DepKind :: Explicit
171+ } ,
172172 } )
173173 }
174174 _ => None
@@ -283,7 +283,7 @@ impl<'a> CrateLoader<'a> {
283283
284284 let Library { dylib, rlib, metadata } = lib;
285285
286- let cnum_map = self . resolve_crate_deps ( root, & crate_root, & metadata, cnum, span) ;
286+ let cnum_map = self . resolve_crate_deps ( root, & crate_root, & metadata, cnum, span, dep_kind ) ;
287287
288288 if crate_root. macro_derive_registrar . is_some ( ) {
289289 self . sess . span_err ( span, "crates of the `proc-macro` crate type \
@@ -427,21 +427,23 @@ impl<'a> CrateLoader<'a> {
427427 crate_root : & CrateRoot ,
428428 metadata : & MetadataBlob ,
429429 krate : CrateNum ,
430- span : Span )
430+ span : Span ,
431+ dep_kind : DepKind )
431432 -> cstore:: CrateNumMap {
432433 debug ! ( "resolving deps of external crate" ) ;
433434 // The map from crate numbers in the crate we're resolving to local crate
434435 // numbers
435436 let deps = crate_root. crate_deps . decode ( metadata) ;
436437 let map: FxHashMap < _ , _ > = deps. enumerate ( ) . map ( |( crate_num, dep) | {
437438 debug ! ( "resolving dep crate {} hash: `{}`" , dep. name, dep. hash) ;
438- let ( local_cnum, ..) = self . resolve_crate ( root,
439- & dep. name . as_str ( ) ,
440- & dep. name . as_str ( ) ,
441- Some ( & dep. hash ) ,
442- span,
443- PathKind :: Dependency ,
444- dep. kind ) ;
439+ let dep_name = & dep. name . as_str ( ) ;
440+ let dep_kind = match dep_kind {
441+ DepKind :: MacrosOnly => DepKind :: MacrosOnly ,
442+ _ => dep. kind ,
443+ } ;
444+ let ( local_cnum, ..) = self . resolve_crate (
445+ root, dep_name, dep_name, Some ( & dep. hash ) , span, PathKind :: Dependency , dep_kind,
446+ ) ;
445447 ( CrateNum :: new ( crate_num + 1 ) , local_cnum)
446448 } ) . collect ( ) ;
447449
@@ -455,8 +457,8 @@ impl<'a> CrateLoader<'a> {
455457 }
456458
457459 fn read_extension_crate ( & mut self , span : Span , info : & ExternCrateInfo ) -> ExtensionCrate {
458- info ! ( "read extension crate {} `extern crate {} as {}` linked={ }" ,
459- info. id, info. name, info. ident, info. should_link ) ;
460+ info ! ( "read extension crate {} `extern crate {} as {}` dep_kind={:? }" ,
461+ info. id, info. name, info. ident, info. dep_kind ) ;
460462 let target_triple = & self . sess . opts . target_triple [ ..] ;
461463 let is_cross = target_triple != config:: host_triple ( ) ;
462464 let mut target_only = false ;
@@ -641,7 +643,7 @@ impl<'a> CrateLoader<'a> {
641643 name : name. to_string ( ) ,
642644 ident : name. to_string ( ) ,
643645 id : ast:: DUMMY_NODE_ID ,
644- should_link : false ,
646+ dep_kind : DepKind :: MacrosOnly ,
645647 } ) ;
646648
647649 if ekrate. target_only {
@@ -984,30 +986,26 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
984986 let ekrate = self . read_extension_crate ( item. span , & info) ;
985987 let loaded_macros = self . read_macros ( item, & ekrate) ;
986988
987- // If this is a proc-macro crate or `#[no_link]` crate, it is only used at compile time,
988- // so we return here to avoid registering the crate.
989- if loaded_macros. is_proc_macros ( ) || !info. should_link {
989+ // If this is a proc-macro crate, return here to avoid registering.
990+ if loaded_macros. is_proc_macros ( ) {
990991 return Some ( loaded_macros) ;
991992 }
992993
993994 // Register crate now to avoid double-reading metadata
994995 if let PMDSource :: Owned ( lib) = ekrate. metadata {
995996 if ekrate. target_only || config:: host_triple ( ) == self . sess . opts . target_triple {
996- let ExternCrateInfo { ref ident, ref name, .. } = info;
997- self . register_crate ( & None , ident, name, item. span , lib, DepKind :: Explicit ) ;
997+ let ExternCrateInfo { ref ident, ref name, dep_kind , .. } = info;
998+ self . register_crate ( & None , ident, name, item. span , lib, dep_kind ) ;
998999 }
9991000 }
10001001
10011002 Some ( loaded_macros)
10021003 } else {
1003- if !info. should_link {
1004- return None ;
1005- }
10061004 None
10071005 } ;
10081006
10091007 let ( cnum, ..) = self . resolve_crate (
1010- & None , & info. ident , & info. name , None , item. span , PathKind :: Crate , DepKind :: Explicit ,
1008+ & None , & info. ident , & info. name , None , item. span , PathKind :: Crate , info . dep_kind ,
10111009 ) ;
10121010
10131011 let def_id = definitions. opt_local_def_id ( item. id ) . unwrap ( ) ;
0 commit comments