-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attributes are silently ignored on ..
in struct pattern
#81282
Comments
..
in struct pattern..
in struct pattern
Technically |
The reference states that |
Actually disregard my comment, it's true that I'd say they should not despite what the reference says. struct S {}
fn main() {
let s = S {};
let z = S { #[nonexistent] ..s }; // error: expected identifier, found `..`
} and we should be able to remove it from patterns too because it's not implemented correctly (the attributes on If someone provides good motivation, then it can always be added in the future. |
I have a use case for this: Allowing exhaustive matching of conceptually non-exhaustive structs, like what syn does for enums: let Foo {
field_a,
field_b,
field_c,
#[cfg(test)]
__test_exhaustive: _,
#[cfg(not(test))]
..
} = foo; or alternatively with the lint suggested in #44109 (comment): let Foo {
field_a,
field_b,
field_c,
// could also be warn(reachable) + `-D warnings` in CI
#[cfg_attr(test, deny(reachable))]
..
} = foo; With that, you have an automated way of being notified (through test failure) when a struct got additional fields without failing compilation entirely, in the second case for anything that's |
@jplatte I believe the |
Heh yes, I'm well aware of it ^^ |
Yeahh, I opted against |
The following code compiles successfully:
However, placing attributes on a normal field pattern:
produces the following 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).The text was updated successfully, but these errors were encountered: