Skip to content

Commit

Permalink
Future-proof against loose bounds if default variant is non-exhaustive.
Browse files Browse the repository at this point in the history
Co-Authored-By: Mark Rousskov <mark.simulacrum@gmail.com>
  • Loading branch information
danielhenrymantilla and Mark-Simulacrum committed Sep 15, 2022
1 parent 975e72f commit 3d4980b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/test/ui/macros/macros-nonfatal-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,24 @@ fn main() {

trace_macros!(invalid); //~ ERROR
}

/// Check that `#[derive(Default)]` does use a `T : Default` bound when the
/// `#[default]` variant is `#[non_exhaustive]` (should this end up allowed).
const _: () = {
#[derive(Default)]
enum NonExhaustiveDefaultGeneric<T> {
#[default]
#[non_exhaustive]
Foo, //~ ERROR default variant must be exhaustive
Bar(T),
}

fn assert_impls_default<T: Default>() {}

enum NotDefault {}

// Note: the `derive(Default)` currently bails early enough for trait-checking
// not to happen. Should it bail late enough, or even pass, make sure to
// assert that the following line fails.
let _ = assert_impls_default::<NonExhaustiveDefaultGeneric<NotDefault>>;
};
12 changes: 11 additions & 1 deletion src/test/ui/macros/macros-nonfatal-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,21 @@ error: trace_macros! accepts only `true` or `false`
LL | trace_macros!(invalid);
| ^^^^^^^^^^^^^^^^^^^^^^

error: default variant must be exhaustive
--> $DIR/macros-nonfatal-errors.rs:127:9
|
LL | #[non_exhaustive]
| ----------------- declared `#[non_exhaustive]` here
LL | Foo,
| ^^^
|
= help: consider a manual implementation of `Default`

error: cannot find macro `llvm_asm` in this scope
--> $DIR/macros-nonfatal-errors.rs:99:5
|
LL | llvm_asm!(invalid);
| ^^^^^^^^

error: aborting due to 27 previous errors
error: aborting due to 28 previous errors

0 comments on commit 3d4980b

Please sign in to comment.