Skip to content

Commit ca663b0

Browse files
committedJan 8, 2024
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`
2 parents 0ee9cfd + db09eb2 commit ca663b0

File tree

112 files changed

+952
-1275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+952
-1275
lines changed
 

Diff for: ‎compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro_rules! gate {
2323
($visitor:expr, $feature:ident, $span:expr, $explain:expr, $help:expr) => {{
2424
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
2525
feature_err(&$visitor.sess.parse_sess, sym::$feature, $span, $explain)
26-
.help($help)
26+
.help_mv($help)
2727
.emit();
2828
}
2929
}};

Diff for: ‎compiler/rustc_attr/src/session_diagnostics.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ pub(crate) struct UnknownMetaItem<'a> {
5454
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnknownMetaItem<'_> {
5555
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
5656
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
57-
let mut diag = DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item);
58-
diag.span(self.span);
59-
diag.code(error_code!(E0541));
60-
diag.arg("item", self.item);
61-
diag.arg("expected", expected.join(", "));
62-
diag.span_label(self.span, fluent::attr_label);
63-
diag
57+
DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item)
58+
.span_mv(self.span)
59+
.code_mv(error_code!(E0541))
60+
.arg_mv("item", self.item)
61+
.arg_mv("expected", expected.join(", "))
62+
.span_label_mv(self.span, fluent::attr_label)
6463
}
6564
}
6665

0 commit comments

Comments
 (0)