Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve errors about #[deprecated] attribute #78626

Merged

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Nov 1, 2020

This change:

  1. Turns #[deprecated] on a trait impl block into an error, which fixes Deprecation attribute on trait impl block is accepted but has no effect #78625;
  2. Changes these and other errors about #[deprecated] to use the span of the attribute instead of the item; and
  3. Turns this error into a lint, to make sure it can be capped with --cap-lints and doesn't break any existing dependencies.

Can be reviewed per commit.


Example:

struct X;

#[deprecated = "a"]
impl Default for X {
    #[deprecated = "b"]
    fn default() -> Self {
        X
    }
}

Before:

error: This deprecation annotation is useless
 --> src/main.rs:6:5
  |
6 | /     fn default() -> Self {
7 | |         X
8 | |     }
  | |_____^

After:

error: this `#[deprecated]' annotation has no effect
 --> src/main.rs:3:1
  |
3 | #[deprecated = "a"]
  | ^^^^^^^^^^^^^^^^^^^ help: try removing the deprecation attribute
  |
  = note: `#[deny(useless_deprecated)]` on by default

error: this `#[deprecated]' annotation has no effect
 --> src/main.rs:5:5
  |
5 |     #[deprecated = "b"]
  |     ^^^^^^^^^^^^^^^^^^^ help: try removing the deprecation attribute

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 1, 2020
@m-ou-se m-ou-se added A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. labels Nov 1, 2020
@m-ou-se m-ou-se force-pushed the deprecated-trait-impl branch 2 times, most recently from e87c60d to c2da4fc Compare November 1, 2020 13:11
@bors

This comment has been minimized.

@m-ou-se m-ou-se force-pushed the deprecated-trait-impl branch from c2da4fc to 9fc991a Compare November 1, 2020 19:49
Comment on lines 658 to 659
struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes")
.span_note(*span, "first deprecation attribute here")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this happen multiple times (if you have three deprecation attributes)? If so, reword the label to not make it technically incorrect.

Also, use prefer to use span_label when possible.

Suggested change
struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes")
.span_note(*span, "first deprecation attribute here")
struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes")
.span_label(attr.span, "repeated deprecated attribute")
.span_label(*span, "prior deprecation attribute")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It stops right after the first duplicate, so having three deprecation attributes wouldn't output any more diagnostics than two.

Is there documentation somewhere about all the different options for diagnostics, like span_label, span_suggestion_short, etc.?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/rust-lang/rust/blob/master/compiler/rustc_errors/src/diagnostic.rs has all the methods that can be used and they have good docstrings for the most part.

compiler/rustc_passes/src/stability.rs Outdated Show resolved Hide resolved
compiler/rustc_passes/src/stability.rs Outdated Show resolved Hide resolved
compiler/rustc_passes/src/stability.rs Outdated Show resolved Hide resolved
(From the PR feedback.)

Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
@m-ou-se
Copy link
Member Author

m-ou-se commented Nov 2, 2020

Thanks! Updated.

@estebank
Copy link
Contributor

estebank commented Nov 2, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Nov 2, 2020

📌 Commit 9c647d1 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 2, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Nov 3, 2020
…-trait-impl, r=estebank

Improve errors about #[deprecated] attribute

This change:

1. Turns `#[deprecated]` on a trait impl block into an error, which fixes rust-lang#78625;
2. Changes these and other errors about `#[deprecated]` to use the span of the attribute instead of the item; and
3. Turns this error into a lint, to make sure it can be capped with `--cap-lints` and doesn't break any existing dependencies.

Can be reviewed per commit.

---
Example:
```rust
struct X;

#[deprecated = "a"]
impl Default for X {
    #[deprecated = "b"]
    fn default() -> Self {
        X
    }
}
```

Before:
```
error: This deprecation annotation is useless
 --> src/main.rs:6:5
  |
6 | /     fn default() -> Self {
7 | |         X
8 | |     }
  | |_____^
```

After:
```
error: this `#[deprecated]' annotation has no effect
 --> src/main.rs:3:1
  |
3 | #[deprecated = "a"]
  | ^^^^^^^^^^^^^^^^^^^ help: try removing the deprecation attribute
  |
  = note: `#[deny(useless_deprecated)]` on by default

error: this `#[deprecated]' annotation has no effect
 --> src/main.rs:5:5
  |
5 |     #[deprecated = "b"]
  |     ^^^^^^^^^^^^^^^^^^^ help: try removing the deprecation attribute
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 3, 2020
Rollup of 7 pull requests

Successful merges:

 - rust-lang#77950 (Add support for SHA256 source file hashing)
 - rust-lang#78624 (Sync rustc_codegen_cranelift)
 - rust-lang#78626 (Improve errors about #[deprecated] attribute)
 - rust-lang#78659 (Corrected suggestion for generic parameters in `function_item_references` lint)
 - rust-lang#78687 (Suggest library/std when running all stage 0 tests)
 - rust-lang#78699 (Show more error information in lldb_batchmode)
 - rust-lang#78709 (Fix panic in bootstrap for non-workspace path dependencies.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f011292 into rust-lang:master Nov 3, 2020
@rustbot rustbot added this to the 1.49.0 milestone Nov 3, 2020
kpcyrd added a commit to sodiumoxide/sodiumoxide that referenced this pull request Nov 22, 2020
bors bot added a commit to sodiumoxide/sodiumoxide that referenced this pull request Nov 23, 2020
443: Remove useless deprecation annotation r=kpcyrd a=kpcyrd

This should fix our broken CI.

The change in rustc was caused by rust-lang/rust#78626, further discussion in rust-lang/rust#79304.

Co-authored-by: kpcyrd <git@rxv.cc>
bors bot added a commit to sodiumoxide/sodiumoxide that referenced this pull request Nov 23, 2020
443: Remove useless deprecation annotation r=kpp a=kpcyrd

This should fix our broken CI.

The change in rustc was caused by rust-lang/rust#78626, further discussion in rust-lang/rust#79304.

Co-authored-by: kpcyrd <git@rxv.cc>
klittlepage pushed a commit to klittlepage/sodiumoxide that referenced this pull request Nov 24, 2020
klittlepage pushed a commit to klittlepage/sodiumoxide that referenced this pull request Nov 24, 2020
klittlepage pushed a commit to klittlepage/sodiumoxide that referenced this pull request Nov 24, 2020
klittlepage pushed a commit to klittlepage/sodiumoxide that referenced this pull request Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecation attribute on trait impl block is accepted but has no effect
5 participants