@@ -47,8 +47,13 @@ crate const COLLECT_INTRA_DOC_LINKS: Pass = Pass {
47
47
description : "resolves intra-doc links" ,
48
48
} ;
49
49
50
- crate fn collect_intra_doc_links ( krate : Crate , cx : & DocContext < ' _ > ) -> Crate {
51
- LinkCollector :: new ( cx) . fold_crate ( krate)
50
+ crate fn collect_intra_doc_links ( krate : Crate , cx : & mut DocContext < ' _ > ) -> Crate {
51
+ LinkCollector {
52
+ cx,
53
+ mod_ids : Vec :: new ( ) ,
54
+ kind_side_channel : Cell :: new ( None ) ,
55
+ visited_links : FxHashMap :: default ( ) ,
56
+ } . fold_crate ( krate)
52
57
}
53
58
54
59
/// Top-level errors emitted by this pass.
@@ -257,7 +262,7 @@ struct CachedLink {
257
262
}
258
263
259
264
struct LinkCollector < ' a , ' tcx > {
260
- cx : & ' a DocContext < ' tcx > ,
265
+ cx : & ' a mut DocContext < ' tcx > ,
261
266
/// A stack of modules used to decide what scope to resolve in.
262
267
///
263
268
/// The last module will be used if the parent scope of the current item is
@@ -273,15 +278,6 @@ struct LinkCollector<'a, 'tcx> {
273
278
}
274
279
275
280
impl < ' a , ' tcx > LinkCollector < ' a , ' tcx > {
276
- fn new ( cx : & ' a DocContext < ' tcx > ) -> Self {
277
- LinkCollector {
278
- cx,
279
- mod_ids : Vec :: new ( ) ,
280
- kind_side_channel : Cell :: new ( None ) ,
281
- visited_links : FxHashMap :: default ( ) ,
282
- }
283
- }
284
-
285
281
/// Given a full link, parse it as an [enum struct variant].
286
282
///
287
283
/// In particular, this will return an error whenever there aren't three
@@ -293,7 +289,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
293
289
path_str : & ' path str ,
294
290
module_id : DefId ,
295
291
) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
296
- let cx = self . cx ;
292
+ let tcx = self . cx . tcx ;
297
293
let no_res = || ResolutionFailure :: NotResolved {
298
294
module_id,
299
295
partial_res : None ,
@@ -317,7 +313,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
317
313
// If there's no third component, we saw `[a::b]` before and it failed to resolve.
318
314
// So there's no partial res.
319
315
. ok_or_else ( no_res) ?;
320
- let ty_res = cx
316
+ let ty_res = self . cx
321
317
. enter_resolver ( |resolver| {
322
318
resolver. resolve_str_path_error ( DUMMY_SP , & path, TypeNS , module_id)
323
319
} )
@@ -326,18 +322,17 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
326
322
327
323
match ty_res {
328
324
Res :: Def ( DefKind :: Enum , did) => {
329
- if cx
330
- . tcx
325
+ if tcx
331
326
. inherent_impls ( did)
332
327
. iter ( )
333
- . flat_map ( |imp| cx . tcx . associated_items ( * imp) . in_definition_order ( ) )
328
+ . flat_map ( |imp| tcx. associated_items ( * imp) . in_definition_order ( ) )
334
329
. any ( |item| item. ident . name == variant_name)
335
330
{
336
331
// This is just to let `fold_item` know that this shouldn't be considered;
337
332
// it's a bug for the error to make it to the user
338
333
return Err ( ResolutionFailure :: Dummy . into ( ) ) ;
339
334
}
340
- match cx . tcx . type_of ( did) . kind ( ) {
335
+ match tcx. type_of ( did) . kind ( ) {
341
336
ty:: Adt ( def, _) if def. is_enum ( ) => {
342
337
if def. all_fields ( ) . any ( |item| item. ident . name == variant_field_name) {
343
338
Ok ( (
@@ -380,16 +375,16 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
380
375
item_name : Symbol ,
381
376
item_str : & ' path str ,
382
377
) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
383
- let cx = self . cx ;
378
+ let tcx = self . cx . tcx ;
384
379
385
380
prim_ty
386
- . impls ( cx . tcx )
381
+ . impls ( tcx)
387
382
. into_iter ( )
388
383
. find_map ( |& impl_| {
389
- cx . tcx
384
+ tcx
390
385
. associated_items ( impl_)
391
386
. find_by_name_and_namespace (
392
- cx . tcx ,
387
+ tcx,
393
388
Ident :: with_dummy_span ( item_name) ,
394
389
ns,
395
390
impl_,
@@ -434,9 +429,8 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
434
429
path_str : & ' a str ,
435
430
module_id : DefId ,
436
431
) -> Result < Res , ResolutionFailure < ' a > > {
437
- let cx = self . cx ;
438
432
let path = ast:: Path :: from_ident ( Ident :: from_str ( path_str) ) ;
439
- cx. enter_resolver ( |resolver| {
433
+ self . cx . enter_resolver ( |resolver| {
440
434
// FIXME(jynelson): does this really need 3 separate lookups?
441
435
if let Ok ( ( Some ( ext) , res) ) = resolver. resolve_macro_path (
442
436
& path,
@@ -498,7 +492,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
498
492
module_id : DefId ,
499
493
extra_fragment : & Option < String > ,
500
494
) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
501
- let cx = self . cx ;
495
+ let cx = & self . cx ;
502
496
503
497
if let Some ( res) = self . resolve_path ( path_str, ns, module_id) {
504
498
match res {
@@ -948,12 +942,11 @@ impl LinkCollector<'_, '_> {
948
942
return None ;
949
943
}
950
944
951
- let cx = self . cx ;
952
945
let link = ori_link. link . replace ( "`" , "" ) ;
953
946
let parts = link. split ( '#' ) . collect :: < Vec < _ > > ( ) ;
954
947
let ( link, extra_fragment) = if parts. len ( ) > 2 {
955
948
// A valid link can't have multiple #'s
956
- anchor_failure ( cx, & item, & link, dox, ori_link. range , AnchorFailure :: MultipleAnchors ) ;
949
+ anchor_failure ( self . cx , & item, & link, dox, ori_link. range , AnchorFailure :: MultipleAnchors ) ;
957
950
return None ;
958
951
} else if parts. len ( ) == 2 {
959
952
if parts[ 0 ] . trim ( ) . is_empty ( ) {
@@ -1105,7 +1098,7 @@ impl LinkCollector<'_, '_> {
1105
1098
if matches ! ( disambiguator, Some ( Disambiguator :: Primitive ) ) {
1106
1099
if fragment. is_some ( ) {
1107
1100
anchor_failure (
1108
- cx,
1101
+ self . cx ,
1109
1102
& item,
1110
1103
path_str,
1111
1104
dox,
@@ -1119,7 +1112,7 @@ impl LinkCollector<'_, '_> {
1119
1112
} else {
1120
1113
// `[char]` when a `char` module is in scope
1121
1114
let candidates = vec ! [ res, prim] ;
1122
- ambiguity_error ( cx, & item, path_str, dox, ori_link. range , candidates) ;
1115
+ ambiguity_error ( self . cx , & item, path_str, dox, ori_link. range , candidates) ;
1123
1116
return None ;
1124
1117
}
1125
1118
}
@@ -1140,7 +1133,7 @@ impl LinkCollector<'_, '_> {
1140
1133
suggest_disambiguator ( resolved, diag, path_str, dox, sp, & ori_link. range ) ;
1141
1134
} ;
1142
1135
report_diagnostic (
1143
- cx,
1136
+ self . cx ,
1144
1137
BROKEN_INTRA_DOC_LINKS ,
1145
1138
& msg,
1146
1139
& item,
@@ -1187,7 +1180,7 @@ impl LinkCollector<'_, '_> {
1187
1180
if self . cx . tcx . privacy_access_levels ( LOCAL_CRATE ) . is_exported ( hir_src)
1188
1181
&& !self . cx . tcx . privacy_access_levels ( LOCAL_CRATE ) . is_exported ( hir_dst)
1189
1182
{
1190
- privacy_error ( cx, & item, & path_str, dox, & ori_link) ;
1183
+ privacy_error ( self . cx , & item, & path_str, dox, & ori_link) ;
1191
1184
}
1192
1185
}
1193
1186
@@ -1211,7 +1204,7 @@ impl LinkCollector<'_, '_> {
1211
1204
&& !self . cx . tcx . features ( ) . intra_doc_pointers
1212
1205
{
1213
1206
let span = super :: source_span_for_markdown_range (
1214
- cx,
1207
+ self . cx ,
1215
1208
dox,
1216
1209
& ori_link. range ,
1217
1210
& item. attrs ,
@@ -1243,7 +1236,7 @@ impl LinkCollector<'_, '_> {
1243
1236
}
1244
1237
Res :: Def ( kind, id) => {
1245
1238
verify ( kind, id) ?;
1246
- let id = clean:: register_res ( cx, rustc_hir:: def:: Res :: Def ( kind, id) ) ;
1239
+ let id = clean:: register_res ( self . cx , rustc_hir:: def:: Res :: Def ( kind, id) ) ;
1247
1240
Some ( ItemLink { link : ori_link. link , link_text, did : Some ( id) , fragment } )
1248
1241
}
1249
1242
}
0 commit comments