Skip to content

Destructuring of foreign non_exhaustive structs with .. wildcard #1

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,15 @@ The variants of `enum`s all have the same visibility as the `enum` itself.

The section should mention [`non_exhaustive`.](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute)

You can't destructure or use [struct update syntax](https://doc.rust-lang.org/reference/expressions/struct-expr.html#functional-update-syntax)
with types that have fields you can't name or foreign types that are `non_exhaustive`.
You can't use [struct update syntax](https://doc.rust-lang.org/reference/expressions/struct-expr.html#functional-update-syntax) with types that have fields you can't name or foreign types that are `non_exhaustive`, and you can only destructure a foreign `non_exhaustive` struct using the `..` wildcard:

```rust
// with bar::Bar being a foreign `non_exhaustive` struct with a single field `x`
let b = bar::Bar::new(5);
//let bar::Bar { x } = b; // no wildcard: won't work
let bar::Bar { x, .. } = b;
println!("{x}");
```

Hmm, do they cover SUS anywhere? I don't think they do. The general idea is that here:
```rust
Expand Down