From 9c647d102168f0344bf895aedf96dd52c193aa25 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 2 Nov 2020 13:17:14 +0100 Subject: [PATCH] Improve deprecation attribute diagnostic messages. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (From the PR feedback.) Co-authored-by: Esteban Küber --- compiler/rustc_attr/src/builtin.rs | 3 ++- compiler/rustc_passes/src/stability.rs | 6 +++--- src/test/ui/deprecation/deprecation-sanity.rs | 2 +- src/test/ui/deprecation/deprecation-sanity.stderr | 12 ++++-------- .../stability-attribute-sanity.stderr | 8 ++------ 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 49ac97d833f9..2fd625c2a6c2 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -656,7 +656,8 @@ where if let Some((_, span)) = &depr { struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes") - .span_note(*span, "first deprecation attribute here") + .span_label(attr.span, "repeated deprecation attribute") + .span_label(*span, "first deprecation attribute") .emit(); break; } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index f6923b0dd9c3..04b5c65e464f 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -92,10 +92,10 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited { self.tcx.struct_span_lint_hir(USELESS_DEPRECATED, hir_id, *span, |lint| { - lint.build("this `#[deprecated]' annotation has no effect") - .span_suggestion( + lint.build("this `#[deprecated]` annotation has no effect") + .span_suggestion_short( *span, - "try removing the deprecation attribute", + "remove the unnecessary deprecation attribute", String::new(), rustc_errors::Applicability::MachineApplicable, ) diff --git a/src/test/ui/deprecation/deprecation-sanity.rs b/src/test/ui/deprecation/deprecation-sanity.rs index 5fb3f8195896..4fc3fddadb99 100644 --- a/src/test/ui/deprecation/deprecation-sanity.rs +++ b/src/test/ui/deprecation/deprecation-sanity.rs @@ -32,7 +32,7 @@ fn f1() { } struct X; -#[deprecated = "hello"] //~ ERROR this `#[deprecated]' annotation has no effect +#[deprecated = "hello"] //~ ERROR this `#[deprecated]` annotation has no effect impl Default for X { fn default() -> Self { X diff --git a/src/test/ui/deprecation/deprecation-sanity.stderr b/src/test/ui/deprecation/deprecation-sanity.stderr index b926a6dc09da..7e70c35eeabd 100644 --- a/src/test/ui/deprecation/deprecation-sanity.stderr +++ b/src/test/ui/deprecation/deprecation-sanity.stderr @@ -44,13 +44,9 @@ error[E0550]: multiple deprecated attributes --> $DIR/deprecation-sanity.rs:27:1 | LL | #[deprecated(since = "a", note = "b")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first deprecation attribute here - --> $DIR/deprecation-sanity.rs:26:1 - | + | -------------------------------------- first deprecation attribute LL | #[deprecated(since = "a", note = "b")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ repeated deprecation attribute error[E0538]: multiple 'since' items --> $DIR/deprecation-sanity.rs:30:27 @@ -58,11 +54,11 @@ error[E0538]: multiple 'since' items LL | #[deprecated(since = "a", since = "b", note = "c")] | ^^^^^^^^^^^ -error: this `#[deprecated]' annotation has no effect +error: this `#[deprecated]` annotation has no effect --> $DIR/deprecation-sanity.rs:35:1 | LL | #[deprecated = "hello"] - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the deprecation attribute + | ^^^^^^^^^^^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute | = note: `#[deny(useless_deprecated)]` on by default diff --git a/src/test/ui/stability-attribute/stability-attribute-sanity.stderr b/src/test/ui/stability-attribute/stability-attribute-sanity.stderr index f3edd5773cbb..bf2436a535fd 100644 --- a/src/test/ui/stability-attribute/stability-attribute-sanity.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-sanity.stderr @@ -86,13 +86,9 @@ error[E0550]: multiple deprecated attributes --> $DIR/stability-attribute-sanity.rs:62:1 | LL | #[rustc_deprecated(since = "b", reason = "text")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first deprecation attribute here - --> $DIR/stability-attribute-sanity.rs:61:1 - | + | ------------------------------------------------- first deprecation attribute LL | #[rustc_deprecated(since = "b", reason = "text")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ repeated deprecation attribute error[E0544]: multiple stability levels --> $DIR/stability-attribute-sanity.rs:64:1