@@ -249,7 +249,7 @@ pub(crate) struct ResolutionInfo {
249
249
extra_fragment : Option < String > ,
250
250
}
251
251
252
- #[ derive( Clone ) ]
252
+ #[ derive( Clone , Debug ) ]
253
253
pub ( crate ) struct DiagnosticInfo < ' a > {
254
254
item : & ' a Item ,
255
255
dox : & ' a str ,
@@ -259,6 +259,7 @@ pub(crate) struct DiagnosticInfo<'a> {
259
259
260
260
pub ( crate ) struct OwnedDiagnosticInfo {
261
261
item : Item ,
262
+ dox : String ,
262
263
ori_link : String ,
263
264
link_range : MarkdownLinkRange ,
264
265
}
@@ -267,6 +268,7 @@ impl From<DiagnosticInfo<'_>> for OwnedDiagnosticInfo {
267
268
fn from ( f : DiagnosticInfo < ' _ > ) -> Self {
268
269
Self {
269
270
item : f. item . clone ( ) ,
271
+ dox : f. dox . to_string ( ) ,
270
272
ori_link : f. ori_link . to_string ( ) ,
271
273
link_range : f. link_range . clone ( ) ,
272
274
}
@@ -278,7 +280,7 @@ impl OwnedDiagnosticInfo {
278
280
DiagnosticInfo {
279
281
item : & self . item ,
280
282
ori_link : & self . ori_link ,
281
- dox : "" ,
283
+ dox : & self . dox ,
282
284
link_range : self . link_range . clone ( ) ,
283
285
}
284
286
}
@@ -1156,18 +1158,45 @@ impl LinkCollector<'_, '_> {
1156
1158
// Primitive types are always valid.
1157
1159
Res :: Primitive ( _) => true ,
1158
1160
} ) ;
1159
- if info. resolved . len ( ) == 1 {
1160
- let ( res, fragment) = info. resolved . pop ( ) . unwrap ( ) ;
1161
- let diag_info = info. diag_info . into_info ( ) ;
1162
- if let Some ( link) = self . compute_link (
1163
- res,
1164
- fragment,
1165
- path_str,
1166
- info. disambiguator ,
1167
- diag_info,
1168
- & info. link_text ,
1169
- ) {
1170
- self . save_link ( * item_id, link) ;
1161
+ let diag_info = info. diag_info . into_info ( ) ;
1162
+ match info. resolved . len ( ) {
1163
+ 1 => {
1164
+ let ( res, fragment) = info. resolved . pop ( ) . unwrap ( ) ;
1165
+ if let Some ( link) = self . compute_link (
1166
+ res,
1167
+ fragment,
1168
+ path_str,
1169
+ info. disambiguator ,
1170
+ diag_info,
1171
+ & info. link_text ,
1172
+ ) {
1173
+ self . save_link ( * item_id, link) ;
1174
+ }
1175
+ }
1176
+ 0 => {
1177
+ report_diagnostic (
1178
+ self . cx . tcx ,
1179
+ BROKEN_INTRA_DOC_LINKS ,
1180
+ format ! (
1181
+ "all items matching `{path_str}` are either private or doc(hidden)"
1182
+ ) ,
1183
+ & diag_info,
1184
+ |diag, sp, _| {
1185
+ if let Some ( sp) = sp {
1186
+ diag. span_label ( sp, "unresolved link" ) ;
1187
+ } else {
1188
+ diag. note ( "unresolved link" ) ;
1189
+ }
1190
+ } ,
1191
+ ) ;
1192
+ }
1193
+ _ => {
1194
+ let candidates = info
1195
+ . resolved
1196
+ . iter ( )
1197
+ . map ( |( res, _) | ( * res, res. def_id ( self . cx . tcx ) ) )
1198
+ . collect :: < Vec < _ > > ( ) ;
1199
+ ambiguity_error ( self . cx , & diag_info, path_str, & candidates, true ) ;
1171
1200
}
1172
1201
}
1173
1202
}
0 commit comments