@@ -100,6 +100,18 @@ enum LoadResult {
100
100
Loaded ( Library ) ,
101
101
}
102
102
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
+
103
115
impl < ' a > CrateLoader < ' a > {
104
116
pub fn new ( sess : & ' a Session , cstore : & ' a CStore , local_crate_name : & str ) -> Self {
105
117
CrateLoader {
@@ -268,16 +280,17 @@ impl<'a> CrateLoader<'a> {
268
280
( cnum, cmeta)
269
281
}
270
282
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 > > {
281
294
info ! ( "resolving crate `extern crate {} as {}`" , name, ident) ;
282
295
let result = if let Some ( cnum) = self . existing_match ( name, hash, path_kind) {
283
296
LoadResult :: Previous ( cnum)
@@ -321,7 +334,7 @@ impl<'a> CrateLoader<'a> {
321
334
} ;
322
335
323
336
self . load ( & mut proc_macro_locator)
324
- } ) . unwrap_or_else ( || locate_ctxt . report_errs ( ) )
337
+ } ) . ok_or_else ( move || LoadError :: LocatorError ( locate_ctxt ) ) ?
325
338
} ;
326
339
327
340
match result {
@@ -333,10 +346,10 @@ impl<'a> CrateLoader<'a> {
333
346
data. dep_kind . with_lock ( |data_dep_kind| {
334
347
* data_dep_kind = cmp:: max ( * data_dep_kind, dep_kind) ;
335
348
} ) ;
336
- ( cnum, data)
349
+ Ok ( ( cnum, data) )
337
350
}
338
351
LoadResult :: Loaded ( library) => {
339
- self . register_crate ( root, ident, span, library, dep_kind)
352
+ Ok ( self . register_crate ( root, ident, span, library, dep_kind) )
340
353
}
341
354
}
342
355
}
@@ -441,7 +454,7 @@ impl<'a> CrateLoader<'a> {
441
454
let ( local_cnum, ..) = self . resolve_crate (
442
455
root, dep. name , dep. name , Some ( & dep. hash ) , Some ( & dep. extra_filename ) , span,
443
456
PathKind :: Dependency , dep_kind,
444
- ) ;
457
+ ) . unwrap_or_else ( |err| err . report ( ) ) ;
445
458
local_cnum
446
459
} ) ) . collect ( )
447
460
}
@@ -695,7 +708,8 @@ impl<'a> CrateLoader<'a> {
695
708
696
709
let dep_kind = DepKind :: Implicit ;
697
710
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 ( ) ) ;
699
713
700
714
// Sanity check the loaded crate to ensure it is indeed a panic runtime
701
715
// and the panic strategy is indeed what we thought it was.
@@ -803,7 +817,8 @@ impl<'a> CrateLoader<'a> {
803
817
let dep_kind = DepKind :: Explicit ;
804
818
let ( _, data) =
805
819
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 ( ) ) ;
807
822
808
823
// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
809
824
if !data. root . sanitizer_runtime {
@@ -826,7 +841,8 @@ impl<'a> CrateLoader<'a> {
826
841
let dep_kind = DepKind :: Implicit ;
827
842
let ( _, data) =
828
843
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 ( ) ) ;
830
846
831
847
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
832
848
if !data. root . profiler_runtime {
@@ -946,7 +962,8 @@ impl<'a> CrateLoader<'a> {
946
962
None ,
947
963
DUMMY_SP ,
948
964
PathKind :: Crate ,
949
- DepKind :: Implicit ) ;
965
+ DepKind :: Implicit )
966
+ . unwrap_or_else ( |err| err. report ( ) ) ;
950
967
self . sess . injected_allocator . set ( Some ( cnum) ) ;
951
968
data
952
969
} )
@@ -1103,7 +1120,7 @@ impl<'a> CrateLoader<'a> {
1103
1120
let ( cnum, ..) = self . resolve_crate (
1104
1121
& None , item. ident . name , orig_name, None , None ,
1105
1122
item. span , PathKind :: Crate , dep_kind,
1106
- ) ;
1123
+ ) . unwrap_or_else ( |err| err . report ( ) ) ;
1107
1124
1108
1125
let def_id = definitions. opt_local_def_id ( item. id ) . unwrap ( ) ;
1109
1126
let path_len = definitions. def_path ( def_id. index ) . data . len ( ) ;
@@ -1131,7 +1148,7 @@ impl<'a> CrateLoader<'a> {
1131
1148
) -> CrateNum {
1132
1149
let cnum = self . resolve_crate (
1133
1150
& None , name, name, None , None , span, PathKind :: Crate , DepKind :: Explicit
1134
- ) . 0 ;
1151
+ ) . unwrap_or_else ( |err| err . report ( ) ) . 0 ;
1135
1152
1136
1153
self . update_extern_crate (
1137
1154
cnum,
@@ -1147,4 +1164,28 @@ impl<'a> CrateLoader<'a> {
1147
1164
1148
1165
cnum
1149
1166
}
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
+ }
1150
1191
}
0 commit comments