@@ -100,6 +100,18 @@ enum LoadResult {
100100 Loaded ( Library ) ,
101101}
102102
103+ enum LoadError < ' a > {
104+ LocatorError ( locator:: Context < ' a > ) ,
105+ }
106+
107+ impl < ' a > LoadError < ' a > {
108+ fn report ( self ) -> ! {
109+ match self {
110+ LoadError :: LocatorError ( mut locate_ctxt) => locate_ctxt. report_errs ( ) ,
111+ }
112+ }
113+ }
114+
103115impl < ' a > CrateLoader < ' a > {
104116 pub fn new ( sess : & ' a Session , cstore : & ' a CStore , local_crate_name : & str ) -> Self {
105117 CrateLoader {
@@ -268,16 +280,17 @@ impl<'a> CrateLoader<'a> {
268280 ( cnum, cmeta)
269281 }
270282
271- fn resolve_crate ( & mut self ,
272- root : & Option < CratePaths > ,
273- ident : Symbol ,
274- name : Symbol ,
275- hash : Option < & Svh > ,
276- extra_filename : Option < & str > ,
277- span : Span ,
278- path_kind : PathKind ,
279- mut dep_kind : DepKind )
280- -> ( CrateNum , Lrc < cstore:: CrateMetadata > ) {
283+ fn resolve_crate < ' b > (
284+ & ' b mut self ,
285+ root : & ' b Option < CratePaths > ,
286+ ident : Symbol ,
287+ name : Symbol ,
288+ hash : Option < & ' b Svh > ,
289+ extra_filename : Option < & ' b str > ,
290+ span : Span ,
291+ path_kind : PathKind ,
292+ mut dep_kind : DepKind ,
293+ ) -> Result < ( CrateNum , Lrc < cstore:: CrateMetadata > ) , LoadError < ' b > > {
281294 info ! ( "resolving crate `extern crate {} as {}`" , name, ident) ;
282295 let result = if let Some ( cnum) = self . existing_match ( name, hash, path_kind) {
283296 LoadResult :: Previous ( cnum)
@@ -321,7 +334,7 @@ impl<'a> CrateLoader<'a> {
321334 } ;
322335
323336 self . load ( & mut proc_macro_locator)
324- } ) . unwrap_or_else ( || locate_ctxt . report_errs ( ) )
337+ } ) . ok_or_else ( move || LoadError :: LocatorError ( locate_ctxt ) ) ?
325338 } ;
326339
327340 match result {
@@ -333,10 +346,10 @@ impl<'a> CrateLoader<'a> {
333346 data. dep_kind . with_lock ( |data_dep_kind| {
334347 * data_dep_kind = cmp:: max ( * data_dep_kind, dep_kind) ;
335348 } ) ;
336- ( cnum, data)
349+ Ok ( ( cnum, data) )
337350 }
338351 LoadResult :: Loaded ( library) => {
339- self . register_crate ( root, ident, span, library, dep_kind)
352+ Ok ( self . register_crate ( root, ident, span, library, dep_kind) )
340353 }
341354 }
342355 }
@@ -441,7 +454,7 @@ impl<'a> CrateLoader<'a> {
441454 let ( local_cnum, ..) = self . resolve_crate (
442455 root, dep. name , dep. name , Some ( & dep. hash ) , Some ( & dep. extra_filename ) , span,
443456 PathKind :: Dependency , dep_kind,
444- ) ;
457+ ) . unwrap_or_else ( |err| err . report ( ) ) ;
445458 local_cnum
446459 } ) ) . collect ( )
447460 }
@@ -695,7 +708,8 @@ impl<'a> CrateLoader<'a> {
695708
696709 let dep_kind = DepKind :: Implicit ;
697710 let ( cnum, data) =
698- self . resolve_crate ( & None , name, name, None , None , DUMMY_SP , PathKind :: Crate , dep_kind) ;
711+ self . resolve_crate ( & None , name, name, None , None , DUMMY_SP , PathKind :: Crate , dep_kind)
712+ . unwrap_or_else ( |err| err. report ( ) ) ;
699713
700714 // Sanity check the loaded crate to ensure it is indeed a panic runtime
701715 // and the panic strategy is indeed what we thought it was.
@@ -803,7 +817,8 @@ impl<'a> CrateLoader<'a> {
803817 let dep_kind = DepKind :: Explicit ;
804818 let ( _, data) =
805819 self . resolve_crate ( & None , symbol, symbol, None , None , DUMMY_SP ,
806- PathKind :: Crate , dep_kind) ;
820+ PathKind :: Crate , dep_kind)
821+ . unwrap_or_else ( |err| err. report ( ) ) ;
807822
808823 // Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
809824 if !data. root . sanitizer_runtime {
@@ -826,7 +841,8 @@ impl<'a> CrateLoader<'a> {
826841 let dep_kind = DepKind :: Implicit ;
827842 let ( _, data) =
828843 self . resolve_crate ( & None , symbol, symbol, None , None , DUMMY_SP ,
829- PathKind :: Crate , dep_kind) ;
844+ PathKind :: Crate , dep_kind)
845+ . unwrap_or_else ( |err| err. report ( ) ) ;
830846
831847 // Sanity check the loaded crate to ensure it is indeed a profiler runtime
832848 if !data. root . profiler_runtime {
@@ -946,7 +962,8 @@ impl<'a> CrateLoader<'a> {
946962 None ,
947963 DUMMY_SP ,
948964 PathKind :: Crate ,
949- DepKind :: Implicit ) ;
965+ DepKind :: Implicit )
966+ . unwrap_or_else ( |err| err. report ( ) ) ;
950967 self . sess . injected_allocator . set ( Some ( cnum) ) ;
951968 data
952969 } )
@@ -1103,7 +1120,7 @@ impl<'a> CrateLoader<'a> {
11031120 let ( cnum, ..) = self . resolve_crate (
11041121 & None , item. ident . name , orig_name, None , None ,
11051122 item. span , PathKind :: Crate , dep_kind,
1106- ) ;
1123+ ) . unwrap_or_else ( |err| err . report ( ) ) ;
11071124
11081125 let def_id = definitions. opt_local_def_id ( item. id ) . unwrap ( ) ;
11091126 let path_len = definitions. def_path ( def_id. index ) . data . len ( ) ;
@@ -1131,7 +1148,7 @@ impl<'a> CrateLoader<'a> {
11311148 ) -> CrateNum {
11321149 let cnum = self . resolve_crate (
11331150 & None , name, name, None , None , span, PathKind :: Crate , DepKind :: Explicit
1134- ) . 0 ;
1151+ ) . unwrap_or_else ( |err| err . report ( ) ) . 0 ;
11351152
11361153 self . update_extern_crate (
11371154 cnum,
@@ -1147,4 +1164,28 @@ impl<'a> CrateLoader<'a> {
11471164
11481165 cnum
11491166 }
1167+
1168+ pub fn maybe_process_path_extern (
1169+ & mut self ,
1170+ name : Symbol ,
1171+ span : Span ,
1172+ ) -> Option < CrateNum > {
1173+ let cnum = self . resolve_crate (
1174+ & None , name, name, None , None , span, PathKind :: Crate , DepKind :: Explicit
1175+ ) . ok ( ) ?. 0 ;
1176+
1177+ self . update_extern_crate (
1178+ cnum,
1179+ ExternCrate {
1180+ src : ExternCrateSource :: Path ,
1181+ span,
1182+ // to have the least priority in `update_extern_crate`
1183+ path_len : usize:: max_value ( ) ,
1184+ direct : true ,
1185+ } ,
1186+ & mut FxHashSet ( ) ,
1187+ ) ;
1188+
1189+ Some ( cnum)
1190+ }
11501191}
0 commit comments