1
Fork 0

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:
Nicholas Nethercote 2024-01-03 16:00:29 +11:00
parent b1b9278851
commit 589591efde
22 changed files with 223 additions and 369 deletions

View file

@ -944,16 +944,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
trait_item_span,
trait_path,
} => {
let mut err = self.dcx().struct_span_err_with_code(
self.dcx().struct_span_err_with_code(
span,
format!(
"item `{name}` is an associated {kind}, which doesn't match its trait `{trait_path}`",
),
code,
);
err.span_label(span, "does not match trait");
err.span_label(trait_item_span, "item in trait");
err
)
.span_label_mv(span, "does not match trait")
.span_label_mv(trait_item_span, "item in trait")
}
ResolutionError::TraitImplDuplicate { name, trait_item_span, old_span } => self
.dcx()

View file

@ -2603,25 +2603,23 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
) {
debug_assert_ne!(lifetime_ref.ident.name, kw::UnderscoreLifetime);
let mut err = if let Some(outer) = outer_lifetime_ref {
let mut err = struct_span_err!(
struct_span_err!(
self.r.dcx(),
lifetime_ref.ident.span,
E0401,
"can't use generic parameters from outer item",
);
err.span_label(lifetime_ref.ident.span, "use of generic parameter from outer item");
err.span_label(outer.span, "lifetime parameter from outer item");
err
)
.span_label_mv(lifetime_ref.ident.span, "use of generic parameter from outer item")
.span_label_mv(outer.span, "lifetime parameter from outer item")
} else {
let mut err = struct_span_err!(
struct_span_err!(
self.r.dcx(),
lifetime_ref.ident.span,
E0261,
"use of undeclared lifetime name `{}`",
lifetime_ref.ident
);
err.span_label(lifetime_ref.ident.span, "undeclared lifetime");
err
)
.span_label_mv(lifetime_ref.ident.span, "undeclared lifetime")
};
self.suggest_introducing_lifetime(
&mut err,