Rename some Diagnostic
setters.
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
This commit is contained in:
parent
e51e98dde6
commit
505c1371d0
53 changed files with 274 additions and 281 deletions
|
@ -212,6 +212,9 @@ impl StringPart {
|
|||
}
|
||||
}
|
||||
|
||||
// Note: most of these methods are setters that return `&mut Self`. The small
|
||||
// number of simple getter functions all have `get_` prefixes to distinguish
|
||||
// them from the setters.
|
||||
impl Diagnostic {
|
||||
#[track_caller]
|
||||
pub fn new<M: Into<DiagnosticMessage>>(level: Level, message: M) -> Self {
|
||||
|
@ -344,7 +347,7 @@ impl Diagnostic {
|
|||
|
||||
pub fn replace_span_with(&mut self, after: Span, keep_label: bool) -> &mut Self {
|
||||
let before = self.span.clone();
|
||||
self.set_span(after);
|
||||
self.span(after);
|
||||
for span_label in before.span_labels() {
|
||||
if let Some(label) = span_label.label {
|
||||
if span_label.is_primary && keep_label {
|
||||
|
@ -876,7 +879,7 @@ impl Diagnostic {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
|
||||
pub fn span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
|
||||
self.span = sp.into();
|
||||
if let Some(span) = self.span.primary_span() {
|
||||
self.sort_span = span;
|
||||
|
@ -884,7 +887,7 @@ impl Diagnostic {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn set_is_lint(&mut self) -> &mut Self {
|
||||
pub fn is_lint(&mut self) -> &mut Self {
|
||||
self.is_lint = true;
|
||||
self
|
||||
}
|
||||
|
@ -903,7 +906,7 @@ impl Diagnostic {
|
|||
self.code.clone()
|
||||
}
|
||||
|
||||
pub fn set_primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self {
|
||||
pub fn primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self {
|
||||
self.messages[0] = (msg.into(), Style::NoStyle);
|
||||
self
|
||||
}
|
||||
|
@ -915,7 +918,7 @@ impl Diagnostic {
|
|||
self.args.iter()
|
||||
}
|
||||
|
||||
pub fn set_arg(
|
||||
pub fn arg(
|
||||
&mut self,
|
||||
name: impl Into<Cow<'static, str>>,
|
||||
arg: impl IntoDiagnosticArg,
|
||||
|
|
|
@ -31,7 +31,7 @@ where
|
|||
{
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
||||
let mut diag = self.node.into_diagnostic(dcx, level);
|
||||
diag.set_span(self.span);
|
||||
diag.span(self.span);
|
||||
diag
|
||||
}
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
sp: impl Into<MultiSpan>,
|
||||
msg: impl Into<SubdiagnosticMessage>,
|
||||
) -> &mut Self);
|
||||
forward!(pub fn set_is_lint(&mut self,) -> &mut Self);
|
||||
forward!(pub fn is_lint(&mut self,) -> &mut Self);
|
||||
|
||||
forward!(pub fn disable_suggestions(&mut self,) -> &mut Self);
|
||||
|
||||
|
@ -499,10 +499,10 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
applicability: Applicability,
|
||||
) -> &mut Self);
|
||||
|
||||
forward!(pub fn set_primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self);
|
||||
forward!(pub fn set_span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self);
|
||||
forward!(pub fn primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self);
|
||||
forward!(pub fn span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self);
|
||||
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
||||
forward!(pub fn set_arg(
|
||||
forward!(pub fn arg(
|
||||
&mut self,
|
||||
name: impl Into<Cow<'static, str>>,
|
||||
arg: impl IntoDiagnosticArg,
|
||||
|
|
|
@ -254,29 +254,29 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetDataLayoutErrors<'_>
|
|||
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
|
||||
diag =
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_address_space);
|
||||
diag.set_arg("addr_space", addr_space);
|
||||
diag.set_arg("cause", cause);
|
||||
diag.set_arg("err", err);
|
||||
diag.arg("addr_space", addr_space);
|
||||
diag.arg("cause", cause);
|
||||
diag.arg("err", err);
|
||||
diag
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => {
|
||||
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits);
|
||||
diag.set_arg("kind", kind);
|
||||
diag.set_arg("bit", bit);
|
||||
diag.set_arg("cause", cause);
|
||||
diag.set_arg("err", err);
|
||||
diag.arg("kind", kind);
|
||||
diag.arg("bit", bit);
|
||||
diag.arg("cause", cause);
|
||||
diag.arg("err", err);
|
||||
diag
|
||||
}
|
||||
TargetDataLayoutErrors::MissingAlignment { cause } => {
|
||||
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_missing_alignment);
|
||||
diag.set_arg("cause", cause);
|
||||
diag.arg("cause", cause);
|
||||
diag
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidAlignment { cause, err } => {
|
||||
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_alignment);
|
||||
diag.set_arg("cause", cause);
|
||||
diag.set_arg("err_kind", err.diag_ident());
|
||||
diag.set_arg("align", err.align());
|
||||
diag.arg("cause", cause);
|
||||
diag.arg("err_kind", err.diag_ident());
|
||||
diag.arg("align", err.align());
|
||||
diag
|
||||
}
|
||||
TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => {
|
||||
|
@ -285,8 +285,8 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetDataLayoutErrors<'_>
|
|||
level,
|
||||
fluent::errors_target_inconsistent_architecture,
|
||||
);
|
||||
diag.set_arg("dl", dl);
|
||||
diag.set_arg("target", target);
|
||||
diag.arg("dl", dl);
|
||||
diag.arg("target", target);
|
||||
diag
|
||||
}
|
||||
TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => {
|
||||
|
@ -295,13 +295,13 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetDataLayoutErrors<'_>
|
|||
level,
|
||||
fluent::errors_target_inconsistent_pointer_width,
|
||||
);
|
||||
diag.set_arg("pointer_size", pointer_size);
|
||||
diag.set_arg("target", target);
|
||||
diag.arg("pointer_size", pointer_size);
|
||||
diag.arg("target", target);
|
||||
diag
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidBitsSize { err } => {
|
||||
diag = DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits_size);
|
||||
diag.set_arg("err", err);
|
||||
diag.arg("err", err);
|
||||
diag
|
||||
}
|
||||
}
|
||||
|
|
|
@ -732,7 +732,7 @@ impl DiagCtxt {
|
|||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
let mut result = self.struct_warn(msg);
|
||||
result.set_span(span);
|
||||
result.span(span);
|
||||
result
|
||||
}
|
||||
|
||||
|
@ -789,7 +789,7 @@ impl DiagCtxt {
|
|||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
let mut result = self.struct_err(msg);
|
||||
result.set_span(span);
|
||||
result.span(span);
|
||||
result
|
||||
}
|
||||
|
||||
|
@ -850,7 +850,7 @@ impl DiagCtxt {
|
|||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, FatalAbort> {
|
||||
let mut result = self.struct_fatal(msg);
|
||||
result.set_span(span);
|
||||
result.span(span);
|
||||
result
|
||||
}
|
||||
|
||||
|
@ -917,7 +917,7 @@ impl DiagCtxt {
|
|||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, BugAbort> {
|
||||
let mut result = self.struct_bug(msg);
|
||||
result.set_span(span);
|
||||
result.span(span);
|
||||
result
|
||||
}
|
||||
|
||||
|
@ -1008,7 +1008,7 @@ impl DiagCtxt {
|
|||
self.span_bug(sp, msg);
|
||||
}
|
||||
let mut diagnostic = Diagnostic::new(DelayedBug, msg);
|
||||
diagnostic.set_span(sp);
|
||||
diagnostic.span(sp);
|
||||
self.emit_diagnostic(diagnostic).unwrap()
|
||||
}
|
||||
|
||||
|
@ -1039,7 +1039,7 @@ impl DiagCtxt {
|
|||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
let mut db = DiagnosticBuilder::new(self, Note, msg);
|
||||
db.set_span(span);
|
||||
db.span(span);
|
||||
db
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue