Take &mut Diagnostic in emit_diagnostic.
Taking a Diagnostic by move would break the usual pattern `diag.label(..).emit()`.
This commit is contained in:
parent
4767ccec93
commit
056951d628
13 changed files with 43 additions and 41 deletions
|
@ -919,7 +919,7 @@ impl Handler {
|
|||
self.inner.borrow_mut().force_print_diagnostic(db)
|
||||
}
|
||||
|
||||
pub fn emit_diagnostic(&self, diagnostic: &Diagnostic) -> Option<ErrorGuaranteed> {
|
||||
pub fn emit_diagnostic(&self, diagnostic: &mut Diagnostic) -> Option<ErrorGuaranteed> {
|
||||
self.inner.borrow_mut().emit_diagnostic(diagnostic)
|
||||
}
|
||||
|
||||
|
@ -993,25 +993,25 @@ impl HandlerInner {
|
|||
self.taught_diagnostics.insert(code.clone())
|
||||
}
|
||||
|
||||
fn force_print_diagnostic(&mut self, db: Diagnostic) {
|
||||
self.emitter.emit_diagnostic(&db);
|
||||
fn force_print_diagnostic(&mut self, mut db: Diagnostic) {
|
||||
self.emitter.emit_diagnostic(&mut db);
|
||||
}
|
||||
|
||||
/// Emit all stashed diagnostics.
|
||||
fn emit_stashed_diagnostics(&mut self) -> Option<ErrorGuaranteed> {
|
||||
let diags = self.stashed_diagnostics.drain(..).map(|x| x.1).collect::<Vec<_>>();
|
||||
let mut reported = None;
|
||||
diags.iter().for_each(|diag| {
|
||||
for mut diag in diags {
|
||||
if diag.is_error() {
|
||||
reported = Some(ErrorGuaranteed(()));
|
||||
}
|
||||
self.emit_diagnostic(diag);
|
||||
});
|
||||
self.emit_diagnostic(&mut diag);
|
||||
}
|
||||
reported
|
||||
}
|
||||
|
||||
// FIXME(eddyb) this should ideally take `diagnostic` by value.
|
||||
fn emit_diagnostic(&mut self, diagnostic: &Diagnostic) -> Option<ErrorGuaranteed> {
|
||||
fn emit_diagnostic(&mut self, diagnostic: &mut Diagnostic) -> Option<ErrorGuaranteed> {
|
||||
if diagnostic.level == Level::DelayedBug {
|
||||
// FIXME(eddyb) this should check for `has_errors` and stop pushing
|
||||
// once *any* errors were emitted (and truncate `delayed_span_bugs`
|
||||
|
@ -1221,22 +1221,22 @@ impl HandlerInner {
|
|||
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg);
|
||||
diagnostic.set_span(sp.into());
|
||||
diagnostic.note(&format!("delayed at {}", std::panic::Location::caller()));
|
||||
self.emit_diagnostic(&diagnostic).unwrap()
|
||||
self.emit_diagnostic(&mut diagnostic).unwrap()
|
||||
}
|
||||
|
||||
// FIXME(eddyb) note the comment inside `impl Drop for HandlerInner`, that's
|
||||
// where the explanation of what "good path" is (also, it should be renamed).
|
||||
fn delay_good_path_bug(&mut self, msg: &str) {
|
||||
let diagnostic = Diagnostic::new(Level::DelayedBug, msg);
|
||||
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg);
|
||||
if self.flags.report_delayed_bugs {
|
||||
self.emit_diagnostic(&diagnostic);
|
||||
self.emit_diagnostic(&mut diagnostic);
|
||||
}
|
||||
let backtrace = std::backtrace::Backtrace::force_capture();
|
||||
self.delayed_good_path_bugs.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
|
||||
}
|
||||
|
||||
fn failure(&mut self, msg: &str) {
|
||||
self.emit_diagnostic(&Diagnostic::new(FailureNote, msg));
|
||||
self.emit_diagnostic(&mut Diagnostic::new(FailureNote, msg));
|
||||
}
|
||||
|
||||
fn fatal(&mut self, msg: &str) -> FatalError {
|
||||
|
@ -1253,11 +1253,11 @@ impl HandlerInner {
|
|||
if self.treat_err_as_bug() {
|
||||
self.bug(msg);
|
||||
}
|
||||
self.emit_diagnostic(&Diagnostic::new(level, msg)).unwrap()
|
||||
self.emit_diagnostic(&mut Diagnostic::new(level, msg)).unwrap()
|
||||
}
|
||||
|
||||
fn bug(&mut self, msg: &str) -> ! {
|
||||
self.emit_diagnostic(&Diagnostic::new(Bug, msg));
|
||||
self.emit_diagnostic(&mut Diagnostic::new(Bug, msg));
|
||||
panic::panic_any(ExplicitBug);
|
||||
}
|
||||
|
||||
|
@ -1267,7 +1267,7 @@ impl HandlerInner {
|
|||
if no_bugs {
|
||||
// Put the overall explanation before the `DelayedBug`s, to
|
||||
// frame them better (e.g. separate warnings from them).
|
||||
self.emit_diagnostic(&Diagnostic::new(Bug, explanation));
|
||||
self.emit_diagnostic(&mut Diagnostic::new(Bug, explanation));
|
||||
no_bugs = false;
|
||||
}
|
||||
|
||||
|
@ -1283,7 +1283,7 @@ impl HandlerInner {
|
|||
}
|
||||
bug.level = Level::Bug;
|
||||
|
||||
self.emit_diagnostic(&bug);
|
||||
self.emit_diagnostic(&mut bug);
|
||||
}
|
||||
|
||||
// Panic with `ExplicitBug` to avoid "unexpected panic" messages.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue