Skip to content

Commit bc20eb6

Browse files
committed
Point to the rustdoc attribute where intralink resolution failed.
1 parent 3575be6 commit bc20eb6

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

src/librustdoc/clean/mod.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -954,12 +954,20 @@ fn type_ns_kind(def: Def, path_str: &str) -> (&'static str, &'static str, String
954954
(kind, article, format!("{}@{}", kind, path_str))
955955
}
956956

957+
fn span_of_attrs(attrs: &Attributes) -> syntax_pos::Span {
958+
if attrs.doc_strings.is_empty() {
959+
return DUMMY_SP;
960+
}
961+
let start = attrs.doc_strings[0].span();
962+
let end = attrs.doc_strings.last().unwrap().span();
963+
start.to(end)
964+
}
965+
957966
fn ambiguity_error(cx: &DocContext, attrs: &Attributes,
958967
path_str: &str,
959968
article1: &str, kind1: &str, disambig1: &str,
960969
article2: &str, kind2: &str, disambig2: &str) {
961-
let sp = attrs.doc_strings.first()
962-
.map_or(DUMMY_SP, |a| a.span());
970+
let sp = span_of_attrs(attrs);
963971
cx.sess()
964972
.struct_span_warn(sp,
965973
&format!("`{}` is both {} {} and {} {}",
@@ -1174,8 +1182,9 @@ enum PathKind {
11741182
Type,
11751183
}
11761184

1177-
fn resolution_failure(cx: &DocContext, path_str: &str) {
1178-
cx.sess().warn(&format!("[{}] cannot be resolved, ignoring it...", path_str));
1185+
fn resolution_failure(cx: &DocContext, attrs: &Attributes, path_str: &str) {
1186+
let sp = span_of_attrs(attrs);
1187+
cx.sess().span_warn(sp, &format!("[{}] cannot be resolved, ignoring it...", path_str));
11791188
}
11801189

11811190
impl Clean<Attributes> for [ast::Attribute] {
@@ -1228,7 +1237,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12281237
if let Ok(def) = resolve(cx, path_str, true) {
12291238
def
12301239
} else {
1231-
resolution_failure(cx, path_str);
1240+
resolution_failure(cx, &attrs, path_str);
12321241
// this could just be a normal link or a broken link
12331242
// we could potentially check if something is
12341243
// "intra-doc-link-like" and warn in that case
@@ -1239,7 +1248,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12391248
if let Ok(def) = resolve(cx, path_str, false) {
12401249
def
12411250
} else {
1242-
resolution_failure(cx, path_str);
1251+
resolution_failure(cx, &attrs, path_str);
12431252
// this could just be a normal link
12441253
continue;
12451254
}
@@ -1284,7 +1293,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12841293
} else if let Ok(value_def) = resolve(cx, path_str, true) {
12851294
value_def
12861295
} else {
1287-
resolution_failure(cx, path_str);
1296+
resolution_failure(cx, &attrs, path_str);
12881297
// this could just be a normal link
12891298
continue;
12901299
}
@@ -1293,7 +1302,7 @@ impl Clean<Attributes> for [ast::Attribute] {
12931302
if let Some(def) = macro_resolve(cx, path_str) {
12941303
(def, None)
12951304
} else {
1296-
resolution_failure(cx, path_str);
1305+
resolution_failure(cx, &attrs, path_str);
12971306
continue
12981307
}
12991308
}

src/test/rustdoc-ui/intra-links-warning.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
// compile-pass
1212

13-
//! Test with [Foo::baz], [Bar::foo], [Uniooon::X]
13+
//! Test with [Foo::baz], [Bar::foo], ...
14+
//!
15+
//! and [Uniooon::X].
1416
1517
pub struct Foo {
1618
pub bar: usize,
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
warning: [Foo::baz] cannot be resolved, ignoring it...
2+
--> $DIR/intra-links-warning.rs:13:1
3+
|
4+
13 | / //! Test with [Foo::baz], [Bar::foo], ...
5+
14 | | //!
6+
15 | | //! and [Uniooon::X].
7+
| |_____________________^
28

39
warning: [Bar::foo] cannot be resolved, ignoring it...
10+
--> $DIR/intra-links-warning.rs:13:1
11+
|
12+
13 | / //! Test with [Foo::baz], [Bar::foo], ...
13+
14 | | //!
14+
15 | | //! and [Uniooon::X].
15+
| |_____________________^
416

517
warning: [Uniooon::X] cannot be resolved, ignoring it...
18+
--> $DIR/intra-links-warning.rs:13:1
19+
|
20+
13 | / //! Test with [Foo::baz], [Bar::foo], ...
21+
14 | | //!
22+
15 | | //! and [Uniooon::X].
23+
| |_____________________^
624

0 commit comments

Comments
 (0)