@@ -484,21 +484,23 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
484
484
/// Resolves a string as a path within a particular namespace. Returns an
485
485
/// optional URL fragment in the case of variants and methods.
486
486
fn resolve < ' path > (
487
- & self ,
487
+ & mut self ,
488
488
path_str : & ' path str ,
489
489
ns : Namespace ,
490
490
module_id : DefId ,
491
491
extra_fragment : & Option < String > ,
492
492
) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
493
- let cx = & self . cx ;
493
+ let tcx = self . cx . tcx ;
494
494
495
495
if let Some ( res) = self . resolve_path ( path_str, ns, module_id) {
496
496
match res {
497
497
// FIXME(#76467): make this fallthrough to lookup the associated
498
498
// item a separate function.
499
499
Res :: Def ( DefKind :: AssocFn | DefKind :: AssocConst , _) => assert_eq ! ( ns, ValueNS ) ,
500
500
Res :: Def ( DefKind :: AssocTy , _) => assert_eq ! ( ns, TypeNS ) ,
501
- Res :: Def ( DefKind :: Variant , _) => return handle_variant ( cx, res, extra_fragment) ,
501
+ Res :: Def ( DefKind :: Variant , _) => {
502
+ return handle_variant ( self . cx , res, extra_fragment) ;
503
+ }
502
504
// Not a trait item; just return what we found.
503
505
Res :: Primitive ( ty) => {
504
506
if extra_fragment. is_some ( ) {
@@ -565,13 +567,12 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
565
567
) => {
566
568
debug ! ( "looking for associated item named {} for item {:?}" , item_name, did) ;
567
569
// Checks if item_name belongs to `impl SomeItem`
568
- let assoc_item = cx
569
- . tcx
570
+ let assoc_item = tcx
570
571
. inherent_impls ( did)
571
572
. iter ( )
572
573
. flat_map ( |& imp| {
573
- cx . tcx . associated_items ( imp) . find_by_name_and_namespace (
574
- cx . tcx ,
574
+ tcx. associated_items ( imp) . find_by_name_and_namespace (
575
+ tcx,
575
576
Ident :: with_dummy_span ( item_name) ,
576
577
ns,
577
578
imp,
@@ -587,7 +588,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
587
588
// something like [`ambi_fn`](<SomeStruct as SomeTrait>::ambi_fn)
588
589
. or_else ( || {
589
590
let kind =
590
- resolve_associated_trait_item ( did, module_id, item_name, ns, & self . cx ) ;
591
+ resolve_associated_trait_item ( did, module_id, item_name, ns, self . cx ) ;
591
592
debug ! ( "got associated item kind {:?}" , kind) ;
592
593
kind
593
594
} ) ;
@@ -611,7 +612,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
611
612
debug ! ( "looking for variants or fields named {} for {:?}" , item_name, did) ;
612
613
// FIXME(jynelson): why is this different from
613
614
// `variant_field`?
614
- match cx . tcx . type_of ( did) . kind ( ) {
615
+ match tcx. type_of ( did) . kind ( ) {
615
616
ty:: Adt ( def, _) => {
616
617
let field = if def. is_enum ( ) {
617
618
def. all_fields ( ) . find ( |item| item. ident . name == item_name)
@@ -652,10 +653,9 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
652
653
None
653
654
}
654
655
}
655
- Res :: Def ( DefKind :: Trait , did) => cx
656
- . tcx
656
+ Res :: Def ( DefKind :: Trait , did) => tcx
657
657
. associated_items ( did)
658
- . find_by_name_and_namespace ( cx . tcx , Ident :: with_dummy_span ( item_name) , ns, did)
658
+ . find_by_name_and_namespace ( tcx, Ident :: with_dummy_span ( item_name) , ns, did)
659
659
. map ( |item| {
660
660
let kind = match item. kind {
661
661
ty:: AssocKind :: Const => "associatedconstant" ,
@@ -699,7 +699,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
699
699
/// This returns the `Res` even if it was erroneous for some reason
700
700
/// (such as having invalid URL fragments or being in the wrong namespace).
701
701
fn check_full_res (
702
- & self ,
702
+ & mut self ,
703
703
ns : Namespace ,
704
704
path_str : & str ,
705
705
module_id : DefId ,
@@ -733,7 +733,7 @@ fn resolve_associated_trait_item(
733
733
module : DefId ,
734
734
item_name : Symbol ,
735
735
ns : Namespace ,
736
- cx : & DocContext < ' _ > ,
736
+ cx : & mut DocContext < ' _ > ,
737
737
) -> Option < ( ty:: AssocKind , DefId ) > {
738
738
// FIXME: this should also consider blanket impls (`impl<T> X for T`). Unfortunately
739
739
// `get_auto_trait_and_blanket_impls` is broken because the caching behavior is wrong. In the
@@ -758,10 +758,10 @@ fn resolve_associated_trait_item(
758
758
///
759
759
/// NOTE: this cannot be a query because more traits could be available when more crates are compiled!
760
760
/// So it is not stable to serialize cross-crate.
761
- fn traits_implemented_by ( cx : & DocContext < ' _ > , type_ : DefId , module : DefId ) -> FxHashSet < DefId > {
762
- let mut cache = cx. module_trait_cache . borrow_mut ( ) ;
763
- let in_scope_traits = cache . entry ( module) . or_insert_with ( || {
764
- cx . enter_resolver ( |resolver| {
761
+ fn traits_implemented_by ( cx : & mut DocContext < ' _ > , type_ : DefId , module : DefId ) -> FxHashSet < DefId > {
762
+ let mut resolver = cx. resolver . borrow_mut ( ) ;
763
+ let in_scope_traits = cx . module_trait_cache . entry ( module) . or_insert_with ( || {
764
+ resolver . access ( |resolver| {
765
765
let parent_scope = & ParentScope :: module ( resolver. get_module ( module) , resolver) ;
766
766
resolver
767
767
. traits_in_scope ( None , parent_scope, SyntaxContext :: root ( ) , None )
@@ -771,13 +771,14 @@ fn traits_implemented_by(cx: &DocContext<'_>, type_: DefId, module: DefId) -> Fx
771
771
} )
772
772
} ) ;
773
773
774
- let ty = cx. tcx . type_of ( type_) ;
774
+ let tcx = cx. tcx ;
775
+ let ty = tcx. type_of ( type_) ;
775
776
let iter = in_scope_traits. iter ( ) . flat_map ( |& trait_| {
776
777
trace ! ( "considering explicit impl for trait {:?}" , trait_) ;
777
778
778
779
// Look at each trait implementation to see if it's an impl for `did`
779
- cx . tcx . find_map_relevant_impl ( trait_, ty, |impl_| {
780
- let trait_ref = cx . tcx . impl_trait_ref ( impl_) . expect ( "this is not an inherent impl" ) ;
780
+ tcx. find_map_relevant_impl ( trait_, ty, |impl_| {
781
+ let trait_ref = tcx. impl_trait_ref ( impl_) . expect ( "this is not an inherent impl" ) ;
781
782
// Check if these are the same type.
782
783
let impl_type = trait_ref. self_ty ( ) ;
783
784
trace ! (
@@ -1146,7 +1147,7 @@ impl LinkCollector<'_, '_> {
1146
1147
suggest_disambiguator ( resolved, diag, path_str, dox, sp, & ori_link. range ) ;
1147
1148
} ;
1148
1149
report_diagnostic (
1149
- self . cx ,
1150
+ self . cx . tcx ,
1150
1151
BROKEN_INTRA_DOC_LINKS ,
1151
1152
& msg,
1152
1153
& item,
@@ -1220,7 +1221,7 @@ impl LinkCollector<'_, '_> {
1220
1221
&& !self . cx . tcx . features ( ) . intra_doc_pointers
1221
1222
{
1222
1223
let span = super :: source_span_for_markdown_range (
1223
- self . cx ,
1224
+ self . cx . tcx ,
1224
1225
dox,
1225
1226
& ori_link. range ,
1226
1227
& item. attrs ,
@@ -1308,7 +1309,7 @@ impl LinkCollector<'_, '_> {
1308
1309
/// After parsing the disambiguator, resolve the main part of the link.
1309
1310
// FIXME(jynelson): wow this is just so much
1310
1311
fn resolve_with_disambiguator (
1311
- & self ,
1312
+ & mut self ,
1312
1313
key : & ResolutionInfo ,
1313
1314
diag : DiagnosticInfo < ' _ > ,
1314
1315
) -> Option < ( Res , Option < String > ) > {
@@ -1674,15 +1675,15 @@ impl Suggestion {
1674
1675
/// parameter of the callback will contain it, and the primary span of the diagnostic will be set
1675
1676
/// to it.
1676
1677
fn report_diagnostic (
1677
- cx : & DocContext < ' _ > ,
1678
+ tcx : TyCtxt < ' _ > ,
1678
1679
lint : & ' static Lint ,
1679
1680
msg : & str ,
1680
1681
item : & Item ,
1681
1682
dox : & str ,
1682
1683
link_range : & Range < usize > ,
1683
1684
decorate : impl FnOnce ( & mut DiagnosticBuilder < ' _ > , Option < rustc_span:: Span > ) ,
1684
1685
) {
1685
- let hir_id = match cx . as_local_hir_id ( item. def_id ) {
1686
+ let hir_id = match DocContext :: as_local_hir_id ( tcx , item. def_id ) {
1686
1687
Some ( hir_id) => hir_id,
1687
1688
None => {
1688
1689
// If non-local, no need to check anything.
@@ -1694,10 +1695,10 @@ fn report_diagnostic(
1694
1695
let attrs = & item. attrs ;
1695
1696
let sp = span_of_attrs ( attrs) . unwrap_or ( item. source . span ( ) ) ;
1696
1697
1697
- cx . tcx . struct_span_lint_hir ( lint, hir_id, sp, |lint| {
1698
+ tcx. struct_span_lint_hir ( lint, hir_id, sp, |lint| {
1698
1699
let mut diag = lint. build ( msg) ;
1699
1700
1700
- let span = super :: source_span_for_markdown_range ( cx , dox, link_range, attrs) ;
1701
+ let span = super :: source_span_for_markdown_range ( tcx , dox, link_range, attrs) ;
1701
1702
1702
1703
if let Some ( sp) = span {
1703
1704
diag. set_span ( sp) ;
@@ -1732,7 +1733,7 @@ fn report_diagnostic(
1732
1733
/// handled earlier. For example, if passed `Item::Crate(std)` and `path_str`
1733
1734
/// `std::io::Error::x`, this will resolve `std::io::Error`.
1734
1735
fn resolution_failure (
1735
- collector : & LinkCollector < ' _ , ' _ > ,
1736
+ collector : & mut LinkCollector < ' _ , ' _ > ,
1736
1737
item : & Item ,
1737
1738
path_str : & str ,
1738
1739
disambiguator : Option < Disambiguator > ,
@@ -1742,7 +1743,7 @@ fn resolution_failure(
1742
1743
) {
1743
1744
let tcx = collector. cx . tcx ;
1744
1745
report_diagnostic (
1745
- collector . cx ,
1746
+ tcx ,
1746
1747
BROKEN_INTRA_DOC_LINKS ,
1747
1748
& format ! ( "unresolved link to `{}`" , path_str) ,
1748
1749
item,
@@ -1973,7 +1974,7 @@ fn anchor_failure(
1973
1974
) ,
1974
1975
} ;
1975
1976
1976
- report_diagnostic ( cx, BROKEN_INTRA_DOC_LINKS , & msg, item, dox, & link_range, |diag, sp| {
1977
+ report_diagnostic ( cx. tcx , BROKEN_INTRA_DOC_LINKS , & msg, item, dox, & link_range, |diag, sp| {
1977
1978
if let Some ( sp) = sp {
1978
1979
diag. span_label ( sp, "contains invalid anchor" ) ;
1979
1980
}
@@ -2013,7 +2014,7 @@ fn ambiguity_error(
2013
2014
}
2014
2015
}
2015
2016
2016
- report_diagnostic ( cx, BROKEN_INTRA_DOC_LINKS , & msg, item, dox, & link_range, |diag, sp| {
2017
+ report_diagnostic ( cx. tcx , BROKEN_INTRA_DOC_LINKS , & msg, item, dox, & link_range, |diag, sp| {
2017
2018
if let Some ( sp) = sp {
2018
2019
diag. span_label ( sp, "ambiguous link" ) ;
2019
2020
} else {
@@ -2066,7 +2067,7 @@ fn privacy_error(cx: &DocContext<'_>, item: &Item, path_str: &str, dox: &str, li
2066
2067
let msg =
2067
2068
format ! ( "public documentation for `{}` links to private item `{}`" , item_name, path_str) ;
2068
2069
2069
- report_diagnostic ( cx, PRIVATE_INTRA_DOC_LINKS , & msg, item, dox, & link. range , |diag, sp| {
2070
+ report_diagnostic ( cx. tcx , PRIVATE_INTRA_DOC_LINKS , & msg, item, dox, & link. range , |diag, sp| {
2070
2071
if let Some ( sp) = sp {
2071
2072
diag. span_label ( sp, "this item is private" ) ;
2072
2073
}
0 commit comments