Replace &mut DiagnosticBuilder
, in signatures, with &mut Diagnostic
.
This commit is contained in:
parent
f24ff1815f
commit
02ff9e0aef
65 changed files with 369 additions and 466 deletions
|
@ -202,6 +202,20 @@ impl Diagnostic {
|
|||
self
|
||||
}
|
||||
|
||||
/// Labels all the given spans with the provided label.
|
||||
/// See [`Self::span_label()`] for more information.
|
||||
pub fn span_labels(
|
||||
&mut self,
|
||||
spans: impl IntoIterator<Item = Span>,
|
||||
label: impl AsRef<str>,
|
||||
) -> &mut Self {
|
||||
let label = label.as_ref();
|
||||
for span in spans {
|
||||
self.span_label(span, label);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn replace_span_with(&mut self, after: Span) -> &mut Self {
|
||||
let before = self.span.clone();
|
||||
self.set_span(after);
|
||||
|
@ -213,7 +227,7 @@ impl Diagnostic {
|
|||
self
|
||||
}
|
||||
|
||||
crate fn note_expected_found(
|
||||
pub fn note_expected_found(
|
||||
&mut self,
|
||||
expected_label: &dyn fmt::Display,
|
||||
expected: DiagnosticStyledString,
|
||||
|
@ -223,7 +237,7 @@ impl Diagnostic {
|
|||
self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"")
|
||||
}
|
||||
|
||||
crate fn note_unsuccessful_coercion(
|
||||
pub fn note_unsuccessful_coercion(
|
||||
&mut self,
|
||||
expected: DiagnosticStyledString,
|
||||
found: DiagnosticStyledString,
|
||||
|
@ -313,33 +327,33 @@ impl Diagnostic {
|
|||
|
||||
/// Prints the span with a note above it.
|
||||
/// This is like [`Diagnostic::note()`], but it gets its own span.
|
||||
crate fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
||||
pub fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
||||
self.sub(Level::Note, msg, sp.into(), None);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add a warning attached to this diagnostic.
|
||||
crate fn warn(&mut self, msg: &str) -> &mut Self {
|
||||
pub fn warn(&mut self, msg: &str) -> &mut Self {
|
||||
self.sub(Level::Warning, msg, MultiSpan::new(), None);
|
||||
self
|
||||
}
|
||||
|
||||
/// Prints the span with a warning above it.
|
||||
/// This is like [`Diagnostic::warn()`], but it gets its own span.
|
||||
crate fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
||||
pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
||||
self.sub(Level::Warning, msg, sp.into(), None);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add a help message attached to this diagnostic.
|
||||
crate fn help(&mut self, msg: &str) -> &mut Self {
|
||||
pub fn help(&mut self, msg: &str) -> &mut Self {
|
||||
self.sub(Level::Help, msg, MultiSpan::new(), None);
|
||||
self
|
||||
}
|
||||
|
||||
/// Prints the span with some help above it.
|
||||
/// This is like [`Diagnostic::help()`], but it gets its own span.
|
||||
crate fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
||||
pub fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
|
||||
self.sub(Level::Help, msg, sp.into(), None);
|
||||
self
|
||||
}
|
||||
|
@ -673,7 +687,7 @@ impl Diagnostic {
|
|||
self.code.clone()
|
||||
}
|
||||
|
||||
crate fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self {
|
||||
pub fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self {
|
||||
self.message[0] = (msg.into(), Style::NoStyle);
|
||||
self
|
||||
}
|
||||
|
|
|
@ -59,23 +59,6 @@ macro_rules! forward {
|
|||
self
|
||||
}
|
||||
};
|
||||
|
||||
// Forward pattern for &mut self -> &mut Self, with generic parameters.
|
||||
(
|
||||
$(#[$attrs:meta])*
|
||||
pub fn $n:ident<$($generic:ident: $bound:path),*>(
|
||||
&mut self,
|
||||
$($name:ident: $ty:ty),*
|
||||
$(,)?
|
||||
) -> &mut Self
|
||||
) => {
|
||||
$(#[$attrs])*
|
||||
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
|
||||
pub fn $n<$($generic: $bound),*>(&mut self, $($name: $ty),*) -> &mut Self {
|
||||
self.diagnostic.$n($($name),*);
|
||||
self
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<'a> Deref for DiagnosticBuilder<'a> {
|
||||
|
@ -172,6 +155,7 @@ impl<'a> DiagnosticBuilder<'a> {
|
|||
pub fn downgrade_to_delayed_bug(&mut self,) -> &mut Self
|
||||
);
|
||||
|
||||
forward!(
|
||||
/// Appends a labeled span to the diagnostic.
|
||||
///
|
||||
/// Labels are used to convey additional context for the diagnostic's primary span. They will
|
||||
|
@ -184,24 +168,16 @@ impl<'a> DiagnosticBuilder<'a> {
|
|||
/// the diagnostic was constructed. However, the label span is *not* considered a
|
||||
/// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is
|
||||
/// primary.
|
||||
pub fn span_label(&mut self, span: Span, label: impl Into<String>) -> &mut Self {
|
||||
self.diagnostic.span_label(span, label);
|
||||
self
|
||||
}
|
||||
pub fn span_label(&mut self, span: Span, label: impl Into<String>) -> &mut Self);
|
||||
|
||||
forward!(
|
||||
/// Labels all the given spans with the provided label.
|
||||
/// See [`Diagnostic::span_label()`] for more information.
|
||||
pub fn span_labels(
|
||||
&mut self,
|
||||
spans: impl IntoIterator<Item = Span>,
|
||||
label: impl AsRef<str>,
|
||||
) -> &mut Self {
|
||||
let label = label.as_ref();
|
||||
for span in spans {
|
||||
self.diagnostic.span_label(span, label);
|
||||
}
|
||||
self
|
||||
}
|
||||
) -> &mut Self);
|
||||
|
||||
forward!(pub fn note_expected_found(
|
||||
&mut self,
|
||||
|
@ -228,17 +204,17 @@ impl<'a> DiagnosticBuilder<'a> {
|
|||
) -> &mut Self);
|
||||
|
||||
forward!(pub fn note(&mut self, msg: &str) -> &mut Self);
|
||||
forward!(pub fn span_note<S: Into<MultiSpan>>(
|
||||
forward!(pub fn span_note(
|
||||
&mut self,
|
||||
sp: S,
|
||||
sp: impl Into<MultiSpan>,
|
||||
msg: &str,
|
||||
) -> &mut Self);
|
||||
forward!(pub fn warn(&mut self, msg: &str) -> &mut Self);
|
||||
forward!(pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self);
|
||||
forward!(pub fn span_warn(&mut self, sp: impl Into<MultiSpan>, msg: &str) -> &mut Self);
|
||||
forward!(pub fn help(&mut self, msg: &str) -> &mut Self);
|
||||
forward!(pub fn span_help<S: Into<MultiSpan>>(
|
||||
forward!(pub fn span_help(
|
||||
&mut self,
|
||||
sp: S,
|
||||
sp: impl Into<MultiSpan>,
|
||||
msg: &str,
|
||||
) -> &mut Self);
|
||||
forward!(pub fn set_is_lint(&mut self,) -> &mut Self);
|
||||
|
@ -312,8 +288,8 @@ impl<'a> DiagnosticBuilder<'a> {
|
|||
applicability: Applicability,
|
||||
) -> &mut Self);
|
||||
|
||||
forward!(pub fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self);
|
||||
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
|
||||
forward!(pub fn set_primary_message(&mut self, msg: impl Into<String>) -> &mut Self);
|
||||
forward!(pub fn set_span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self);
|
||||
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
||||
|
||||
/// Convenience function for internal use, clients should use one of the
|
||||
|
|
|
@ -1319,9 +1319,10 @@ impl Level {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME(eddyb) this doesn't belong here AFAICT, should be moved to callsite.
|
||||
pub fn add_elided_lifetime_in_path_suggestion(
|
||||
source_map: &SourceMap,
|
||||
db: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diagnostic,
|
||||
n: usize,
|
||||
path_span: Span,
|
||||
incl_angl_brckt: bool,
|
||||
|
@ -1353,7 +1354,7 @@ pub fn add_elided_lifetime_in_path_suggestion(
|
|||
(insertion_span, anon_lts)
|
||||
}
|
||||
};
|
||||
db.span_suggestion(
|
||||
diag.span_suggestion(
|
||||
replace_span,
|
||||
&format!("indicate the anonymous lifetime{}", pluralize!(n)),
|
||||
suggestion,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue