Skip to content

Commit 3d56889

Browse files
author
Clar Charr
committed
Updated with feedback from FCP.
1 parent 61a4b14 commit 3d56889

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

text/0000-non-exhaustive.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ as well.
278278
# Detailed design
279279

280280
An attribute `#[non_exhaustive]` is added to the language, which will (for now)
281-
fail to compile if it's used on anything other than an enum, struct definition,
282-
or enum variant.
281+
fail to compile if it's used on anything other than an enum or struct
282+
definition, or enum variant.
283283

284284
## Enums
285285

@@ -417,6 +417,10 @@ Then we the only valid way of matching will be:
417417
let Config { 0: width, 1: height, .. } = config;
418418
```
419419

420+
We can think of this as lowering the visibility of the constructor to
421+
`pub(crate)` if it is marked as `pub`, then applying the standard structure
422+
rules.
423+
420424
## Unit structs
421425

422426
Unit structs will work very similarly to tuple structs. Consider this struct:
@@ -433,6 +437,41 @@ match it like:
433437
let Unit { .. } = unit;
434438
```
435439

440+
To users of this crate, this will act exactly as if the struct were defined as:
441+
442+
```
443+
#[non_exhaustive]
444+
pub struct Unit {}
445+
```
446+
447+
## Functional record updates
448+
449+
Functional record updates will operate exactly the same regardless of whether
450+
structs are marked as non-exhaustive or not. For example, given this struct:
451+
452+
```
453+
#[derive(Debug)]
454+
#[non_exhaustive]
455+
pub struct Config {
456+
pub width: u16,
457+
pub height: u16,
458+
pub fullscreen: bool,
459+
}
460+
impl Default for Config {
461+
fn default() -> Config {
462+
Config { width: 640, height: 480, fullscreen: false }
463+
}
464+
}
465+
```
466+
467+
The below code will print `Config { width: 1920, height: 1080, fullscreen:
468+
false }` regardless of which crate is calling it:
469+
470+
```
471+
let c = Config { width: 1920, height: 1080, ..Config::default() };
472+
println!("{:?}", c);
473+
```
474+
436475
## Changes to rustdoc
437476

438477
Right now, the only indicator that rustdoc gives for non-exhaustive enums and

0 commit comments

Comments
 (0)