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
|
@ -30,9 +30,7 @@ where
|
|||
G: EmissionGuarantee,
|
||||
{
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
||||
let mut diag = self.node.into_diagnostic(dcx, level);
|
||||
diag.span(self.span);
|
||||
diag
|
||||
self.node.into_diagnostic(dcx, level).span_mv(self.span)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -249,60 +249,43 @@ impl<Id> IntoDiagnosticArg for hir::def::Res<Id> {
|
|||
|
||||
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetDataLayoutErrors<'_> {
|
||||
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||
let mut diag;
|
||||
match self {
|
||||
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
|
||||
diag =
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_address_space);
|
||||
diag.arg("addr_space", addr_space);
|
||||
diag.arg("cause", cause);
|
||||
diag.arg("err", err);
|
||||
diag
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_address_space)
|
||||
.arg_mv("addr_space", addr_space)
|
||||
.arg_mv("cause", cause)
|
||||
.arg_mv("err", err)
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => {
|
||||
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits);
|
||||
diag.arg("kind", kind);
|
||||
diag.arg("bit", bit);
|
||||
diag.arg("cause", cause);
|
||||
diag.arg("err", err);
|
||||
diag
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits)
|
||||
.arg_mv("kind", kind)
|
||||
.arg_mv("bit", bit)
|
||||
.arg_mv("cause", cause)
|
||||
.arg_mv("err", err)
|
||||
}
|
||||
TargetDataLayoutErrors::MissingAlignment { cause } => {
|
||||
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_missing_alignment);
|
||||
diag.arg("cause", cause);
|
||||
diag
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_missing_alignment)
|
||||
.arg_mv("cause", cause)
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidAlignment { cause, err } => {
|
||||
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_alignment);
|
||||
diag.arg("cause", cause);
|
||||
diag.arg("err_kind", err.diag_ident());
|
||||
diag.arg("align", err.align());
|
||||
diag
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_alignment)
|
||||
.arg_mv("cause", cause)
|
||||
.arg_mv("err_kind", err.diag_ident())
|
||||
.arg_mv("align", err.align())
|
||||
}
|
||||
TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => {
|
||||
diag = DiagnosticBuilder::new(
|
||||
dcx,
|
||||
level,
|
||||
fluent::errors_target_inconsistent_architecture,
|
||||
);
|
||||
diag.arg("dl", dl);
|
||||
diag.arg("target", target);
|
||||
diag
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_inconsistent_architecture)
|
||||
.arg_mv("dl", dl)
|
||||
.arg_mv("target", target)
|
||||
}
|
||||
TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => {
|
||||
diag = DiagnosticBuilder::new(
|
||||
dcx,
|
||||
level,
|
||||
fluent::errors_target_inconsistent_pointer_width,
|
||||
);
|
||||
diag.arg("pointer_size", pointer_size);
|
||||
diag.arg("target", target);
|
||||
diag
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_inconsistent_pointer_width)
|
||||
.arg_mv("pointer_size", pointer_size)
|
||||
.arg_mv("target", target)
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidBitsSize { err } => {
|
||||
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits_size);
|
||||
diag.arg("err", err);
|
||||
diag
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits_size)
|
||||
.arg_mv("err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -729,9 +729,7 @@ impl DiagCtxt {
|
|||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
let mut result = self.struct_warn(msg);
|
||||
result.span(span);
|
||||
result
|
||||
self.struct_warn(msg).span_mv(span)
|
||||
}
|
||||
|
||||
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
|
||||
|
@ -744,9 +742,7 @@ impl DiagCtxt {
|
|||
msg: impl Into<DiagnosticMessage>,
|
||||
code: DiagnosticId,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
let mut result = self.struct_span_warn(span, msg);
|
||||
result.code(code);
|
||||
result
|
||||
self.struct_span_warn(span, msg).code_mv(code)
|
||||
}
|
||||
|
||||
/// Construct a builder at the `Warning` level with the `msg`.
|
||||
|
@ -786,9 +782,7 @@ impl DiagCtxt {
|
|||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
let mut result = self.struct_err(msg);
|
||||
result.span(span);
|
||||
result
|
||||
self.struct_err(msg).span_mv(span)
|
||||
}
|
||||
|
||||
/// Construct a builder at the `Error` level at the given `span`, with the `msg`, and `code`.
|
||||
|
@ -800,9 +794,7 @@ impl DiagCtxt {
|
|||
msg: impl Into<DiagnosticMessage>,
|
||||
code: DiagnosticId,
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
let mut result = self.struct_span_err(span, msg);
|
||||
result.code(code);
|
||||
result
|
||||
self.struct_span_err(span, msg).code_mv(code)
|
||||
}
|
||||
|
||||
/// Construct a builder at the `Error` level with the `msg`.
|
||||
|
@ -821,9 +813,7 @@ impl DiagCtxt {
|
|||
msg: impl Into<DiagnosticMessage>,
|
||||
code: DiagnosticId,
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
let mut result = self.struct_err(msg);
|
||||
result.code(code);
|
||||
result
|
||||
self.struct_err(msg).code_mv(code)
|
||||
}
|
||||
|
||||
/// Construct a builder at the `Warn` level with the `msg` and the `code`.
|
||||
|
@ -834,9 +824,7 @@ impl DiagCtxt {
|
|||
msg: impl Into<DiagnosticMessage>,
|
||||
code: DiagnosticId,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
let mut result = self.struct_warn(msg);
|
||||
result.code(code);
|
||||
result
|
||||
self.struct_warn(msg).code_mv(code)
|
||||
}
|
||||
|
||||
/// Construct a builder at the `Fatal` level at the given `span` and with the `msg`.
|
||||
|
@ -847,9 +835,7 @@ impl DiagCtxt {
|
|||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, FatalAbort> {
|
||||
let mut result = self.struct_fatal(msg);
|
||||
result.span(span);
|
||||
result
|
||||
self.struct_fatal(msg).span_mv(span)
|
||||
}
|
||||
|
||||
/// Construct a builder at the `Fatal` level at the given `span`, with the `msg`, and `code`.
|
||||
|
@ -861,9 +847,7 @@ impl DiagCtxt {
|
|||
msg: impl Into<DiagnosticMessage>,
|
||||
code: DiagnosticId,
|
||||
) -> DiagnosticBuilder<'_, FatalAbort> {
|
||||
let mut result = self.struct_span_fatal(span, msg);
|
||||
result.code(code);
|
||||
result
|
||||
self.struct_span_fatal(span, msg).code_mv(code)
|
||||
}
|
||||
|
||||
/// Construct a builder at the `Fatal` level with the `msg`.
|
||||
|
@ -904,9 +888,7 @@ impl DiagCtxt {
|
|||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, BugAbort> {
|
||||
let mut result = self.struct_bug(msg);
|
||||
result.span(span);
|
||||
result
|
||||
self.struct_bug(msg).span_mv(span)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
|
@ -1021,9 +1003,7 @@ impl DiagCtxt {
|
|||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
let mut db = DiagnosticBuilder::new(self, Note, msg);
|
||||
db.span(span);
|
||||
db
|
||||
DiagnosticBuilder::new(self, Note, msg).span_mv(span)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue