diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1c1ba208678ed..e24c1a23b89b0 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1191,30 +1191,60 @@ fn resolution_failure( link_range: Option>, ) { let sp = span_of_attrs(attrs); - let mut diag = cx.sess() - .struct_span_warn(sp, &format!("[{}] cannot be resolved, ignoring it...", path_str)); + let msg = format!("`[{}]` cannot be resolved, ignoring it...", path_str); - if let Some(link_range) = link_range { + let code_dox = sp.to_src(cx); + + let doc_comment_padding = 3; + let mut diag = if let Some(link_range) = link_range { // blah blah blah\nblah\nblah [blah] blah blah\nblah blah // ^ ~~~~~~ // | link_range // last_new_line_offset - let last_new_line_offset = dox[..link_range.start].rfind('\n').map_or(0, |n| n + 1); - let line = dox[last_new_line_offset..].lines().next().unwrap_or(""); - - // Print the line containing the `link_range` and manually mark it with '^'s - diag.note(&format!( - "the link appears in this line:\n\n{line}\n{indicator: { + #[doc = $f] + pub fn f() {} + } +} +f!("Foo\nbar [BarF] bar\nbaz"); diff --git a/src/test/rustdoc-ui/intra-links-warning.stderr b/src/test/rustdoc-ui/intra-links-warning.stderr index 1e8e9f04c26ac..52adba5679fe0 100644 --- a/src/test/rustdoc-ui/intra-links-warning.stderr +++ b/src/test/rustdoc-ui/intra-links-warning.stderr @@ -1,39 +1,105 @@ -warning: [Foo::baz] cannot be resolved, ignoring it... - --> $DIR/intra-links-warning.rs:13:1 +warning: `[Foo::baz]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:13:23 | -13 | / //! Test with [Foo::baz], [Bar::foo], ... -14 | | //! -15 | | //! and [Uniooon::X]. - | |_____________________^ +13 | //! Test with [Foo::baz], [Bar::foo], ... + | ^^^^^^^^ cannot be resolved, ignoring + +warning: `[Bar::foo]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:13:35 + | +13 | //! Test with [Foo::baz], [Bar::foo], ... + | ^^^^^^^^ cannot be resolved, ignoring + +warning: `[Uniooon::X]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:14:13 + | +14 | //! , [Uniooon::X] and [Qux::Z]. + | ^^^^^^^^^^ cannot be resolved, ignoring + +warning: `[Qux::Z]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:14:30 + | +14 | //! , [Uniooon::X] and [Qux::Z]. + | ^^^^^^ cannot be resolved, ignoring + +warning: `[Uniooon::X]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:16:14 + | +16 | //! , [Uniooon::X] and [Qux::Z]. + | ^^^^^^^^^^ cannot be resolved, ignoring + +warning: `[Qux::Z]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:16:31 + | +16 | //! , [Uniooon::X] and [Qux::Z]. + | ^^^^^^ cannot be resolved, ignoring + +warning: `[Qux:Y]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:18:13 + | +18 | /// [Qux:Y] + | ^^^^^ cannot be resolved, ignoring + +warning: `[BarA]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:24:10 + | +24 | /// bar [BarA] bar + | ^^^^ cannot be resolved, ignoring + +warning: `[BarB]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:28:1 + | +28 | / /** +29 | | * Foo +30 | | * bar [BarB] bar +31 | | * baz +32 | | */ + | |___^ + | + = note: the link appears in this line: + + bar [BarB] bar + ^^^^ + +warning: `[BarC]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:35:1 + | +35 | / /** Foo +36 | | +37 | | bar [BarC] bar +38 | | baz +... | +44 | | +45 | | */ + | |__^ | = note: the link appears in this line: - Test with [Foo::baz], [Bar::foo], ... - ^^^^^^^^ + bar [BarC] bar + ^^^^ -warning: [Bar::foo] cannot be resolved, ignoring it... - --> $DIR/intra-links-warning.rs:13:1 +warning: `[BarD]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:48:1 | -13 | / //! Test with [Foo::baz], [Bar::foo], ... -14 | | //! -15 | | //! and [Uniooon::X]. - | |_____________________^ +48 | #[doc = "Foo/nbar [BarD] bar/nbaz"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the link appears in this line: - Test with [Foo::baz], [Bar::foo], ... - ^^^^^^^^ + bar [BarD] bar + ^^^^ -warning: [Uniooon::X] cannot be resolved, ignoring it... - --> $DIR/intra-links-warning.rs:13:1 +warning: `[BarF]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:53:9 | -13 | / //! Test with [Foo::baz], [Bar::foo], ... -14 | | //! -15 | | //! and [Uniooon::X]. - | |_____________________^ +53 | #[doc = $f] + | ^^^^^^^^^^^ +... +57 | f!("Foo/nbar [BarF] bar/nbaz"); + | ------------------------------- in this macro invocation | = note: the link appears in this line: - and [Uniooon::X]. - ^^^^^^^^^^ + bar [BarF] bar + ^^^^