Skip to content

Commit 13076f9

Browse files
committed
Tweak diagnostics
- Tweak lint message - Display multi-segment paths correctly
1 parent 13884dc commit 13076f9

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,14 @@ impl CheckAttrVisitor<'tcx> {
597597
hir_id,
598598
i_meta.span,
599599
|lint| {
600-
lint.build(&format!(
601-
"unknown `doc` attribute `{}`",
602-
i_meta.name_or_empty()
603-
))
604-
.emit();
600+
let msg = if let Ok(snippet) =
601+
self.tcx.sess.source_map().span_to_snippet(i_meta.path.span)
602+
{
603+
format!("unknown `doc` attribute `{}`", snippet,)
604+
} else {
605+
String::from("unknown `doc` attribute")
606+
};
607+
lint.build(&msg).emit();
605608
},
606609
);
607610
is_valid = false;
@@ -613,7 +616,7 @@ impl CheckAttrVisitor<'tcx> {
613616
hir_id,
614617
meta.span(),
615618
|lint| {
616-
lint.build(&format!("unknown `doc` attribute")).emit();
619+
lint.build(&format!("invalid `doc` attribute")).emit();
617620
},
618621
);
619622
is_valid = false;

src/test/rustdoc-ui/doc-attr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
pub fn foo() {}
1111

1212
#[doc(123)]
13-
//~^ ERROR unknown `doc` attribute
13+
//~^ ERROR invalid `doc` attribute
1414
//~| WARN
1515
#[doc("hello", "bar")]
16-
//~^ ERROR unknown `doc` attribute
16+
//~^ ERROR invalid `doc` attribute
1717
//~| WARN
18-
//~| ERROR unknown `doc` attribute
18+
//~| ERROR invalid `doc` attribute
1919
//~| WARN
2020
#[doc(foo::bar, crate::bar::baz = "bye")]
2121
//~^ ERROR unknown `doc` attribute

src/test/rustdoc-ui/doc-attr.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | #![deny(warnings)]
1313
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1414
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
1515

16-
error: unknown `doc` attribute
16+
error: invalid `doc` attribute
1717
--> $DIR/doc-attr.rs:12:7
1818
|
1919
LL | #[doc(123)]
@@ -22,7 +22,7 @@ LL | #[doc(123)]
2222
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2323
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
2424

25-
error: unknown `doc` attribute
25+
error: invalid `doc` attribute
2626
--> $DIR/doc-attr.rs:15:7
2727
|
2828
LL | #[doc("hello", "bar")]
@@ -31,7 +31,7 @@ LL | #[doc("hello", "bar")]
3131
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3232
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
3333

34-
error: unknown `doc` attribute
34+
error: invalid `doc` attribute
3535
--> $DIR/doc-attr.rs:15:16
3636
|
3737
LL | #[doc("hello", "bar")]
@@ -40,7 +40,7 @@ LL | #[doc("hello", "bar")]
4040
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4141
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
4242

43-
error: unknown `doc` attribute ``
43+
error: unknown `doc` attribute `foo::bar`
4444
--> $DIR/doc-attr.rs:20:7
4545
|
4646
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
@@ -49,7 +49,7 @@ LL | #[doc(foo::bar, crate::bar::baz = "bye")]
4949
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5050
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
5151

52-
error: unknown `doc` attribute ``
52+
error: unknown `doc` attribute `crate::bar::baz`
5353
--> $DIR/doc-attr.rs:20:17
5454
|
5555
LL | #[doc(foo::bar, crate::bar::baz = "bye")]

src/test/ui/attributes/doc-attr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
pub fn foo() {}
1111

1212
#[doc(123)]
13-
//~^ ERROR unknown `doc` attribute
13+
//~^ ERROR invalid `doc` attribute
1414
//~| WARN
1515
#[doc("hello", "bar")]
16-
//~^ ERROR unknown `doc` attribute
16+
//~^ ERROR invalid `doc` attribute
1717
//~| WARN
18-
//~| ERROR unknown `doc` attribute
18+
//~| ERROR invalid `doc` attribute
1919
//~| WARN
2020
#[doc(foo::bar, crate::bar::baz = "bye")]
2121
//~^ ERROR unknown `doc` attribute

src/test/ui/attributes/doc-attr.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | #![deny(warnings)]
1313
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1414
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
1515

16-
error: unknown `doc` attribute
16+
error: invalid `doc` attribute
1717
--> $DIR/doc-attr.rs:12:7
1818
|
1919
LL | #[doc(123)]
@@ -22,7 +22,7 @@ LL | #[doc(123)]
2222
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2323
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
2424

25-
error: unknown `doc` attribute
25+
error: invalid `doc` attribute
2626
--> $DIR/doc-attr.rs:15:7
2727
|
2828
LL | #[doc("hello", "bar")]
@@ -31,7 +31,7 @@ LL | #[doc("hello", "bar")]
3131
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3232
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
3333

34-
error: unknown `doc` attribute
34+
error: invalid `doc` attribute
3535
--> $DIR/doc-attr.rs:15:16
3636
|
3737
LL | #[doc("hello", "bar")]
@@ -40,7 +40,7 @@ LL | #[doc("hello", "bar")]
4040
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4141
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
4242

43-
error: unknown `doc` attribute ``
43+
error: unknown `doc` attribute `foo::bar`
4444
--> $DIR/doc-attr.rs:20:7
4545
|
4646
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
@@ -49,7 +49,7 @@ LL | #[doc(foo::bar, crate::bar::baz = "bye")]
4949
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5050
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
5151

52-
error: unknown `doc` attribute ``
52+
error: unknown `doc` attribute `crate::bar::baz`
5353
--> $DIR/doc-attr.rs:20:17
5454
|
5555
LL | #[doc(foo::bar, crate::bar::baz = "bye")]

0 commit comments

Comments
 (0)