Make Emitter::emit_diagnostic
consuming.
All the other `emit`/`emit_diagnostic` methods were recently made consuming (e.g. #119606), but this one wasn't. But it makes sense to. Much of this is straightforward, and lots of `clone` calls are avoided. There are a couple of tricky bits. - `Emitter::primary_span_formatted` no longer takes a `Diagnostic` and returns a pair. Instead it takes the two fields from `Diagnostic` that it used (`span` and `suggestions`) as `&mut`, and modifies them. This is necessary to avoid the cloning of `diag.children` in two emitters. - `from_errors_diagnostic` is rearranged so various uses of `diag` occur before the consuming `emit_diagnostic` call.
This commit is contained in:
parent
4e3eed4892
commit
d9508a1fd2
7 changed files with 84 additions and 75 deletions
|
@ -44,15 +44,15 @@ impl Translate for AnnotateSnippetEmitter {
|
|||
|
||||
impl Emitter for AnnotateSnippetEmitter {
|
||||
/// The entry point for the diagnostics generation
|
||||
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
|
||||
fn emit_diagnostic(&mut self, mut diag: Diagnostic) {
|
||||
let fluent_args = to_fluent_args(diag.args());
|
||||
|
||||
let mut children = diag.children.clone();
|
||||
let (mut primary_span, suggestions) = self.primary_span_formatted(diag, &fluent_args);
|
||||
let mut suggestions = diag.suggestions.unwrap_or(vec![]);
|
||||
self.primary_span_formatted(&mut diag.span, &mut suggestions, &fluent_args);
|
||||
|
||||
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
||||
&mut primary_span,
|
||||
&mut children,
|
||||
&mut diag.span,
|
||||
&mut diag.children,
|
||||
&diag.level,
|
||||
self.macro_backtrace,
|
||||
);
|
||||
|
@ -62,9 +62,9 @@ impl Emitter for AnnotateSnippetEmitter {
|
|||
&diag.messages,
|
||||
&fluent_args,
|
||||
&diag.code,
|
||||
&primary_span,
|
||||
&children,
|
||||
suggestions,
|
||||
&diag.span,
|
||||
&diag.children,
|
||||
&suggestions,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue