diff options
| author | Camelid <camelidcamel@gmail.com> | 2021-03-14 14:00:02 -0700 |
|---|---|---|
| committer | Camelid <camelidcamel@gmail.com> | 2021-03-14 14:00:02 -0700 |
| commit | 13076f90d2febedd44d395561b0ec844cac64f8b (patch) | |
| tree | 951f89bbd21411243441fd76362ae3b05e182ee5 | |
| parent | 13884dc2af3d993629eec4a5489dc99bd0a00a71 (diff) | |
| download | rust-13076f90d2febedd44d395561b0ec844cac64f8b.tar.gz rust-13076f90d2febedd44d395561b0ec844cac64f8b.zip | |
Tweak diagnostics
- Tweak lint message - Display multi-segment paths correctly
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 15 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/doc-attr.rs | 6 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/doc-attr.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/attributes/doc-attr.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/attributes/doc-attr.stderr | 10 |
5 files changed, 25 insertions, 22 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index c89518df007..2edc2315f05 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -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; diff --git a/src/test/rustdoc-ui/doc-attr.rs b/src/test/rustdoc-ui/doc-attr.rs index daf73dd023c..980d1c0e207 100644 --- a/src/test/rustdoc-ui/doc-attr.rs +++ b/src/test/rustdoc-ui/doc-attr.rs @@ -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 diff --git a/src/test/rustdoc-ui/doc-attr.stderr b/src/test/rustdoc-ui/doc-attr.stderr index a2831770943..cc2494c92e6 100644 --- a/src/test/rustdoc-ui/doc-attr.stderr +++ b/src/test/rustdoc-ui/doc-attr.stderr @@ -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")] diff --git a/src/test/ui/attributes/doc-attr.rs b/src/test/ui/attributes/doc-attr.rs index daf73dd023c..980d1c0e207 100644 --- a/src/test/ui/attributes/doc-attr.rs +++ b/src/test/ui/attributes/doc-attr.rs @@ -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 diff --git a/src/test/ui/attributes/doc-attr.stderr b/src/test/ui/attributes/doc-attr.stderr index a2831770943..cc2494c92e6 100644 --- a/src/test/ui/attributes/doc-attr.stderr +++ b/src/test/ui/attributes/doc-attr.stderr @@ -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")] |
