mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Refactor emit_diagnostic
.
- Combine two different blocks involving `diagnostic.level.get_expectation_id()` into one. - Combine several `if`s involving `diagnostic.level` into a single `match`. This requires reordering some of the operations, but this has no functional effect.
This commit is contained in:
parent
5dd0431386
commit
c367386832
@ -1247,24 +1247,41 @@ impl DiagCtxtInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn emit_diagnostic(&mut self, mut diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
|
fn emit_diagnostic(&mut self, mut diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
|
||||||
// The `LintExpectationId` can be stable or unstable depending on when it was created.
|
if let Some(expectation_id) = diagnostic.level.get_expectation_id() {
|
||||||
// Diagnostics created before the definition of `HirId`s are unstable and can not yet
|
// The `LintExpectationId` can be stable or unstable depending on when it was created.
|
||||||
// be stored. Instead, they are buffered until the `LintExpectationId` is replaced by
|
// Diagnostics created before the definition of `HirId`s are unstable and can not yet
|
||||||
// a stable one by the `LintLevelsBuilder`.
|
// be stored. Instead, they are buffered until the `LintExpectationId` is replaced by
|
||||||
if let Some(LintExpectationId::Unstable { .. }) = diagnostic.level.get_expectation_id() {
|
// a stable one by the `LintLevelsBuilder`.
|
||||||
self.unstable_expect_diagnostics.push(diagnostic);
|
if let LintExpectationId::Unstable { .. } = expectation_id {
|
||||||
return None;
|
self.unstable_expect_diagnostics.push(diagnostic);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
self.suppressed_expected_diag = true;
|
||||||
|
self.fulfilled_expectations.insert(expectation_id.normalize());
|
||||||
|
}
|
||||||
|
|
||||||
|
if diagnostic.has_future_breakage() {
|
||||||
|
// Future breakages aren't emitted if they're Level::Allow,
|
||||||
|
// but they still need to be constructed and stashed below,
|
||||||
|
// so they'll trigger the good-path bug check.
|
||||||
|
self.suppressed_expected_diag = true;
|
||||||
|
self.future_breakage_diagnostics.push(diagnostic.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches!(diagnostic.level, DelayedBug(_)) && self.flags.eagerly_emit_delayed_bugs {
|
||||||
|
diagnostic.level = Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(eddyb) this should check for `has_errors` and stop pushing
|
|
||||||
// once *any* errors were emitted (and truncate `span_delayed_bugs`
|
|
||||||
// when an error is first emitted, also), but maybe there's a case
|
|
||||||
// in which that's not sound? otherwise this is really inefficient.
|
|
||||||
match diagnostic.level {
|
match diagnostic.level {
|
||||||
DelayedBug(_) if self.flags.eagerly_emit_delayed_bugs => {
|
// This must come after the possible promotion of `DelayedBug` to `Error` above.
|
||||||
diagnostic.level = Error;
|
Fatal | Error if self.treat_next_err_as_bug() => {
|
||||||
|
diagnostic.level = Bug;
|
||||||
}
|
}
|
||||||
DelayedBug(DelayedBugKind::Normal) => {
|
DelayedBug(DelayedBugKind::Normal) => {
|
||||||
|
// FIXME(eddyb) this should check for `has_errors` and stop pushing
|
||||||
|
// once *any* errors were emitted (and truncate `span_delayed_bugs`
|
||||||
|
// when an error is first emitted, also), but maybe there's a case
|
||||||
|
// in which that's not sound? otherwise this is really inefficient.
|
||||||
let backtrace = std::backtrace::Backtrace::capture();
|
let backtrace = std::backtrace::Backtrace::capture();
|
||||||
self.span_delayed_bugs
|
self.span_delayed_bugs
|
||||||
.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
|
.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
|
||||||
@ -1277,38 +1294,17 @@ impl DiagCtxtInner {
|
|||||||
.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
|
.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
_ => {}
|
Warning if !self.flags.can_emit_warnings => {
|
||||||
}
|
if diagnostic.has_future_breakage() {
|
||||||
|
(*TRACK_DIAGNOSTIC)(diagnostic, &mut |_| {});
|
||||||
// This must come after the possible promotion of `DelayedBug` to
|
}
|
||||||
// `Error` above.
|
return None;
|
||||||
if matches!(diagnostic.level, Error | Fatal) && self.treat_next_err_as_bug() {
|
|
||||||
diagnostic.level = Bug;
|
|
||||||
}
|
|
||||||
|
|
||||||
if diagnostic.has_future_breakage() {
|
|
||||||
// Future breakages aren't emitted if they're Level::Allow,
|
|
||||||
// but they still need to be constructed and stashed below,
|
|
||||||
// so they'll trigger the good-path bug check.
|
|
||||||
self.suppressed_expected_diag = true;
|
|
||||||
self.future_breakage_diagnostics.push(diagnostic.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(expectation_id) = diagnostic.level.get_expectation_id() {
|
|
||||||
self.suppressed_expected_diag = true;
|
|
||||||
self.fulfilled_expectations.insert(expectation_id.normalize());
|
|
||||||
}
|
|
||||||
|
|
||||||
if diagnostic.level == Warning && !self.flags.can_emit_warnings {
|
|
||||||
if diagnostic.has_future_breakage() {
|
|
||||||
(*TRACK_DIAGNOSTIC)(diagnostic, &mut |_| {});
|
|
||||||
}
|
}
|
||||||
return None;
|
Allow | Expect(_) => {
|
||||||
}
|
(*TRACK_DIAGNOSTIC)(diagnostic, &mut |_| {});
|
||||||
|
return None;
|
||||||
if matches!(diagnostic.level, Expect(_) | Allow) {
|
}
|
||||||
(*TRACK_DIAGNOSTIC)(diagnostic, &mut |_| {});
|
_ => {}
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut guaranteed = None;
|
let mut guaranteed = None;
|
||||||
|
Loading…
Reference in New Issue
Block a user