File tree 5 files changed +53
-0
lines changed
compiler/rustc_metadata/src/rmeta
librustdoc/passes/collect_intra_doc_links
5 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -1369,10 +1369,27 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1369
1369
)
1370
1370
}
1371
1371
1372
+ /// Decodes all inherent impls in the crate (for rustdoc).
1373
+ fn get_inherent_impls ( self ) -> impl Iterator < Item = ( DefId , DefId ) > + ' a {
1374
+ ( 0 ..self . root . tables . inherent_impls . size ( ) ) . flat_map ( move |i| {
1375
+ let ty_index = DefIndex :: from_usize ( i) ;
1376
+ let ty_def_id = self . local_def_id ( ty_index) ;
1377
+ self . root
1378
+ . tables
1379
+ . inherent_impls
1380
+ . get ( self , ty_index)
1381
+ . unwrap_or_else ( Lazy :: empty)
1382
+ . decode ( self )
1383
+ . map ( move |impl_index| ( ty_def_id, self . local_def_id ( impl_index) ) )
1384
+ } )
1385
+ }
1386
+
1387
+ /// Decodes all traits in the crate (for rustdoc and rustc diagnostics).
1372
1388
fn get_traits ( self ) -> impl Iterator < Item = DefId > + ' a {
1373
1389
self . root . traits . decode ( self ) . map ( move |index| self . local_def_id ( index) )
1374
1390
}
1375
1391
1392
+ /// Decodes all trait impls in the crate (for rustdoc).
1376
1393
fn get_trait_impls ( self ) -> impl Iterator < Item = ( DefId , DefId , Option < SimplifiedType > ) > + ' a {
1377
1394
self . cdata . trait_impls . iter ( ) . flat_map ( move |( ( trait_cnum_raw, trait_index) , impls) | {
1378
1395
let trait_def_id = DefId {
Original file line number Diff line number Diff line change @@ -486,16 +486,26 @@ impl CStore {
486
486
self . get_crate_data ( cnum) . get_proc_macro_quoted_span ( id, sess)
487
487
}
488
488
489
+ /// Decodes all traits in the crate (for rustdoc).
489
490
pub fn traits_in_crate_untracked ( & self , cnum : CrateNum ) -> impl Iterator < Item = DefId > + ' _ {
490
491
self . get_crate_data ( cnum) . get_traits ( )
491
492
}
492
493
494
+ /// Decodes all trait impls in the crate (for rustdoc).
493
495
pub fn trait_impls_in_crate_untracked (
494
496
& self ,
495
497
cnum : CrateNum ,
496
498
) -> impl Iterator < Item = ( DefId , DefId , Option < SimplifiedType > ) > + ' _ {
497
499
self . get_crate_data ( cnum) . get_trait_impls ( )
498
500
}
501
+
502
+ /// Decodes all inherent impls in the crate (for rustdoc).
503
+ pub fn inherent_impls_in_crate_untracked (
504
+ & self ,
505
+ cnum : CrateNum ,
506
+ ) -> impl Iterator < Item = ( DefId , DefId ) > + ' _ {
507
+ self . get_crate_data ( cnum) . get_inherent_impls ( )
508
+ }
499
509
}
500
510
501
511
impl CrateStore for CStore {
Original file line number Diff line number Diff line change @@ -116,6 +116,8 @@ impl IntraLinkCrateLoader<'_, '_> {
116
116
let all_traits = Vec :: from_iter ( self . resolver . cstore ( ) . traits_in_crate_untracked ( cnum) ) ;
117
117
let all_trait_impls =
118
118
Vec :: from_iter ( self . resolver . cstore ( ) . trait_impls_in_crate_untracked ( cnum) ) ;
119
+ let all_inherent_impls =
120
+ Vec :: from_iter ( self . resolver . cstore ( ) . inherent_impls_in_crate_untracked ( cnum) ) ;
119
121
120
122
// Querying traits in scope is expensive so we try to prune the impl and traits lists
121
123
// using privacy, private traits and impls from other crates are never documented in
@@ -134,6 +136,11 @@ impl IntraLinkCrateLoader<'_, '_> {
134
136
self . add_traits_in_parent_scope ( impl_def_id) ;
135
137
}
136
138
}
139
+ for ( ty_def_id, impl_def_id) in all_inherent_impls {
140
+ if self . resolver . cstore ( ) . visibility_untracked ( ty_def_id) == Visibility :: Public {
141
+ self . add_traits_in_parent_scope ( impl_def_id) ;
142
+ }
143
+ }
137
144
138
145
self . all_traits . extend ( all_traits) ;
139
146
self . all_trait_impls . extend ( all_trait_impls. into_iter ( ) . map ( |( _, def_id, _) | def_id) ) ;
Original file line number Diff line number Diff line change
1
+ #[ derive( Clone ) ]
2
+ pub struct PublicStruct ;
3
+
4
+ mod inner {
5
+ use super :: PublicStruct ;
6
+
7
+ impl PublicStruct {
8
+ /// [PublicStruct::clone]
9
+ pub fn method ( ) { }
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ // Reexport of a structure with public inherent impls having doc links in their comments. The doc
2
+ // link points to an associated item, so we check that traits in scope for that link are populated.
3
+
4
+ // aux-build:extern-inherent-impl-dep.rs
5
+
6
+ extern crate extern_inherent_impl_dep;
7
+
8
+ pub use extern_inherent_impl_dep:: PublicStruct ;
You can’t perform that action at this time.
0 commit comments