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

Deprecation attribute on trait impl block is accepted but has no effect #78625

Closed
m-ou-se opened this issue Nov 1, 2020 · 0 comments · Fixed by #78626
Closed

Deprecation attribute on trait impl block is accepted but has no effect #78625

m-ou-se opened this issue Nov 1, 2020 · 0 comments · Fixed by #78626
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-papercut Diagnostics: An error or lint that needs small tweaks.

Comments

@m-ou-se
Copy link
Member

m-ou-se commented Nov 1, 2020

The following code is accepted, but the #[deprecated] attribute has no effect:

struct X;

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

(Reported to me by @de-vri-es)

@m-ou-se m-ou-se added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Nov 1, 2020
@m-ou-se m-ou-se self-assigned this Nov 1, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue 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 bors closed this as completed in f011292 Nov 3, 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 C-bug Category: This is a bug. D-papercut Diagnostics: An error or lint that needs small tweaks.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant