Skip to content

Commit

Permalink
Improve deprecation attribute diagnostic messages.
Browse files Browse the repository at this point in the history
(From the PR feedback.)

Co-authored-by: Esteban Küber <[email protected]>
  • Loading branch information
m-ou-se and estebank committed Nov 2, 2020
1 parent 9fc991a commit 9c647d1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/deprecation/deprecation-sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions src/test/ui/deprecation/deprecation-sanity.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,21 @@ 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
|
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9c647d1

Please sign in to comment.