1
Fork 0

Use chaining for DiagnosticBuilder construction and emit.

To avoid the use of a mutable local variable, and because it reads more
nicely.
This commit is contained in:
Nicholas Nethercote 2024-01-03 17:03:10 +11:00
parent 589591efde
commit bd4e623485
22 changed files with 193 additions and 183 deletions

View file

@ -141,17 +141,18 @@ impl<'a> Parser<'a> {
// Parse optional const generics default value.
let default = if self.eat(&token::Eq) { Some(self.parse_const_arg()?) } else { None };
let mut err = self.dcx().struct_span_err(
mistyped_const_ident.span,
format!("`const` keyword was mistyped as `{}`", mistyped_const_ident.as_str()),
);
err.span_suggestion_verbose(
mistyped_const_ident.span,
"use the `const` keyword",
kw::Const.as_str(),
Applicability::MachineApplicable,
);
err.emit();
self.dcx()
.struct_span_err(
mistyped_const_ident.span,
format!("`const` keyword was mistyped as `{}`", mistyped_const_ident.as_str()),
)
.span_suggestion_verbose_mv(
mistyped_const_ident.span,
"use the `const` keyword",
kw::Const.as_str(),
Applicability::MachineApplicable,
)
.emit();
Ok(GenericParam {
ident,