Skip to content

[E0529] can wrongly suggest as_deref() #165365

Closed

Description

@jendrikw

Code

use std::ffi::FromBytesWithNulError; // or any other enum

fn f(err: Result<(), Vec<FromBytesWithNulError>>) {
    assert!(matches!(err, Err([FromBytesWithNulError::InteriorNul{..}])));
}

Current output

error[E0529]: expected an array or slice, found `Vec<FromBytesWithNulError>`
 --> src/lib.rs:4:31
  |
4 |     assert!(matches!(err, Err([FromBytesWithNulError::InteriorNul{..}])));
  |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern cannot match with input type `Vec<FromBytesWithNulError>`
  |
help: consider using `as_deref` here
  |
4 |     assert!(matches!(err.as_deref(), Err([FromBytesWithNulError::InteriorNul{..}])));
  |                         +++++++++++

Desired output

error[E0529]: expected an array or slice, found `Vec<FromBytesWithNulError>`
 --> src/lib.rs:4:31
  |
4 |     assert!(matches!(err, Err([FromBytesWithNulError::InteriorNul{..}])));
  |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern cannot match with input type `Vec<FromBytesWithNulError>`

Rationale and extra context

When applied, the code doesn't compile because () doesn't implement Deref:

error[E0599]: the method `as_deref` exists for enum `Result<(), Vec<FromBytesWithNulError>>`, but its trait bounds were not satisfied
 --> src/lib.rs:4:26
  |
4 |     assert!(matches!(err.as_deref(), Err([FromBytesWithNulError::InteriorNul{..}])));
  |                          ^^^^^^^^
  |
  = note: the following trait bounds were not satisfied:
          `(): Deref`

Other cases

Rust Version

rustc 1.101.0-nightly (92b5b8c87 2026-10-29)
binary: rustc
commit-hash: 92b5b8c87c61b20adc9001b41baf587634a74734
commit-date: 2026-10-29
host: x86_64-unknown-linux-gnu
release: 1.101.0-nightly
LLVM version: 23.1.4

Anything else?

No response

Activity

  1. added
    A-diagnostics
    T-compiler
    on Nov 2, 2026
  2. added
    D-invalid-suggestion
    on Nov 2, 2026
  3. added 4 commits that reference this issue on Nov 16, 2026
    da78cd7
    c8f2e73
    6dffcd1
    1463c41
  4. added a commit that references this issue on Nov 16, 2026
    76e8776
  5. added a commit that references this issue on Nov 16, 2026
    2b348c1
  6. added a commit that references this issue on Nov 16, 2026
    431b921
  7. added a commit that references this issue on Nov 17, 2026
    aa8593f
  8. added a commit that references this issue on Nov 19, 2026
    7b873ce
  9. added a commit that references this issue on Nov 23, 2026
    1004e20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsD-invalid-suggestionT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions