suggest using else when '_' is used for exhaustive enums (#16583)

This commit is contained in:
xdBronch
2023-07-28 22:28:55 -04:00
committed by GitHub
parent bde6e075df
commit 2826f78a61
3 changed files with 9 additions and 0 deletions

View File

@@ -10791,6 +10791,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
"'_' prong here",
.{},
);
try sema.errNote(
block,
src,
msg,
"consider using 'else'",
.{},
);
break :msg msg;
};
return sema.failWithOwnedErrorMsg(msg);

View File

@@ -17,3 +17,4 @@ pub export fn entry() void {
//
// :7:5: error: '_' prong only allowed when switching on non-exhaustive enums
// :10:11: note: '_' prong here
// :7:5: note: consider using 'else'

View File

@@ -40,3 +40,4 @@ pub export fn entry3() void {
// :19:5: error: switch on non-exhaustive enum must include 'else' or '_' prong
// :26:5: error: '_' prong only allowed when switching on non-exhaustive enums
// :29:11: note: '_' prong here
// :26:5: note: consider using 'else'