Skip to content

Commit 9c647d1

Browse files
m-ou-seestebank
andcommitted
Improve deprecation attribute diagnostic messages.
(From the PR feedback.) Co-authored-by: Esteban Küber <[email protected]>
1 parent 9fc991a commit 9c647d1

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

compiler/rustc_attr/src/builtin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ where
656656

657657
if let Some((_, span)) = &depr {
658658
struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes")
659-
.span_note(*span, "first deprecation attribute here")
659+
.span_label(attr.span, "repeated deprecation attribute")
660+
.span_label(*span, "first deprecation attribute")
660661
.emit();
661662
break;
662663
}

compiler/rustc_passes/src/stability.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
9292

9393
if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited {
9494
self.tcx.struct_span_lint_hir(USELESS_DEPRECATED, hir_id, *span, |lint| {
95-
lint.build("this `#[deprecated]' annotation has no effect")
96-
.span_suggestion(
95+
lint.build("this `#[deprecated]` annotation has no effect")
96+
.span_suggestion_short(
9797
*span,
98-
"try removing the deprecation attribute",
98+
"remove the unnecessary deprecation attribute",
9999
String::new(),
100100
rustc_errors::Applicability::MachineApplicable,
101101
)

src/test/ui/deprecation/deprecation-sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn f1() { }
3232

3333
struct X;
3434

35-
#[deprecated = "hello"] //~ ERROR this `#[deprecated]' annotation has no effect
35+
#[deprecated = "hello"] //~ ERROR this `#[deprecated]` annotation has no effect
3636
impl Default for X {
3737
fn default() -> Self {
3838
X

src/test/ui/deprecation/deprecation-sanity.stderr

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,21 @@ error[E0550]: multiple deprecated attributes
4444
--> $DIR/deprecation-sanity.rs:27:1
4545
|
4646
LL | #[deprecated(since = "a", note = "b")]
47-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48-
|
49-
note: first deprecation attribute here
50-
--> $DIR/deprecation-sanity.rs:26:1
51-
|
47+
| -------------------------------------- first deprecation attribute
5248
LL | #[deprecated(since = "a", note = "b")]
53-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ repeated deprecation attribute
5450

5551
error[E0538]: multiple 'since' items
5652
--> $DIR/deprecation-sanity.rs:30:27
5753
|
5854
LL | #[deprecated(since = "a", since = "b", note = "c")]
5955
| ^^^^^^^^^^^
6056

61-
error: this `#[deprecated]' annotation has no effect
57+
error: this `#[deprecated]` annotation has no effect
6258
--> $DIR/deprecation-sanity.rs:35:1
6359
|
6460
LL | #[deprecated = "hello"]
65-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the deprecation attribute
61+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute
6662
|
6763
= note: `#[deny(useless_deprecated)]` on by default
6864

src/test/ui/stability-attribute/stability-attribute-sanity.stderr

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,9 @@ error[E0550]: multiple deprecated attributes
8686
--> $DIR/stability-attribute-sanity.rs:62:1
8787
|
8888
LL | #[rustc_deprecated(since = "b", reason = "text")]
89-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
90-
|
91-
note: first deprecation attribute here
92-
--> $DIR/stability-attribute-sanity.rs:61:1
93-
|
89+
| ------------------------------------------------- first deprecation attribute
9490
LL | #[rustc_deprecated(since = "b", reason = "text")]
95-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ repeated deprecation attribute
9692

9793
error[E0544]: multiple stability levels
9894
--> $DIR/stability-attribute-sanity.rs:64:1

0 commit comments

Comments
 (0)