@@ -3,7 +3,6 @@ use crate::rmeta::def_path_hash_map::DefPathHashMapRef;
33use crate :: rmeta:: table:: TableBuilder ;
44use crate :: rmeta:: * ;
55
6- use rustc_ast:: util:: comments;
76use rustc_ast:: Attribute ;
87use rustc_data_structures:: fingerprint:: Fingerprint ;
98use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
@@ -772,7 +771,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
772771
773772struct AnalyzeAttrState {
774773 is_exported : bool ,
775- may_have_doc_links : bool ,
776774 is_doc_hidden : bool ,
777775}
778776
@@ -790,15 +788,12 @@ fn analyze_attr(attr: &Attribute, state: &mut AnalyzeAttrState) -> bool {
790788 let mut should_encode = false ;
791789 if rustc_feature:: is_builtin_only_local ( attr. name_or_empty ( ) ) {
792790 // Attributes marked local-only don't need to be encoded for downstream crates.
793- } else if let Some ( s ) = attr. doc_str ( ) {
791+ } else if attr. doc_str ( ) . is_some ( ) {
794792 // We keep all doc comments reachable to rustdoc because they might be "imported" into
795793 // downstream crates if they use `#[doc(inline)]` to copy an item's documentation into
796794 // their own.
797795 if state. is_exported {
798796 should_encode = true ;
799- if comments:: may_have_doc_links ( s. as_str ( ) ) {
800- state. may_have_doc_links = true ;
801- }
802797 }
803798 } else if attr. has_name ( sym:: doc) {
804799 // If this is a `doc` attribute that doesn't have anything except maybe `inline` (as in
@@ -1139,7 +1134,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11391134 let tcx = self . tcx ;
11401135 let mut state = AnalyzeAttrState {
11411136 is_exported : tcx. effective_visibilities ( ( ) ) . is_exported ( def_id) ,
1142- may_have_doc_links : false ,
11431137 is_doc_hidden : false ,
11441138 } ;
11451139 let attr_iter = tcx
@@ -1151,9 +1145,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11511145 record_array ! ( self . tables. attributes[ def_id. to_def_id( ) ] <- attr_iter) ;
11521146
11531147 let mut attr_flags = AttrFlags :: empty ( ) ;
1154- if state. may_have_doc_links {
1155- attr_flags |= AttrFlags :: MAY_HAVE_DOC_LINKS ;
1156- }
11571148 if state. is_doc_hidden {
11581149 attr_flags |= AttrFlags :: IS_DOC_HIDDEN ;
11591150 }
@@ -1231,6 +1222,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12311222 def_id. index
12321223 } ) ) ;
12331224 }
1225+
1226+ for ( def_id, res_map) in & tcx. resolutions ( ( ) ) . doc_link_resolutions {
1227+ record ! ( self . tables. doc_link_resolutions[ def_id. to_def_id( ) ] <- res_map) ;
1228+ }
1229+
1230+ for ( def_id, traits) in & tcx. resolutions ( ( ) ) . doc_link_traits_in_scope {
1231+ record_array ! ( self . tables. doc_link_traits_in_scope[ def_id. to_def_id( ) ] <- traits) ;
1232+ }
12341233 }
12351234
12361235 #[ instrument( level = "trace" , skip( self ) ) ]
@@ -1715,6 +1714,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17151714 record ! ( self . tables. lookup_stability[ LOCAL_CRATE . as_def_id( ) ] <- stability) ;
17161715 }
17171716 self . encode_deprecation ( LOCAL_CRATE . as_def_id ( ) ) ;
1717+ if let Some ( res_map) = tcx. resolutions ( ( ) ) . doc_link_resolutions . get ( & CRATE_DEF_ID ) {
1718+ record ! ( self . tables. doc_link_resolutions[ LOCAL_CRATE . as_def_id( ) ] <- res_map) ;
1719+ }
1720+ if let Some ( traits) = tcx. resolutions ( ( ) ) . doc_link_traits_in_scope . get ( & CRATE_DEF_ID ) {
1721+ record_array ! ( self . tables. doc_link_traits_in_scope[ LOCAL_CRATE . as_def_id( ) ] <- traits) ;
1722+ }
17181723
17191724 // Normally, this information is encoded when we walk the items
17201725 // defined in this crate. However, we skip doing that for proc-macro crates,
@@ -2225,6 +2230,18 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
22252230
22262231pub fn provide ( providers : & mut Providers ) {
22272232 * providers = Providers {
2233+ doc_link_resolutions : |tcx, def_id| {
2234+ tcx. resolutions ( ( ) )
2235+ . doc_link_resolutions
2236+ . get ( & def_id. expect_local ( ) )
2237+ . expect ( "no resolutions for a doc link" )
2238+ } ,
2239+ doc_link_traits_in_scope : |tcx, def_id| {
2240+ tcx. resolutions ( ( ) )
2241+ . doc_link_traits_in_scope
2242+ . get ( & def_id. expect_local ( ) )
2243+ . expect ( "no traits in scope for a doc link" )
2244+ } ,
22282245 traits_in_crate : |tcx, cnum| {
22292246 assert_eq ! ( cnum, LOCAL_CRATE ) ;
22302247
0 commit comments