Skip to content

unnested_or_patterns demands invalid code #7368

@Licenser

Description

@Licenser

I tried this code:

When writing the following (or similar) code

Err(e @ Error(ErrorKind::Io(_), _) | e @ Error(ErrorKind::NoSocket, _))

clippies unnested_or_patterns lint demands the following change:

error: unnested or-patterns
   --> src/sink/tcp.rs:169:13
    |
169 |             Err(e @ Error(ErrorKind::Io(_), _) | e @ Error(ErrorKind::NoSocket, _)) => {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
help: nest the patterns
    |
169 |             Err(e @ Error(ErrorKind::Io(_) | ErrorKind::NoSocket, _)) => {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This change however isn't valid rust code:

error[E0408]: variable `e` is not bound in all patterns
   --> src/sink/tcp.rs:169:50
    |
169 |             Err(e @ Error(ErrorKind::Io(_), _) | Error(ErrorKind::NoSocket, _)) => {
    |                 - variable not in all patterns   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern doesn't bind `e`

I expected to see this happen: The lint would accept nested pattern where the rust compiler needs them

Instead, this happened: Lint demands invalid code

Meta

  • cargo clippy -V: e.g. clippy 0.1.53 (53cb7b0 2021-06-17)
  • rustc -Vv:

rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-unknown-linux-gnu
release: 1.53.0
LLVM version: 12.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions