Tweak diagnostics

- Tweak lint message
- Display multi-segment paths correctly
This commit is contained in:
Camelid 2021-03-14 14:00:02 -07:00
parent 13884dc2af
commit 13076f90d2
5 changed files with 25 additions and 22 deletions

View File

@ -597,11 +597,14 @@ impl CheckAttrVisitor<'tcx> {
hir_id,
i_meta.span,
|lint| {
lint.build(&format!(
"unknown `doc` attribute `{}`",
i_meta.name_or_empty()
))
.emit();
let msg = if let Ok(snippet) =
self.tcx.sess.source_map().span_to_snippet(i_meta.path.span)
{
format!("unknown `doc` attribute `{}`", snippet,)
} else {
String::from("unknown `doc` attribute")
};
lint.build(&msg).emit();
},
);
is_valid = false;
@ -613,7 +616,7 @@ impl CheckAttrVisitor<'tcx> {
hir_id,
meta.span(),
|lint| {
lint.build(&format!("unknown `doc` attribute")).emit();
lint.build(&format!("invalid `doc` attribute")).emit();
},
);
is_valid = false;

View File

@ -10,12 +10,12 @@
pub fn foo() {}
#[doc(123)]
//~^ ERROR unknown `doc` attribute
//~^ ERROR invalid `doc` attribute
//~| WARN
#[doc("hello", "bar")]
//~^ ERROR unknown `doc` attribute
//~^ ERROR invalid `doc` attribute
//~| WARN
//~| ERROR unknown `doc` attribute
//~| ERROR invalid `doc` attribute
//~| WARN
#[doc(foo::bar, crate::bar::baz = "bye")]
//~^ ERROR unknown `doc` attribute

View File

@ -13,7 +13,7 @@ LL | #![deny(warnings)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: unknown `doc` attribute
error: invalid `doc` attribute
--> $DIR/doc-attr.rs:12:7
|
LL | #[doc(123)]
@ -22,7 +22,7 @@ LL | #[doc(123)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: unknown `doc` attribute
error: invalid `doc` attribute
--> $DIR/doc-attr.rs:15:7
|
LL | #[doc("hello", "bar")]
@ -31,7 +31,7 @@ LL | #[doc("hello", "bar")]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: unknown `doc` attribute
error: invalid `doc` attribute
--> $DIR/doc-attr.rs:15:16
|
LL | #[doc("hello", "bar")]
@ -40,7 +40,7 @@ LL | #[doc("hello", "bar")]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: unknown `doc` attribute ``
error: unknown `doc` attribute `foo::bar`
--> $DIR/doc-attr.rs:20:7
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
@ -49,7 +49,7 @@ LL | #[doc(foo::bar, crate::bar::baz = "bye")]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: unknown `doc` attribute ``
error: unknown `doc` attribute `crate::bar::baz`
--> $DIR/doc-attr.rs:20:17
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]

View File

@ -10,12 +10,12 @@
pub fn foo() {}
#[doc(123)]
//~^ ERROR unknown `doc` attribute
//~^ ERROR invalid `doc` attribute
//~| WARN
#[doc("hello", "bar")]
//~^ ERROR unknown `doc` attribute
//~^ ERROR invalid `doc` attribute
//~| WARN
//~| ERROR unknown `doc` attribute
//~| ERROR invalid `doc` attribute
//~| WARN
#[doc(foo::bar, crate::bar::baz = "bye")]
//~^ ERROR unknown `doc` attribute

View File

@ -13,7 +13,7 @@ LL | #![deny(warnings)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: unknown `doc` attribute
error: invalid `doc` attribute
--> $DIR/doc-attr.rs:12:7
|
LL | #[doc(123)]
@ -22,7 +22,7 @@ LL | #[doc(123)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: unknown `doc` attribute
error: invalid `doc` attribute
--> $DIR/doc-attr.rs:15:7
|
LL | #[doc("hello", "bar")]
@ -31,7 +31,7 @@ LL | #[doc("hello", "bar")]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: unknown `doc` attribute
error: invalid `doc` attribute
--> $DIR/doc-attr.rs:15:16
|
LL | #[doc("hello", "bar")]
@ -40,7 +40,7 @@ LL | #[doc("hello", "bar")]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: unknown `doc` attribute ``
error: unknown `doc` attribute `foo::bar`
--> $DIR/doc-attr.rs:20:7
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
@ -49,7 +49,7 @@ LL | #[doc(foo::bar, crate::bar::baz = "bye")]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: unknown `doc` attribute ``
error: unknown `doc` attribute `crate::bar::baz`
--> $DIR/doc-attr.rs:20:17
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]