about summary refs log tree commit diff
path: root/compiler/rustc_session/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-01-08 16:06:28 +0000
committerbors <bors@rust-lang.org>2024-01-08 16:06:28 +0000
commitca663b06c5492ac2dde5e53cd11579fa8e4d68bd (patch)
treedbc8c5a057699093a6c544c6df2d65accc0fffb5 /compiler/rustc_session/src
parent0ee9cfd54db7b5f4be35f026588904500c866196 (diff)
parentdb09eb2d3accf8909ea2813ebb00c58c7f2fad64 (diff)
downloadrust-ca663b06c5492ac2dde5e53cd11579fa8e4d68bd.tar.gz
rust-ca663b06c5492ac2dde5e53cd11579fa8e4d68bd.zip
Auto merge of #119606 - nnethercote:consuming-emit, r=oli-obk
Consuming `emit`

This PR makes `DiagnosticBuilder::emit` consuming, i.e. take `self` instead of `&mut self`. This is good because it doesn't make sense to emit a diagnostic twice.

This requires some changes to `DiagnosticBuilder` method changing -- every existing non-consuming chaining method gets a new consuming partner with a `_mv` suffix -- but permits a host of beneficial follow-up changes: more concise code through more chaining, removal of redundant diagnostic construction API methods, and removal of machinery to track the possibility of a diagnostic being emitted multiple times.

r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_session/src')
-rw-r--r--compiler/rustc_session/src/errors.rs7
-rw-r--r--compiler/rustc_session/src/session.rs5
2 files changed, 7 insertions, 5 deletions
diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs
index 758c3122404..8baa5d892a5 100644
--- a/compiler/rustc_session/src/errors.rs
+++ b/compiler/rustc_session/src/errors.rs
@@ -18,10 +18,9 @@ pub struct FeatureGateError {
 impl<'a> IntoDiagnostic<'a> for FeatureGateError {
     #[track_caller]
     fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a> {
-        let mut diag = DiagnosticBuilder::new(dcx, level, self.explain);
-        diag.span(self.span);
-        diag.code(error_code!(E0658));
-        diag
+        DiagnosticBuilder::new(dcx, level, self.explain)
+            .span_mv(self.span)
+            .code_mv(error_code!(E0658))
     }
 }
 
diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs
index ce166ae352f..8491d9b4abc 100644
--- a/compiler/rustc_session/src/session.rs
+++ b/compiler/rustc_session/src/session.rs
@@ -1491,7 +1491,10 @@ impl EarlyDiagCtxt {
         jobserver::initialize_checked(|err| {
             #[allow(rustc::untranslatable_diagnostic)]
             #[allow(rustc::diagnostic_outside_of_impl)]
-            self.dcx.struct_warn(err).note("the build environment is likely misconfigured").emit()
+            self.dcx
+                .struct_warn(err)
+                .note_mv("the build environment is likely misconfigured")
+                .emit()
         });
     }
 }