]> git.lizzy.rs Git - rust.git/commitdiff
Take &mut Diagnostic in emit_diagnostic.
authorCamille GILLOT <gillot.camille@gmail.com>
Sun, 20 Mar 2022 17:26:09 +0000 (18:26 +0100)
committerCamille GILLOT <gillot.camille@gmail.com>
Sun, 20 Mar 2022 19:36:08 +0000 (20:36 +0100)
Taking a Diagnostic by move would break the usual pattern
`diag.label(..).emit()`.

13 files changed:
compiler/rustc_borrowck/src/lib.rs
compiler/rustc_codegen_ssa/src/back/write.rs
compiler/rustc_const_eval/src/transform/check_consts/check.rs
compiler/rustc_driver/src/lib.rs
compiler/rustc_errors/src/diagnostic_builder.rs
compiler/rustc_errors/src/emitter.rs
compiler/rustc_errors/src/lib.rs
compiler/rustc_expand/src/proc_macro_server.rs
compiler/rustc_parse/src/lib.rs
compiler/rustc_query_system/src/dep_graph/graph.rs
compiler/rustc_typeck/src/check/writeback.rs
src/tools/clippy/src/driver.rs
src/tools/rustfmt/src/parse/session.rs

index c9c973bd34350267fb0520a326cef38eec911b74..6f78c8160932a60b8715a30176eacac3ed643b41 100644 (file)
@@ -2361,8 +2361,8 @@ pub fn emit_errors(&mut self) -> Option<ErrorGuaranteed> {
             if !self.errors.buffered.is_empty() {
                 self.errors.buffered.sort_by_key(|diag| diag.sort_span);
 
-                for diag in self.errors.buffered.drain(..) {
-                    self.infcx.tcx.sess.diagnostic().emit_diagnostic(&diag);
+                for mut diag in self.errors.buffered.drain(..) {
+                    self.infcx.tcx.sess.diagnostic().emit_diagnostic(&mut diag);
                 }
             }
 
index e23572104c4756b1fc486285cba57dff2746b30e..1d11e6dfbd25f42f58b23b3f61aebd7517fb628c 100644 (file)
@@ -1748,7 +1748,7 @@ pub fn check(&self, sess: &Session, blocking: bool) {
                     if let Some(code) = diag.code {
                         d.code(code);
                     }
-                    handler.emit_diagnostic(&d);
+                    handler.emit_diagnostic(&mut d);
                 }
                 Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
                     let msg = msg.strip_prefix("error: ").unwrap_or(&msg);
index eb01e261c1a55706a94c3cbd6814809e3e215c42..223b3ad0cf9ce99a4e75506f69e82d67542b2789 100644 (file)
@@ -255,8 +255,8 @@ pub fn check_body(&mut self) {
         // "secondary" errors if they occurred.
         let secondary_errors = mem::take(&mut self.secondary_errors);
         if self.error_emitted.is_none() {
-            for error in secondary_errors {
-                self.tcx.sess.diagnostic().emit_diagnostic(&error);
+            for mut error in secondary_errors {
+                self.tcx.sess.diagnostic().emit_diagnostic(&mut error);
             }
         } else {
             assert!(self.tcx.sess.has_errors().is_some());
index 91bb38e5a95d5321e758e9810b977fd2abe3dab7..667c63b709b76220e73603686c86ef98c66d66e2 100644 (file)
@@ -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
     // it wants to print.
     if !info.payload().is::<rustc_errors::ExplicitBug>() {
-        let d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
-        handler.emit_diagnostic(&d);
+        let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
+        handler.emit_diagnostic(&mut d);
     }
 
     let mut xs: Vec<Cow<'static, str>> = vec![
index 72471638a966bbb4fffd7ef0ec5628de47691808..34236d3603558ae467cd3926037b8146fe110897 100644 (file)
@@ -128,7 +128,7 @@ fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Se
             DiagnosticBuilderState::Emittable(handler) => {
                 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
                 // non-error - the field isn't `pub`, but the whole `Diagnostic`
@@ -190,7 +190,7 @@ fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Se
             DiagnosticBuilderState::Emittable(handler) => {
                 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.
             DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
@@ -500,11 +500,11 @@ fn drop(&mut self) {
             // No `.emit()` or `.cancel()` calls.
             DiagnosticBuilderState::Emittable(handler) => {
                 if !panicking() {
-                    handler.emit_diagnostic(&Diagnostic::new(
+                    handler.emit_diagnostic(&mut Diagnostic::new(
                         Level::Bug,
                         "the following error was constructed but not emitted",
                     ));
-                    handler.emit_diagnostic(&self.diagnostic);
+                    handler.emit_diagnostic(&mut self.diagnostic);
                     panic!();
                 }
             }
index 831d408195e2feede83e3e6f26f7f475bcff38cf..93b7201023a496290c77b74e549e16fc58c45cbc 100644 (file)
@@ -542,7 +542,7 @@ fn emit_diagnostic(&mut self, d: &Diagnostic) {
             if let Some(ref note) = self.fatal_note {
                 d.note(note);
             }
-            self.fatal_handler.emit_diagnostic(&d);
+            self.fatal_handler.emit_diagnostic(&mut d);
         }
     }
 }
index c719e4910ce4eaa3942536193e9abacb0f855adb..7cfb332d69d895403dabb6f94b5e28613a001892 100644 (file)
@@ -919,7 +919,7 @@ pub fn force_print_diagnostic(&self, db: Diagnostic) {
         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 @@ fn must_teach(&mut self, code: &DiagnosticId) -> bool {
         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 @@ fn delay_span_bug(&mut self, sp: impl Into<MultiSpan>, msg: &str) -> ErrorGuaran
         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 @@ fn emit(&mut self, level: Level, msg: &str) -> ErrorGuaranteed {
         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 @@ fn flush_delayed(&mut self, bugs: impl IntoIterator<Item = Diagnostic>, explanat
             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 @@ fn flush_delayed(&mut self, bugs: impl IntoIterator<Item = Diagnostic>, explanat
             }
             bug.level = Level::Bug;
 
-            self.emit_diagnostic(&bug);
+            self.emit_diagnostic(&mut bug);
         }
 
         // Panic with `ExplicitBug` to avoid "unexpected panic" messages.
index 0aef5982cff509ccd066b6584fb6b9b071d7a191..5bd4bee3adfca58e50c6f7c2bfe036da96303726 100644 (file)
@@ -771,8 +771,8 @@ fn sub(
     ) {
         diag.sub(level.to_internal(), msg, MultiSpan::from_spans(spans), None);
     }
-    fn emit(&mut self, diag: Self::Diagnostic) {
-        self.sess().span_diagnostic.emit_diagnostic(&diag);
+    fn emit(&mut self, mut diag: Self::Diagnostic) {
+        self.sess().span_diagnostic.emit_diagnostic(&mut diag);
     }
 }
 
index a3e66464fbc8fdde4f45002a1c01d6830394a836..0ce86a764f417a1d5843198fb424bc4666859d7f 100644 (file)
@@ -49,8 +49,8 @@ macro_rules! panictry_buffer {
         match $e {
             Ok(e) => e,
             Err(errs) => {
-                for e in errs {
-                    $handler.emit_diagnostic(&e);
+                for mut e in errs {
+                    $handler.emit_diagnostic(&mut e);
                 }
                 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> {
     match try_file_to_source_file(sess, path, spanopt) {
         Ok(source_file) => source_file,
-        Err(d) => {
-            sess.span_diagnostic.emit_diagnostic(&d);
+        Err(mut d) => {
+            sess.span_diagnostic.emit_diagnostic(&mut d);
             FatalError.raise();
         }
     }
index a080b4a3e9ab58b5eba37cba571782db85d4b7af..f7655e55d34859a248871090b0f589857ec27a81 100644 (file)
@@ -784,8 +784,8 @@ fn emit_side_effects<Ctxt: QueryContext<DepKind = K>>(
 
             let handle = tcx.dep_context().sess().diagnostic();
 
-            for diagnostic in side_effects.diagnostics {
-                handle.emit_diagnostic(&diagnostic);
+            for mut diagnostic in side_effects.diagnostics {
+                handle.emit_diagnostic(&mut diagnostic);
             }
         }
     }
index 16ffabb76a515f82947dcaf80b5ec9dca9012185..c1cb9a1a8d1394ebdafe272674556f9635628ad2 100644 (file)
@@ -467,8 +467,8 @@ fn visit_user_provided_tys(&mut self) {
 
         if !errors_buffer.is_empty() {
             errors_buffer.sort_by_key(|diag| diag.span.primary_span());
-            for diag in errors_buffer.drain(..) {
-                self.tcx().sess.diagnostic().emit_diagnostic(&diag);
+            for mut diag in errors_buffer.drain(..) {
+                self.tcx().sess.diagnostic().emit_diagnostic(&mut diag);
             }
         }
     }
index 8f8f1140a3da62e86f030a16f10abacaccb9d6df..855a6a6ef6adafd4aaa2dd5441189dce22e7b60d 100644 (file)
@@ -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
     // it wants to print.
     if !info.payload().is::<rustc_errors::ExplicitBug>() {
-        let d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
-        handler.emit_diagnostic(&d);
+        let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
+        handler.emit_diagnostic(&mut d);
     }
 
     let version_info = rustc_tools_util::get_version_info!();
index a34ceed3fc91fe76ea306acdae1b07077d4991dc..412f4434b9ead51f2ea5412ab16df06266aa11e9 100644 (file)
@@ -225,8 +225,10 @@ pub(crate) fn get_original_snippet(&self, file_name: &FileName) -> Option<Lrc<St
 // Methods that should be restricted within the parse module.
 impl ParseSess {
     pub(super) fn emit_diagnostics(&self, diagnostics: Vec<Diagnostic>) {
-        for diagnostic in diagnostics {
-            self.parse_sess.span_diagnostic.emit_diagnostic(&diagnostic);
+        for mut diagnostic in diagnostics {
+            self.parse_sess
+                .span_diagnostic
+                .emit_diagnostic(&mut diagnostic);
         }
     }