Skip to content

Unexpected "deprecated" warning when derive attribute for enum and enum has deprecated items #38832

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

Closed
Mingun opened this issue Jan 4, 2017 · 3 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@Mingun
Copy link

Mingun commented Jan 4, 2017

Let's consider the following situation: there is a enumeration in which have an deprecated element. This enumeration derives implementation of some traits. In such case rustc generates deprecation warning, but actually deprecated item never used.

As in this case there is no control over the generated code, I consider that the warning shouldn't be. It is impossible to suppress warning also because the element is marked deprecated for the reason that he shouldn't be used obviously. If to suppress him, then meaning to mark a enumaration element as deprecated is lost.

Example of problem:

#![allow(dead_code)]
#[derive(Debug)]
enum Example {
    Var1,
    #[deprecated]
    Var2,
}
fn main() {
}

Output:

rustc 1.14.0 (e8a012324 2016-12-16)
warning: use of deprecated item, #[warn(deprecated)] on by default
 --> <anon>:6:5
  |
6 |     Var2,
  |     ^^^^

play-pen

@RReverser
Copy link
Contributor

Not disagreeing that this should likely be the default behavior, but just a suggestion - for now you can use following workaround by allowing deprecated items on enum itself:

#![allow(dead_code)]

#[derive(Debug)]
#[allow(deprecated)]
enum Example {
    Var1,
    #[deprecated]
    Var2,
}

fn main() {
}

In that case compiler won't warn on declaration itself, but will warn on any usages of Example::Var2 as expected.

@Mark-Simulacrum Mark-Simulacrum added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label May 19, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@Mingun
Copy link
Author

Mingun commented Jan 6, 2019

I think that the solution proposed by @RReverser is enough for a solution and if the Rust team agrees with it, then this issue can be closed

@da-x
Copy link
Member

da-x commented Oct 11, 2019

This can be closed - in the playpen the original issue does not reproduce with stable.

@Mingun Mingun closed this as completed Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants