Use chaining in DiagnosticBuilder
construction.
To avoid the use of a mutable local variable, and because it reads more nicely.
This commit is contained in:
parent
b1b9278851
commit
589591efde
22 changed files with 223 additions and 369 deletions
|
@ -249,9 +249,9 @@ impl<'a> StringReader<'a> {
|
|||
let lifetime_name = self.str_from(start);
|
||||
if starts_with_number {
|
||||
let span = self.mk_sp(start, self.pos);
|
||||
let mut diag = self.dcx().struct_err("lifetimes cannot start with a number");
|
||||
diag.span(span);
|
||||
diag.stash(span, StashKey::LifetimeIsChar);
|
||||
self.dcx().struct_err("lifetimes cannot start with a number")
|
||||
.span_mv(span)
|
||||
.stash(span, StashKey::LifetimeIsChar);
|
||||
}
|
||||
let ident = Symbol::intern(lifetime_name);
|
||||
token::Lifetime(ident)
|
||||
|
|
|
@ -200,23 +200,22 @@ impl<'a> Parser<'a> {
|
|||
if let InnerAttrPolicy::Forbidden(reason) = policy {
|
||||
let mut diag = match reason.as_ref().copied() {
|
||||
Some(InnerAttrForbiddenReason::AfterOuterDocComment { prev_doc_comment_span }) => {
|
||||
let mut diag = self.dcx().struct_span_err(
|
||||
attr_sp,
|
||||
fluent::parse_inner_attr_not_permitted_after_outer_doc_comment,
|
||||
);
|
||||
diag.span_label(attr_sp, fluent::parse_label_attr)
|
||||
.span_label(prev_doc_comment_span, fluent::parse_label_prev_doc_comment);
|
||||
diag
|
||||
self.dcx()
|
||||
.struct_span_err(
|
||||
attr_sp,
|
||||
fluent::parse_inner_attr_not_permitted_after_outer_doc_comment,
|
||||
)
|
||||
.span_label_mv(attr_sp, fluent::parse_label_attr)
|
||||
.span_label_mv(prev_doc_comment_span, fluent::parse_label_prev_doc_comment)
|
||||
}
|
||||
Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }) => {
|
||||
let mut diag = self.dcx().struct_span_err(
|
||||
Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }) => self
|
||||
.dcx()
|
||||
.struct_span_err(
|
||||
attr_sp,
|
||||
fluent::parse_inner_attr_not_permitted_after_outer_attr,
|
||||
);
|
||||
diag.span_label(attr_sp, fluent::parse_label_attr)
|
||||
.span_label(prev_outer_attr_sp, fluent::parse_label_prev_attr);
|
||||
diag
|
||||
}
|
||||
)
|
||||
.span_label_mv(attr_sp, fluent::parse_label_attr)
|
||||
.span_label_mv(prev_outer_attr_sp, fluent::parse_label_prev_attr),
|
||||
Some(InnerAttrForbiddenReason::InCodeBlock) | None => {
|
||||
self.dcx().struct_span_err(attr_sp, fluent::parse_inner_attr_not_permitted)
|
||||
}
|
||||
|
|
|
@ -1941,15 +1941,14 @@ impl<'a> Parser<'a> {
|
|||
Case::Insensitive,
|
||||
) {
|
||||
Ok(_) => {
|
||||
let mut err = self.dcx().struct_span_err(
|
||||
self.dcx().struct_span_err(
|
||||
lo.to(self.prev_token.span),
|
||||
format!("functions are not allowed in {adt_ty} definitions"),
|
||||
);
|
||||
err.help(
|
||||
)
|
||||
.help_mv(
|
||||
"unlike in C++, Java, and C#, functions are declared in `impl` blocks",
|
||||
);
|
||||
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
|
||||
err
|
||||
)
|
||||
.help_mv("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information")
|
||||
}
|
||||
Err(err) => {
|
||||
err.cancel();
|
||||
|
@ -1959,14 +1958,13 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
} else if self.eat_keyword(kw::Struct) {
|
||||
match self.parse_item_struct() {
|
||||
Ok((ident, _)) => {
|
||||
let mut err = self.dcx().struct_span_err(
|
||||
Ok((ident, _)) => self
|
||||
.dcx()
|
||||
.struct_span_err(
|
||||
lo.with_hi(ident.span.hi()),
|
||||
format!("structs are not allowed in {adt_ty} definitions"),
|
||||
);
|
||||
err.help("consider creating a new `struct` definition instead of nesting");
|
||||
err
|
||||
}
|
||||
)
|
||||
.help_mv("consider creating a new `struct` definition instead of nesting"),
|
||||
Err(err) => {
|
||||
err.cancel();
|
||||
self.restore_snapshot(snapshot);
|
||||
|
|
|
@ -460,9 +460,10 @@ impl<'a> Parser<'a> {
|
|||
super::token_descr(&self_.token)
|
||||
);
|
||||
|
||||
let mut err = self_.dcx().struct_span_err(self_.token.span, msg);
|
||||
err.span_label(self_.token.span, format!("expected {expected}"));
|
||||
err
|
||||
self_
|
||||
.dcx()
|
||||
.struct_span_err(self_.token.span, msg)
|
||||
.span_label_mv(self_.token.span, format!("expected {expected}"))
|
||||
});
|
||||
PatKind::Lit(self.mk_expr(lo, ExprKind::Lit(lit)))
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue