diff options
| author | kennytm <kennytm@gmail.com> | 2018-05-28 01:46:59 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-06-03 15:51:31 +0800 |
| commit | bc20eb6fbc1109462147fbd5d0680b6015f71e94 (patch) | |
| tree | 5730e0bdb51c32d45574435cc0222683aedf4420 /src | |
| parent | 3575be60eab140e69e5a75fe5c3b4119c2a17179 (diff) | |
| download | rust-bc20eb6fbc1109462147fbd5d0680b6015f71e94.tar.gz rust-bc20eb6fbc1109462147fbd5d0680b6015f71e94.zip | |
Point to the rustdoc attribute where intralink resolution failed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 25 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/intra-links-warning.rs | 4 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/intra-links-warning.stderr | 18 |
3 files changed, 38 insertions, 9 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a57f3a42939..7c3df329bb7 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -954,12 +954,20 @@ fn type_ns_kind(def: Def, path_str: &str) -> (&'static str, &'static str, String (kind, article, format!("{}@{}", kind, path_str)) } +fn span_of_attrs(attrs: &Attributes) -> syntax_pos::Span { + if attrs.doc_strings.is_empty() { + return DUMMY_SP; + } + let start = attrs.doc_strings[0].span(); + let end = attrs.doc_strings.last().unwrap().span(); + start.to(end) +} + fn ambiguity_error(cx: &DocContext, attrs: &Attributes, path_str: &str, article1: &str, kind1: &str, disambig1: &str, article2: &str, kind2: &str, disambig2: &str) { - let sp = attrs.doc_strings.first() - .map_or(DUMMY_SP, |a| a.span()); + let sp = span_of_attrs(attrs); cx.sess() .struct_span_warn(sp, &format!("`{}` is both {} {} and {} {}", @@ -1174,8 +1182,9 @@ enum PathKind { Type, } -fn resolution_failure(cx: &DocContext, path_str: &str) { - cx.sess().warn(&format!("[{}] cannot be resolved, ignoring it...", path_str)); +fn resolution_failure(cx: &DocContext, attrs: &Attributes, path_str: &str) { + let sp = span_of_attrs(attrs); + cx.sess().span_warn(sp, &format!("[{}] cannot be resolved, ignoring it...", path_str)); } impl Clean<Attributes> for [ast::Attribute] { @@ -1228,7 +1237,7 @@ impl Clean<Attributes> for [ast::Attribute] { if let Ok(def) = resolve(cx, path_str, true) { def } else { - resolution_failure(cx, path_str); + resolution_failure(cx, &attrs, path_str); // this could just be a normal link or a broken link // we could potentially check if something is // "intra-doc-link-like" and warn in that case @@ -1239,7 +1248,7 @@ impl Clean<Attributes> for [ast::Attribute] { if let Ok(def) = resolve(cx, path_str, false) { def } else { - resolution_failure(cx, path_str); + resolution_failure(cx, &attrs, path_str); // this could just be a normal link continue; } @@ -1284,7 +1293,7 @@ impl Clean<Attributes> for [ast::Attribute] { } else if let Ok(value_def) = resolve(cx, path_str, true) { value_def } else { - resolution_failure(cx, path_str); + resolution_failure(cx, &attrs, path_str); // this could just be a normal link continue; } @@ -1293,7 +1302,7 @@ impl Clean<Attributes> for [ast::Attribute] { if let Some(def) = macro_resolve(cx, path_str) { (def, None) } else { - resolution_failure(cx, path_str); + resolution_failure(cx, &attrs, path_str); continue } } diff --git a/src/test/rustdoc-ui/intra-links-warning.rs b/src/test/rustdoc-ui/intra-links-warning.rs index 2a00d31e3d7..830aaabf9d2 100644 --- a/src/test/rustdoc-ui/intra-links-warning.rs +++ b/src/test/rustdoc-ui/intra-links-warning.rs @@ -10,7 +10,9 @@ // compile-pass -//! Test with [Foo::baz], [Bar::foo], [Uniooon::X] +//! Test with [Foo::baz], [Bar::foo], ... +//! +//! and [Uniooon::X]. pub struct Foo { pub bar: usize, diff --git a/src/test/rustdoc-ui/intra-links-warning.stderr b/src/test/rustdoc-ui/intra-links-warning.stderr index 67d7bdd02b3..539ae94c3a9 100644 --- a/src/test/rustdoc-ui/intra-links-warning.stderr +++ b/src/test/rustdoc-ui/intra-links-warning.stderr @@ -1,6 +1,24 @@ warning: [Foo::baz] cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:13:1 + | +13 | / //! Test with [Foo::baz], [Bar::foo], ... +14 | | //! +15 | | //! and [Uniooon::X]. + | |_____________________^ warning: [Bar::foo] cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:13:1 + | +13 | / //! Test with [Foo::baz], [Bar::foo], ... +14 | | //! +15 | | //! and [Uniooon::X]. + | |_____________________^ warning: [Uniooon::X] cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:13:1 + | +13 | / //! Test with [Foo::baz], [Bar::foo], ... +14 | | //! +15 | | //! and [Uniooon::X]. + | |_____________________^ |
