Skip to content

Deprecation warning not easily avoidable when using elim form of enum with deprecated field #80107

Open
@mcoblenz

Description

The code below warns for the use of the deprecated field:

enum A {
    X{
        #[deprecated(
            since = "0.0.1",
            note = "Don't use this")]
        x: u32
      }
}

fn takeA(a: A) {
    match a {
        A::X{x} => (),
    }
}
warning: use of deprecated field `A::X::x`: Don't use this
  --> src/lib.rs:13:14
   |
13 |         A::X{x} => (),
   |              ^
   |
   = note: `#[warn(deprecated)]` on by default

But I don't see a good way to avoid the warning. I tried matching with A::X{x: _}, but that emits the same warning. If I omit the field entirely, I get an error because the pattern fails to mention field 'x'. If I use A::X{..}, that works, but it applies to all remaining fields, not just x. I want to get an error if, in the future, a new field is added to the enum and I need to consider adding that field to my case.

My suggestion would be to make matching with A::X{x: _} suppress the warning.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-deprecatedLint: deprecatedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions