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:
parent
589591efde
commit
bd4e623485
22 changed files with 193 additions and 183 deletions
|
@ -2848,15 +2848,16 @@ impl<'a> Parser<'a> {
|
|||
let label = self.eat_label().expect("just checked if a label exists");
|
||||
self.bump(); // eat `:`
|
||||
let span = label.ident.span.to(self.prev_token.span);
|
||||
let mut err = self.dcx().struct_span_err(span, "block label not supported here");
|
||||
err.span_label(span, "not supported here");
|
||||
err.tool_only_span_suggestion(
|
||||
label.ident.span.until(self.token.span),
|
||||
"remove this block label",
|
||||
"",
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
err.emit();
|
||||
self.dcx()
|
||||
.struct_span_err(span, "block label not supported here")
|
||||
.span_label_mv(span, "not supported here")
|
||||
.tool_only_span_suggestion_mv(
|
||||
label.ident.span.until(self.token.span),
|
||||
"remove this block label",
|
||||
"",
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
.emit();
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1109,8 +1109,7 @@ impl<'a> Parser<'a> {
|
|||
&& self.token.is_keyword(kw::Unsafe)
|
||||
&& self.look_ahead(1, |t| t.kind == token::OpenDelim(Delimiter::Brace))
|
||||
{
|
||||
let err = self.expect(&token::OpenDelim(Delimiter::Brace)).unwrap_err();
|
||||
err.emit();
|
||||
self.expect(&token::OpenDelim(Delimiter::Brace)).unwrap_err().emit();
|
||||
unsafety = Unsafe::Yes(self.token.span);
|
||||
self.eat_keyword(kw::Unsafe);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue