Inline and remove more DiagnosticBuilder::new_diagnostic_*
functions.
They each have a single call site. Note: the `make_diagnostic_builder` calls in `lib.rs` will be replaced in a subsequent commit.
This commit is contained in:
parent
d4933aaf1f
commit
ab640ca86b
@ -116,26 +116,6 @@ pub trait EmissionGuarantee: Sized {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
impl<'a> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||||
/// Convenience function for internal use, clients should use one of the
|
|
||||||
/// `struct_*` methods on [`Handler`].
|
|
||||||
#[track_caller]
|
|
||||||
pub(crate) fn new_guaranteeing_error<M: Into<DiagnosticMessage>>(
|
|
||||||
handler: &'a Handler,
|
|
||||||
message: M,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
inner: DiagnosticBuilderInner {
|
|
||||||
state: DiagnosticBuilderState::Emittable(handler),
|
|
||||||
diagnostic: Box::new(Diagnostic::new_with_code(
|
|
||||||
Level::Error { lint: false },
|
|
||||||
None,
|
|
||||||
message,
|
|
||||||
)),
|
|
||||||
},
|
|
||||||
_marker: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Discard the guarantee `.emit()` would return, in favor of having the
|
/// Discard the guarantee `.emit()` would return, in favor of having the
|
||||||
/// type `DiagnosticBuilder<'a, ()>`. This may be necessary whenever there
|
/// type `DiagnosticBuilder<'a, ()>`. This may be necessary whenever there
|
||||||
/// is a common codepath handling both errors and warnings.
|
/// is a common codepath handling both errors and warnings.
|
||||||
@ -189,7 +169,13 @@ impl EmissionGuarantee for ErrorGuaranteed {
|
|||||||
handler: &Handler,
|
handler: &Handler,
|
||||||
msg: impl Into<DiagnosticMessage>,
|
msg: impl Into<DiagnosticMessage>,
|
||||||
) -> DiagnosticBuilder<'_, Self> {
|
) -> DiagnosticBuilder<'_, Self> {
|
||||||
DiagnosticBuilder::new_guaranteeing_error(handler, msg)
|
DiagnosticBuilder {
|
||||||
|
inner: DiagnosticBuilderInner {
|
||||||
|
state: DiagnosticBuilderState::Emittable(handler),
|
||||||
|
diagnostic: Box::new(Diagnostic::new(Level::Error { lint: false }, msg)),
|
||||||
|
},
|
||||||
|
_marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,21 +235,6 @@ impl EmissionGuarantee for () {
|
|||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Noted;
|
pub struct Noted;
|
||||||
|
|
||||||
impl<'a> DiagnosticBuilder<'a, Noted> {
|
|
||||||
/// Convenience function for internal use, clients should use one of the
|
|
||||||
/// `struct_*` methods on [`Handler`].
|
|
||||||
pub(crate) fn new_note(handler: &'a Handler, message: impl Into<DiagnosticMessage>) -> Self {
|
|
||||||
let diagnostic = Diagnostic::new_with_code(Level::Note, None, message);
|
|
||||||
Self {
|
|
||||||
inner: DiagnosticBuilderInner {
|
|
||||||
state: DiagnosticBuilderState::Emittable(handler),
|
|
||||||
diagnostic: Box::new(diagnostic),
|
|
||||||
},
|
|
||||||
_marker: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EmissionGuarantee for Noted {
|
impl EmissionGuarantee for Noted {
|
||||||
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||||
match db.inner.state {
|
match db.inner.state {
|
||||||
@ -283,7 +254,13 @@ impl EmissionGuarantee for Noted {
|
|||||||
handler: &Handler,
|
handler: &Handler,
|
||||||
msg: impl Into<DiagnosticMessage>,
|
msg: impl Into<DiagnosticMessage>,
|
||||||
) -> DiagnosticBuilder<'_, Self> {
|
) -> DiagnosticBuilder<'_, Self> {
|
||||||
DiagnosticBuilder::new_note(handler, msg)
|
DiagnosticBuilder {
|
||||||
|
inner: DiagnosticBuilderInner {
|
||||||
|
state: DiagnosticBuilderState::Emittable(handler),
|
||||||
|
diagnostic: Box::new(Diagnostic::new_with_code(Level::Note, None, msg)),
|
||||||
|
},
|
||||||
|
_marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,22 +269,6 @@ impl EmissionGuarantee for Noted {
|
|||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Bug;
|
pub struct Bug;
|
||||||
|
|
||||||
impl<'a> DiagnosticBuilder<'a, Bug> {
|
|
||||||
/// Convenience function for internal use, clients should use one of the
|
|
||||||
/// `struct_*` methods on [`Handler`].
|
|
||||||
#[track_caller]
|
|
||||||
pub(crate) fn new_bug(handler: &'a Handler, message: impl Into<DiagnosticMessage>) -> Self {
|
|
||||||
let diagnostic = Diagnostic::new_with_code(Level::Bug, None, message);
|
|
||||||
Self {
|
|
||||||
inner: DiagnosticBuilderInner {
|
|
||||||
state: DiagnosticBuilderState::Emittable(handler),
|
|
||||||
diagnostic: Box::new(diagnostic),
|
|
||||||
},
|
|
||||||
_marker: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EmissionGuarantee for Bug {
|
impl EmissionGuarantee for Bug {
|
||||||
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||||
match db.inner.state {
|
match db.inner.state {
|
||||||
@ -328,19 +289,10 @@ impl EmissionGuarantee for Bug {
|
|||||||
handler: &Handler,
|
handler: &Handler,
|
||||||
msg: impl Into<DiagnosticMessage>,
|
msg: impl Into<DiagnosticMessage>,
|
||||||
) -> DiagnosticBuilder<'_, Self> {
|
) -> DiagnosticBuilder<'_, Self> {
|
||||||
DiagnosticBuilder::new_bug(handler, msg)
|
DiagnosticBuilder {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> DiagnosticBuilder<'a, !> {
|
|
||||||
/// Convenience function for internal use, clients should use one of the
|
|
||||||
/// `struct_*` methods on [`Handler`].
|
|
||||||
#[track_caller]
|
|
||||||
pub(crate) fn new_fatal(handler: &'a Handler, message: impl Into<DiagnosticMessage>) -> Self {
|
|
||||||
Self {
|
|
||||||
inner: DiagnosticBuilderInner {
|
inner: DiagnosticBuilderInner {
|
||||||
state: DiagnosticBuilderState::Emittable(handler),
|
state: DiagnosticBuilderState::Emittable(handler),
|
||||||
diagnostic: Box::new(Diagnostic::new_with_code(Level::Fatal, None, message)),
|
diagnostic: Box::new(Diagnostic::new_with_code(Level::Bug, None, msg)),
|
||||||
},
|
},
|
||||||
_marker: PhantomData,
|
_marker: PhantomData,
|
||||||
}
|
}
|
||||||
@ -367,23 +319,10 @@ impl EmissionGuarantee for ! {
|
|||||||
handler: &Handler,
|
handler: &Handler,
|
||||||
msg: impl Into<DiagnosticMessage>,
|
msg: impl Into<DiagnosticMessage>,
|
||||||
) -> DiagnosticBuilder<'_, Self> {
|
) -> DiagnosticBuilder<'_, Self> {
|
||||||
DiagnosticBuilder::new_fatal(handler, msg)
|
DiagnosticBuilder {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> DiagnosticBuilder<'a, rustc_span::fatal_error::FatalError> {
|
|
||||||
/// Convenience function for internal use, clients should use one of the
|
|
||||||
/// `struct_*` methods on [`Handler`].
|
|
||||||
#[track_caller]
|
|
||||||
pub(crate) fn new_almost_fatal(
|
|
||||||
handler: &'a Handler,
|
|
||||||
message: impl Into<DiagnosticMessage>,
|
|
||||||
) -> Self {
|
|
||||||
let diagnostic = Diagnostic::new_with_code(Level::Fatal, None, message);
|
|
||||||
Self {
|
|
||||||
inner: DiagnosticBuilderInner {
|
inner: DiagnosticBuilderInner {
|
||||||
state: DiagnosticBuilderState::Emittable(handler),
|
state: DiagnosticBuilderState::Emittable(handler),
|
||||||
diagnostic: Box::new(diagnostic),
|
diagnostic: Box::new(Diagnostic::new_with_code(Level::Fatal, None, msg)),
|
||||||
},
|
},
|
||||||
_marker: PhantomData,
|
_marker: PhantomData,
|
||||||
}
|
}
|
||||||
@ -410,7 +349,13 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
|
|||||||
handler: &Handler,
|
handler: &Handler,
|
||||||
msg: impl Into<DiagnosticMessage>,
|
msg: impl Into<DiagnosticMessage>,
|
||||||
) -> DiagnosticBuilder<'_, Self> {
|
) -> DiagnosticBuilder<'_, Self> {
|
||||||
DiagnosticBuilder::new_almost_fatal(handler, msg)
|
DiagnosticBuilder {
|
||||||
|
inner: DiagnosticBuilderInner {
|
||||||
|
state: DiagnosticBuilderState::Emittable(handler),
|
||||||
|
diagnostic: Box::new(Diagnostic::new_with_code(Level::Fatal, None, msg)),
|
||||||
|
},
|
||||||
|
_marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,7 +776,7 @@ impl Handler {
|
|||||||
#[rustc_lint_diagnostics]
|
#[rustc_lint_diagnostics]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||||
DiagnosticBuilder::new(self, Level::Warning(None), msg)
|
<()>::make_diagnostic_builder(self, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a builder at the `Warning` level with the `msg`. The `id` is used for
|
/// Construct a builder at the `Warning` level with the `msg`. The `id` is used for
|
||||||
@ -847,7 +847,7 @@ impl Handler {
|
|||||||
&self,
|
&self,
|
||||||
msg: impl Into<DiagnosticMessage>,
|
msg: impl Into<DiagnosticMessage>,
|
||||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||||
DiagnosticBuilder::new_guaranteeing_error(self, msg)
|
ErrorGuaranteed::make_diagnostic_builder(self, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors.
|
/// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors.
|
||||||
@ -914,7 +914,7 @@ impl Handler {
|
|||||||
#[rustc_lint_diagnostics]
|
#[rustc_lint_diagnostics]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
|
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
|
||||||
DiagnosticBuilder::new_fatal(self, msg)
|
<!>::make_diagnostic_builder(self, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a builder at the `Help` level with the `msg`.
|
/// Construct a builder at the `Help` level with the `msg`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user