Closed
Description
The following code compiles successfully:
struct Foo {
val: bool
}
fn main() {
let data = Foo { val: true };
match data {
Foo { #[missing_attr] #[cfg(FALSE)] .. } => {}
}
}
However, placing attributes on a normal field pattern:
struct Foo {
val: bool
}
fn main() {
let data = Foo { val: true };
match data {
Foo { #[missing_attr] #[cfg(FALSE)] val } => {}
}
}
produces the following error:
error[E0027]: pattern does not mention field `val`
--> src/main.rs:8:9
|
8 | Foo { #[missing_attr] #[cfg(FALSE)] val } => {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `val`
|
help: include the missing field in the pattern
|
8 | Foo { val } => {}
| ^^^^^^^
help: if you don't care about this missing field, you can explicitly ignore it
|
8 | Foo { .. } => {}
| ^^^^^^
error: aborting due to previous error
We should either handle attributes consistently across field patterns and ..
patterns, or emit an error when any attributes are present on ..
patterns. This is technically a breaking change, but there's precedent here (we've made misplaced #[inline]
attributes into hard errors).