diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-01 10:13:24 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-19 20:23:20 +1100 |
| commit | b18f3e11fa9c2d6fb8a6c4807229bebc3608d3ac (patch) | |
| tree | 733ac87b5dd3c7ba88b0655b0ee3282a2fa02ba3 /compiler/rustc_parse/src/parser/diagnostics.rs | |
| parent | 8b21296b5db6d5724d6b8440dcf459fa82fd88b5 (diff) | |
| download | rust-b18f3e11fa9c2d6fb8a6c4807229bebc3608d3ac.tar.gz rust-b18f3e11fa9c2d6fb8a6c4807229bebc3608d3ac.zip | |
Prefer `DiagnosticBuilder` over `Diagnostic` in diagnostic modifiers.
There are lots of functions that modify a diagnostic. This can be via a `&mut Diagnostic` or a `&mut DiagnosticBuilder`, because the latter type wraps the former and impls `DerefMut`. This commit converts all the `&mut Diagnostic` occurrences to `&mut DiagnosticBuilder`. This is a step towards greatly simplifying `Diagnostic`. Some of the relevant function are made generic, because they deal with both errors and warnings. No function bodies are changed, because all the modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`.
Diffstat (limited to 'compiler/rustc_parse/src/parser/diagnostics.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 659716548d9..0cc2170714c 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -34,8 +34,8 @@ use rustc_ast::{ use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{ - pluralize, AddToDiagnostic, Applicability, DiagCtxt, Diagnostic, DiagnosticBuilder, - ErrorGuaranteed, FatalError, PErr, PResult, + pluralize, AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, ErrorGuaranteed, + FatalError, PErr, PResult, }; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::Spanned; @@ -208,11 +208,11 @@ struct MultiSugg { } impl MultiSugg { - fn emit(self, err: &mut Diagnostic) { + fn emit(self, err: &mut DiagnosticBuilder<'_>) { err.multipart_suggestion(self.msg, self.patches, self.applicability); } - fn emit_verbose(self, err: &mut Diagnostic) { + fn emit_verbose(self, err: &mut DiagnosticBuilder<'_>) { err.multipart_suggestion_verbose(self.msg, self.patches, self.applicability); } } @@ -846,7 +846,7 @@ impl<'a> Parser<'a> { err.emit(); } - fn check_too_many_raw_str_terminators(&mut self, err: &mut Diagnostic) -> bool { + fn check_too_many_raw_str_terminators(&mut self, err: &mut DiagnosticBuilder<'_>) -> bool { let sm = self.sess.source_map(); match (&self.prev_token.kind, &self.token.kind) { ( @@ -2179,7 +2179,7 @@ impl<'a> Parser<'a> { pub(super) fn parameter_without_type( &mut self, - err: &mut Diagnostic, + err: &mut DiagnosticBuilder<'_>, pat: P<ast::Pat>, require_name: bool, first_param: bool, |
