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
|
@ -2361,8 +2361,8 @@ mod error {
|
||||||
if !self.errors.buffered.is_empty() {
|
if !self.errors.buffered.is_empty() {
|
||||||
self.errors.buffered.sort_by_key(|diag| diag.sort_span);
|
self.errors.buffered.sort_by_key(|diag| diag.sort_span);
|
||||||
|
|
||||||
for diag in self.errors.buffered.drain(..) {
|
for mut diag in self.errors.buffered.drain(..) {
|
||||||
self.infcx.tcx.sess.diagnostic().emit_diagnostic(&diag);
|
self.infcx.tcx.sess.diagnostic().emit_diagnostic(&mut diag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1748,7 +1748,7 @@ impl SharedEmitterMain {
|
||||||
if let Some(code) = diag.code {
|
if let Some(code) = diag.code {
|
||||||
d.code(code);
|
d.code(code);
|
||||||
}
|
}
|
||||||
handler.emit_diagnostic(&d);
|
handler.emit_diagnostic(&mut d);
|
||||||
}
|
}
|
||||||
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
|
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
|
||||||
let msg = msg.strip_prefix("error: ").unwrap_or(&msg);
|
let msg = msg.strip_prefix("error: ").unwrap_or(&msg);
|
||||||
|
|
|
@ -255,8 +255,8 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
|
||||||
// "secondary" errors if they occurred.
|
// "secondary" errors if they occurred.
|
||||||
let secondary_errors = mem::take(&mut self.secondary_errors);
|
let secondary_errors = mem::take(&mut self.secondary_errors);
|
||||||
if self.error_emitted.is_none() {
|
if self.error_emitted.is_none() {
|
||||||
for error in secondary_errors {
|
for mut error in secondary_errors {
|
||||||
self.tcx.sess.diagnostic().emit_diagnostic(&error);
|
self.tcx.sess.diagnostic().emit_diagnostic(&mut error);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert!(self.tcx.sess.has_errors().is_some());
|
assert!(self.tcx.sess.has_errors().is_some());
|
||||||
|
|
|
@ -1181,8 +1181,8 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
||||||
// a .span_bug or .bug call has already printed what
|
// a .span_bug or .bug call has already printed what
|
||||||
// it wants to print.
|
// it wants to print.
|
||||||
if !info.payload().is::<rustc_errors::ExplicitBug>() {
|
if !info.payload().is::<rustc_errors::ExplicitBug>() {
|
||||||
let d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
|
let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
|
||||||
handler.emit_diagnostic(&d);
|
handler.emit_diagnostic(&mut d);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut xs: Vec<Cow<'static, str>> = vec![
|
let mut xs: Vec<Cow<'static, str>> = vec![
|
||||||
|
|
|
@ -128,7 +128,7 @@ impl EmissionGuarantee for ErrorGuaranteed {
|
||||||
DiagnosticBuilderState::Emittable(handler) => {
|
DiagnosticBuilderState::Emittable(handler) => {
|
||||||
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||||
|
|
||||||
let guar = handler.emit_diagnostic(&db.inner.diagnostic);
|
let guar = handler.emit_diagnostic(&mut db.inner.diagnostic);
|
||||||
|
|
||||||
// Only allow a guarantee if the `level` wasn't switched to a
|
// Only allow a guarantee if the `level` wasn't switched to a
|
||||||
// non-error - the field isn't `pub`, but the whole `Diagnostic`
|
// non-error - the field isn't `pub`, but the whole `Diagnostic`
|
||||||
|
@ -190,7 +190,7 @@ impl EmissionGuarantee for () {
|
||||||
DiagnosticBuilderState::Emittable(handler) => {
|
DiagnosticBuilderState::Emittable(handler) => {
|
||||||
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||||
|
|
||||||
handler.emit_diagnostic(&db.inner.diagnostic);
|
handler.emit_diagnostic(&mut db.inner.diagnostic);
|
||||||
}
|
}
|
||||||
// `.emit()` was previously called, disallowed from repeating it.
|
// `.emit()` was previously called, disallowed from repeating it.
|
||||||
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
|
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
|
||||||
|
@ -500,11 +500,11 @@ impl Drop for DiagnosticBuilderInner<'_> {
|
||||||
// No `.emit()` or `.cancel()` calls.
|
// No `.emit()` or `.cancel()` calls.
|
||||||
DiagnosticBuilderState::Emittable(handler) => {
|
DiagnosticBuilderState::Emittable(handler) => {
|
||||||
if !panicking() {
|
if !panicking() {
|
||||||
handler.emit_diagnostic(&Diagnostic::new(
|
handler.emit_diagnostic(&mut Diagnostic::new(
|
||||||
Level::Bug,
|
Level::Bug,
|
||||||
"the following error was constructed but not emitted",
|
"the following error was constructed but not emitted",
|
||||||
));
|
));
|
||||||
handler.emit_diagnostic(&self.diagnostic);
|
handler.emit_diagnostic(&mut self.diagnostic);
|
||||||
panic!();
|
panic!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -542,7 +542,7 @@ impl Emitter for SilentEmitter {
|
||||||
if let Some(ref note) = self.fatal_note {
|
if let Some(ref note) = self.fatal_note {
|
||||||
d.note(note);
|
d.note(note);
|
||||||
}
|
}
|
||||||
self.fatal_handler.emit_diagnostic(&d);
|
self.fatal_handler.emit_diagnostic(&mut d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -919,7 +919,7 @@ impl Handler {
|
||||||
self.inner.borrow_mut().force_print_diagnostic(db)
|
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)
|
self.inner.borrow_mut().emit_diagnostic(diagnostic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -993,25 +993,25 @@ impl HandlerInner {
|
||||||
self.taught_diagnostics.insert(code.clone())
|
self.taught_diagnostics.insert(code.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn force_print_diagnostic(&mut self, db: Diagnostic) {
|
fn force_print_diagnostic(&mut self, mut db: Diagnostic) {
|
||||||
self.emitter.emit_diagnostic(&db);
|
self.emitter.emit_diagnostic(&mut db);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emit all stashed diagnostics.
|
/// Emit all stashed diagnostics.
|
||||||
fn emit_stashed_diagnostics(&mut self) -> Option<ErrorGuaranteed> {
|
fn emit_stashed_diagnostics(&mut self) -> Option<ErrorGuaranteed> {
|
||||||
let diags = self.stashed_diagnostics.drain(..).map(|x| x.1).collect::<Vec<_>>();
|
let diags = self.stashed_diagnostics.drain(..).map(|x| x.1).collect::<Vec<_>>();
|
||||||
let mut reported = None;
|
let mut reported = None;
|
||||||
diags.iter().for_each(|diag| {
|
for mut diag in diags {
|
||||||
if diag.is_error() {
|
if diag.is_error() {
|
||||||
reported = Some(ErrorGuaranteed(()));
|
reported = Some(ErrorGuaranteed(()));
|
||||||
}
|
}
|
||||||
self.emit_diagnostic(diag);
|
self.emit_diagnostic(&mut diag);
|
||||||
});
|
}
|
||||||
reported
|
reported
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(eddyb) this should ideally take `diagnostic` by value.
|
// 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 {
|
if diagnostic.level == Level::DelayedBug {
|
||||||
// FIXME(eddyb) this should check for `has_errors` and stop pushing
|
// FIXME(eddyb) this should check for `has_errors` and stop pushing
|
||||||
// once *any* errors were emitted (and truncate `delayed_span_bugs`
|
// once *any* errors were emitted (and truncate `delayed_span_bugs`
|
||||||
|
@ -1221,22 +1221,22 @@ impl HandlerInner {
|
||||||
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg);
|
let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg);
|
||||||
diagnostic.set_span(sp.into());
|
diagnostic.set_span(sp.into());
|
||||||
diagnostic.note(&format!("delayed at {}", std::panic::Location::caller()));
|
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
|
// 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).
|
// where the explanation of what "good path" is (also, it should be renamed).
|
||||||
fn delay_good_path_bug(&mut self, msg: &str) {
|
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 {
|
if self.flags.report_delayed_bugs {
|
||||||
self.emit_diagnostic(&diagnostic);
|
self.emit_diagnostic(&mut diagnostic);
|
||||||
}
|
}
|
||||||
let backtrace = std::backtrace::Backtrace::force_capture();
|
let backtrace = std::backtrace::Backtrace::force_capture();
|
||||||
self.delayed_good_path_bugs.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
|
self.delayed_good_path_bugs.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn failure(&mut self, msg: &str) {
|
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 {
|
fn fatal(&mut self, msg: &str) -> FatalError {
|
||||||
|
@ -1253,11 +1253,11 @@ impl HandlerInner {
|
||||||
if self.treat_err_as_bug() {
|
if self.treat_err_as_bug() {
|
||||||
self.bug(msg);
|
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) -> ! {
|
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);
|
panic::panic_any(ExplicitBug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1267,7 +1267,7 @@ impl HandlerInner {
|
||||||
if no_bugs {
|
if no_bugs {
|
||||||
// Put the overall explanation before the `DelayedBug`s, to
|
// Put the overall explanation before the `DelayedBug`s, to
|
||||||
// frame them better (e.g. separate warnings from them).
|
// 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;
|
no_bugs = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1283,7 +1283,7 @@ impl HandlerInner {
|
||||||
}
|
}
|
||||||
bug.level = Level::Bug;
|
bug.level = Level::Bug;
|
||||||
|
|
||||||
self.emit_diagnostic(&bug);
|
self.emit_diagnostic(&mut bug);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panic with `ExplicitBug` to avoid "unexpected panic" messages.
|
// Panic with `ExplicitBug` to avoid "unexpected panic" messages.
|
||||||
|
|
|
@ -771,8 +771,8 @@ impl server::Diagnostic for Rustc<'_, '_> {
|
||||||
) {
|
) {
|
||||||
diag.sub(level.to_internal(), msg, MultiSpan::from_spans(spans), None);
|
diag.sub(level.to_internal(), msg, MultiSpan::from_spans(spans), None);
|
||||||
}
|
}
|
||||||
fn emit(&mut self, diag: Self::Diagnostic) {
|
fn emit(&mut self, mut diag: Self::Diagnostic) {
|
||||||
self.sess().span_diagnostic.emit_diagnostic(&diag);
|
self.sess().span_diagnostic.emit_diagnostic(&mut diag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ macro_rules! panictry_buffer {
|
||||||
match $e {
|
match $e {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(errs) => {
|
Err(errs) => {
|
||||||
for e in errs {
|
for mut e in errs {
|
||||||
$handler.emit_diagnostic(&e);
|
$handler.emit_diagnostic(&mut e);
|
||||||
}
|
}
|
||||||
FatalError.raise()
|
FatalError.raise()
|
||||||
}
|
}
|
||||||
|
@ -167,8 +167,8 @@ fn try_file_to_source_file(
|
||||||
fn file_to_source_file(sess: &ParseSess, path: &Path, spanopt: Option<Span>) -> Lrc<SourceFile> {
|
fn file_to_source_file(sess: &ParseSess, path: &Path, spanopt: Option<Span>) -> Lrc<SourceFile> {
|
||||||
match try_file_to_source_file(sess, path, spanopt) {
|
match try_file_to_source_file(sess, path, spanopt) {
|
||||||
Ok(source_file) => source_file,
|
Ok(source_file) => source_file,
|
||||||
Err(d) => {
|
Err(mut d) => {
|
||||||
sess.span_diagnostic.emit_diagnostic(&d);
|
sess.span_diagnostic.emit_diagnostic(&mut d);
|
||||||
FatalError.raise();
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -784,8 +784,8 @@ impl<K: DepKind> DepGraph<K> {
|
||||||
|
|
||||||
let handle = tcx.dep_context().sess().diagnostic();
|
let handle = tcx.dep_context().sess().diagnostic();
|
||||||
|
|
||||||
for diagnostic in side_effects.diagnostics {
|
for mut diagnostic in side_effects.diagnostics {
|
||||||
handle.emit_diagnostic(&diagnostic);
|
handle.emit_diagnostic(&mut diagnostic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -467,8 +467,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||||
|
|
||||||
if !errors_buffer.is_empty() {
|
if !errors_buffer.is_empty() {
|
||||||
errors_buffer.sort_by_key(|diag| diag.span.primary_span());
|
errors_buffer.sort_by_key(|diag| diag.span.primary_span());
|
||||||
for diag in errors_buffer.drain(..) {
|
for mut diag in errors_buffer.drain(..) {
|
||||||
self.tcx().sess.diagnostic().emit_diagnostic(&diag);
|
self.tcx().sess.diagnostic().emit_diagnostic(&mut diag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,8 +178,8 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
||||||
// a .span_bug or .bug call has already printed what
|
// a .span_bug or .bug call has already printed what
|
||||||
// it wants to print.
|
// it wants to print.
|
||||||
if !info.payload().is::<rustc_errors::ExplicitBug>() {
|
if !info.payload().is::<rustc_errors::ExplicitBug>() {
|
||||||
let d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
|
let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
|
||||||
handler.emit_diagnostic(&d);
|
handler.emit_diagnostic(&mut d);
|
||||||
}
|
}
|
||||||
|
|
||||||
let version_info = rustc_tools_util::get_version_info!();
|
let version_info = rustc_tools_util::get_version_info!();
|
||||||
|
|
|
@ -225,8 +225,10 @@ impl ParseSess {
|
||||||
// Methods that should be restricted within the parse module.
|
// Methods that should be restricted within the parse module.
|
||||||
impl ParseSess {
|
impl ParseSess {
|
||||||
pub(super) fn emit_diagnostics(&self, diagnostics: Vec<Diagnostic>) {
|
pub(super) fn emit_diagnostics(&self, diagnostics: Vec<Diagnostic>) {
|
||||||
for diagnostic in diagnostics {
|
for mut diagnostic in diagnostics {
|
||||||
self.parse_sess.span_diagnostic.emit_diagnostic(&diagnostic);
|
self.parse_sess
|
||||||
|
.span_diagnostic
|
||||||
|
.emit_diagnostic(&mut diagnostic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue