Closed
Description
Code
pub struct Struct {
a: Vec<Struct>,
}
impl Struct {
pub fn test(&self) {
if let [Struct { a: [] }] = &self.a[..] {
println!("matches!")
}
}
}
Current output
error[E0529]: expected an array or slice, found `Vec<Struct>`
--> src/main.rs:47:29
|
47 | if let [Struct { a: [] }] = &self.a[..] {
| ^^ ----------- help: consider slicing here: `&self.a[..][..]`
| |
| pattern cannot match with input type `Vec<Struct>`
Desired output
error[E0529]: expected an array or slice, found `Vec<Struct>`
--> src/main.rs:47:29
|
47 | if let [Struct { a: [] }] = &self.a[..] {
| ^^
| |
| pattern cannot match with input type `Vec<Struct>`
Rationale and extra context
The suggestion to try &self.a[..][..]
does not work, and should not be included. If you do try to follow this suggestion, the error then suggests &self.a[..][..][..]
, then &self.a[..][..][..][..]
, and so on.
Other cases
No response
Rust Version
rustc 1.77.0-nightly (88189a71e 2024-01-19)
binary: rustc
commit-hash: 88189a71e4e4376eea82ac61db6a539612eb200a
commit-date: 2024-01-19
host: aarch64-apple-darwin
release: 1.77.0-nightly
LLVM version: 17.0.6
(Also repros on latest nightly using the Playground)
Anything else?
No response