@@ -47,8 +47,13 @@ crate const COLLECT_INTRA_DOC_LINKS: Pass = Pass {
4747 description : "resolves intra-doc links" ,
4848} ;
4949
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)
5257}
5358
5459/// Top-level errors emitted by this pass.
@@ -257,7 +262,7 @@ struct CachedLink {
257262}
258263
259264struct LinkCollector < ' a , ' tcx > {
260- cx : & ' a DocContext < ' tcx > ,
265+ cx : & ' a mut DocContext < ' tcx > ,
261266 /// A stack of modules used to decide what scope to resolve in.
262267 ///
263268 /// The last module will be used if the parent scope of the current item is
@@ -273,15 +278,6 @@ struct LinkCollector<'a, 'tcx> {
273278}
274279
275280impl < ' 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-
285281 /// Given a full link, parse it as an [enum struct variant].
286282 ///
287283 /// In particular, this will return an error whenever there aren't three
@@ -293,7 +289,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
293289 path_str : & ' path str ,
294290 module_id : DefId ,
295291 ) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
296- let cx = self . cx ;
292+ let tcx = self . cx . tcx ;
297293 let no_res = || ResolutionFailure :: NotResolved {
298294 module_id,
299295 partial_res : None ,
@@ -317,7 +313,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
317313 // If there's no third component, we saw `[a::b]` before and it failed to resolve.
318314 // So there's no partial res.
319315 . ok_or_else ( no_res) ?;
320- let ty_res = cx
316+ let ty_res = self . cx
321317 . enter_resolver ( |resolver| {
322318 resolver. resolve_str_path_error ( DUMMY_SP , & path, TypeNS , module_id)
323319 } )
@@ -326,18 +322,17 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
326322
327323 match ty_res {
328324 Res :: Def ( DefKind :: Enum , did) => {
329- if cx
330- . tcx
325+ if tcx
331326 . inherent_impls ( did)
332327 . iter ( )
333- . flat_map ( |imp| cx . tcx . associated_items ( * imp) . in_definition_order ( ) )
328+ . flat_map ( |imp| tcx. associated_items ( * imp) . in_definition_order ( ) )
334329 . any ( |item| item. ident . name == variant_name)
335330 {
336331 // This is just to let `fold_item` know that this shouldn't be considered;
337332 // it's a bug for the error to make it to the user
338333 return Err ( ResolutionFailure :: Dummy . into ( ) ) ;
339334 }
340- match cx . tcx . type_of ( did) . kind ( ) {
335+ match tcx. type_of ( did) . kind ( ) {
341336 ty:: Adt ( def, _) if def. is_enum ( ) => {
342337 if def. all_fields ( ) . any ( |item| item. ident . name == variant_field_name) {
343338 Ok ( (
@@ -380,16 +375,16 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
380375 item_name : Symbol ,
381376 item_str : & ' path str ,
382377 ) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
383- let cx = self . cx ;
378+ let tcx = self . cx . tcx ;
384379
385380 prim_ty
386- . impls ( cx . tcx )
381+ . impls ( tcx)
387382 . into_iter ( )
388383 . find_map ( |& impl_| {
389- cx . tcx
384+ tcx
390385 . associated_items ( impl_)
391386 . find_by_name_and_namespace (
392- cx . tcx ,
387+ tcx,
393388 Ident :: with_dummy_span ( item_name) ,
394389 ns,
395390 impl_,
@@ -434,9 +429,8 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
434429 path_str : & ' a str ,
435430 module_id : DefId ,
436431 ) -> Result < Res , ResolutionFailure < ' a > > {
437- let cx = self . cx ;
438432 let path = ast:: Path :: from_ident ( Ident :: from_str ( path_str) ) ;
439- cx. enter_resolver ( |resolver| {
433+ self . cx . enter_resolver ( |resolver| {
440434 // FIXME(jynelson): does this really need 3 separate lookups?
441435 if let Ok ( ( Some ( ext) , res) ) = resolver. resolve_macro_path (
442436 & path,
@@ -498,7 +492,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
498492 module_id : DefId ,
499493 extra_fragment : & Option < String > ,
500494 ) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
501- let cx = self . cx ;
495+ let cx = & self . cx ;
502496
503497 if let Some ( res) = self . resolve_path ( path_str, ns, module_id) {
504498 match res {
@@ -948,12 +942,11 @@ impl LinkCollector<'_, '_> {
948942 return None ;
949943 }
950944
951- let cx = self . cx ;
952945 let link = ori_link. link . replace ( "`" , "" ) ;
953946 let parts = link. split ( '#' ) . collect :: < Vec < _ > > ( ) ;
954947 let ( link, extra_fragment) = if parts. len ( ) > 2 {
955948 // 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 ) ;
957950 return None ;
958951 } else if parts. len ( ) == 2 {
959952 if parts[ 0 ] . trim ( ) . is_empty ( ) {
@@ -1105,7 +1098,7 @@ impl LinkCollector<'_, '_> {
11051098 if matches ! ( disambiguator, Some ( Disambiguator :: Primitive ) ) {
11061099 if fragment. is_some ( ) {
11071100 anchor_failure (
1108- cx,
1101+ self . cx ,
11091102 & item,
11101103 path_str,
11111104 dox,
@@ -1119,7 +1112,7 @@ impl LinkCollector<'_, '_> {
11191112 } else {
11201113 // `[char]` when a `char` module is in scope
11211114 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) ;
11231116 return None ;
11241117 }
11251118 }
@@ -1140,7 +1133,7 @@ impl LinkCollector<'_, '_> {
11401133 suggest_disambiguator ( resolved, diag, path_str, dox, sp, & ori_link. range ) ;
11411134 } ;
11421135 report_diagnostic (
1143- cx,
1136+ self . cx ,
11441137 BROKEN_INTRA_DOC_LINKS ,
11451138 & msg,
11461139 & item,
@@ -1187,7 +1180,7 @@ impl LinkCollector<'_, '_> {
11871180 if self . cx . tcx . privacy_access_levels ( LOCAL_CRATE ) . is_exported ( hir_src)
11881181 && !self . cx . tcx . privacy_access_levels ( LOCAL_CRATE ) . is_exported ( hir_dst)
11891182 {
1190- privacy_error ( cx, & item, & path_str, dox, & ori_link) ;
1183+ privacy_error ( self . cx , & item, & path_str, dox, & ori_link) ;
11911184 }
11921185 }
11931186
@@ -1211,7 +1204,7 @@ impl LinkCollector<'_, '_> {
12111204 && !self . cx . tcx . features ( ) . intra_doc_pointers
12121205 {
12131206 let span = super :: source_span_for_markdown_range (
1214- cx,
1207+ self . cx ,
12151208 dox,
12161209 & ori_link. range ,
12171210 & item. attrs ,
@@ -1243,7 +1236,7 @@ impl LinkCollector<'_, '_> {
12431236 }
12441237 Res :: Def ( kind, id) => {
12451238 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) ) ;
12471240 Some ( ItemLink { link : ori_link. link , link_text, did : Some ( id) , fragment } )
12481241 }
12491242 }
0 commit comments