This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -116,3 +116,24 @@ fn main() {
116116
117117 trace_macros ! ( invalid) ; //~ ERROR
118118}
119+
120+ /// Check that `#[derive(Default)]` does use a `T : Default` bound when the
121+ /// `#[default]` variant is `#[non_exhaustive]` (should this end up allowed).
122+ const _: ( ) = {
123+ #[ derive( Default ) ]
124+ enum NonExhaustiveDefaultGeneric < T > {
125+ #[ default]
126+ #[ non_exhaustive]
127+ Foo , //~ ERROR default variant must be exhaustive
128+ Bar ( T ) ,
129+ }
130+
131+ fn assert_impls_default < T : Default > ( ) { }
132+
133+ enum NotDefault { }
134+
135+ // Note: the `derive(Default)` currently bails early enough for trait-checking
136+ // not to happen. Should it bail late enough, or even pass, make sure to
137+ // assert that the following line fails.
138+ let _ = assert_impls_default :: < NonExhaustiveDefaultGeneric < NotDefault > > ;
139+ } ;
Original file line number Diff line number Diff line change @@ -215,11 +215,21 @@ error: trace_macros! accepts only `true` or `false`
215215LL | trace_macros!(invalid);
216216 | ^^^^^^^^^^^^^^^^^^^^^^
217217
218+ error: default variant must be exhaustive
219+ --> $DIR/macros-nonfatal-errors.rs:127:9
220+ |
221+ LL | #[non_exhaustive]
222+ | ----------------- declared `#[non_exhaustive]` here
223+ LL | Foo,
224+ | ^^^
225+ |
226+ = help: consider a manual implementation of `Default`
227+
218228error: cannot find macro `llvm_asm` in this scope
219229 --> $DIR/macros-nonfatal-errors.rs:99:5
220230 |
221231LL | llvm_asm!(invalid);
222232 | ^^^^^^^^
223233
224- error: aborting due to 27 previous errors
234+ error: aborting due to 28 previous errors
225235
You can’t perform that action at this time.
0 commit comments