Make the match
in emit_diagnostic
complete.
This match is complex enough that it's a good idea to enumerate every variant. This also means `can_be_top_or_sub` can just be `can_be_subdiag`.
This commit is contained in:
parent
a7d926265f
commit
7ef605be3f
2 changed files with 24 additions and 19 deletions
|
@ -2104,7 +2104,7 @@ impl HumanEmitter {
|
||||||
}
|
}
|
||||||
if !self.short_message {
|
if !self.short_message {
|
||||||
for child in children {
|
for child in children {
|
||||||
assert!(child.level.can_be_top_or_sub().1);
|
assert!(child.level.can_be_subdiag());
|
||||||
let span = &child.span;
|
let span = &child.span;
|
||||||
if let Err(err) = self.emit_messages_default_inner(
|
if let Err(err) = self.emit_messages_default_inner(
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -1354,8 +1354,6 @@ impl DiagCtxtInner {
|
||||||
|
|
||||||
// Return value is only `Some` if the level is `Error` or `DelayedBug`.
|
// Return value is only `Some` if the level is `Error` or `DelayedBug`.
|
||||||
fn emit_diagnostic(&mut self, mut diagnostic: DiagInner) -> Option<ErrorGuaranteed> {
|
fn emit_diagnostic(&mut self, mut diagnostic: DiagInner) -> Option<ErrorGuaranteed> {
|
||||||
assert!(diagnostic.level.can_be_top_or_sub().0);
|
|
||||||
|
|
||||||
if diagnostic.has_future_breakage() {
|
if diagnostic.has_future_breakage() {
|
||||||
// Future breakages aren't emitted if they're Level::Allow,
|
// Future breakages aren't emitted if they're Level::Allow,
|
||||||
// but they still need to be constructed and stashed below,
|
// but they still need to be constructed and stashed below,
|
||||||
|
@ -1368,10 +1366,13 @@ impl DiagCtxtInner {
|
||||||
// return early *and* have some kind of side-effect, except where
|
// return early *and* have some kind of side-effect, except where
|
||||||
// noted.
|
// noted.
|
||||||
match diagnostic.level {
|
match diagnostic.level {
|
||||||
Fatal | Error if self.treat_next_err_as_bug() => {
|
Bug => {}
|
||||||
|
Fatal | Error => {
|
||||||
|
if self.treat_next_err_as_bug() {
|
||||||
// `Fatal` and `Error` can be promoted to `Bug`.
|
// `Fatal` and `Error` can be promoted to `Bug`.
|
||||||
diagnostic.level = Bug;
|
diagnostic.level = Bug;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
DelayedBug => {
|
DelayedBug => {
|
||||||
// Note that because we check these conditions first,
|
// Note that because we check these conditions first,
|
||||||
// `-Zeagerly-emit-delayed-bugs` and `-Ztreat-err-as-bug`
|
// `-Zeagerly-emit-delayed-bugs` and `-Ztreat-err-as-bug`
|
||||||
|
@ -1405,14 +1406,21 @@ impl DiagCtxtInner {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Warning if !self.flags.can_emit_warnings => {
|
ForceWarning(None) => {} // `ForceWarning(Some(...))` is below, with `Expect`
|
||||||
|
Warning => {
|
||||||
|
if !self.flags.can_emit_warnings {
|
||||||
|
// We are not emitting warnings.
|
||||||
if diagnostic.has_future_breakage() {
|
if diagnostic.has_future_breakage() {
|
||||||
// The side-effect is at the top of this method.
|
// The side-effect is at the top of this method.
|
||||||
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
|
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Note | Help | FailureNote => {}
|
||||||
|
OnceNote | OnceHelp => panic!("bad level: {:?}", diagnostic.level),
|
||||||
Allow => {
|
Allow => {
|
||||||
|
// Nothing emitted for allowed lints.
|
||||||
if diagnostic.has_future_breakage() {
|
if diagnostic.has_future_breakage() {
|
||||||
// The side-effect is at the top of this method.
|
// The side-effect is at the top of this method.
|
||||||
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
|
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
|
||||||
|
@ -1434,12 +1442,12 @@ impl DiagCtxtInner {
|
||||||
}
|
}
|
||||||
self.fulfilled_expectations.insert(expect_id.normalize());
|
self.fulfilled_expectations.insert(expect_id.normalize());
|
||||||
if let Expect(_) = diagnostic.level {
|
if let Expect(_) = diagnostic.level {
|
||||||
|
// Nothing emitted here for expected lints.
|
||||||
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
|
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
|
||||||
self.suppressed_expected_diag = true;
|
self.suppressed_expected_diag = true;
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACK_DIAGNOSTIC(diagnostic, &mut |mut diagnostic| {
|
TRACK_DIAGNOSTIC(diagnostic, &mut |mut diagnostic| {
|
||||||
|
@ -1816,16 +1824,13 @@ impl Level {
|
||||||
matches!(*self, FailureNote)
|
matches!(*self, FailureNote)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can this level be used in a top-level diagnostic message and/or a
|
// Can this level be used in a subdiagnostic message?
|
||||||
// subdiagnostic message?
|
fn can_be_subdiag(&self) -> bool {
|
||||||
fn can_be_top_or_sub(&self) -> (bool, bool) {
|
|
||||||
match self {
|
match self {
|
||||||
Bug | DelayedBug | Fatal | Error | ForceWarning(_) | FailureNote | Allow
|
Bug | DelayedBug | Fatal | Error | ForceWarning(_) | FailureNote | Allow
|
||||||
| Expect(_) => (true, false),
|
| Expect(_) => false,
|
||||||
|
|
||||||
Warning | Note | Help => (true, true),
|
Warning | Note | Help | OnceNote | OnceHelp => true,
|
||||||
|
|
||||||
OnceNote | OnceHelp => (false, true),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue