-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language team
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).
Metadata
Metadata
Assignees
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language team