Rename DiagnosticBuilder
as Diag
.
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
This commit is contained in:
parent
4e1f9bd528
commit
899cb40809
153 changed files with 1136 additions and 1367 deletions
|
@ -45,29 +45,29 @@ pub enum DiagnosticArgValue {
|
|||
|
||||
pub type DiagnosticArgMap = FxIndexMap<DiagnosticArgName, DiagnosticArgValue>;
|
||||
|
||||
/// Trait for types that `DiagnosticBuilder::emit` can return as a "guarantee"
|
||||
/// (or "proof") token that the emission happened.
|
||||
/// Trait for types that `Diag::emit` can return as a "guarantee" (or "proof")
|
||||
/// token that the emission happened.
|
||||
pub trait EmissionGuarantee: Sized {
|
||||
/// This exists so that bugs and fatal errors can both result in `!` (an
|
||||
/// abort) when emitted, but have different aborting behaviour.
|
||||
type EmitResult = Self;
|
||||
|
||||
/// Implementation of `DiagnosticBuilder::emit`, fully controlled by each
|
||||
/// `impl` of `EmissionGuarantee`, to make it impossible to create a value
|
||||
/// of `Self::EmitResult` without actually performing the emission.
|
||||
/// Implementation of `Diag::emit`, fully controlled by each `impl` of
|
||||
/// `EmissionGuarantee`, to make it impossible to create a value of
|
||||
/// `Self::EmitResult` without actually performing the emission.
|
||||
#[track_caller]
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult;
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult;
|
||||
}
|
||||
|
||||
impl EmissionGuarantee for ErrorGuaranteed {
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
|
||||
db.emit_producing_error_guaranteed()
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult {
|
||||
diag.emit_producing_error_guaranteed()
|
||||
}
|
||||
}
|
||||
|
||||
impl EmissionGuarantee for () {
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
|
||||
db.emit_producing_nothing();
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult {
|
||||
diag.emit_producing_nothing();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,8 @@ pub struct BugAbort;
|
|||
impl EmissionGuarantee for BugAbort {
|
||||
type EmitResult = !;
|
||||
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
|
||||
db.emit_producing_nothing();
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult {
|
||||
diag.emit_producing_nothing();
|
||||
panic::panic_any(ExplicitBug);
|
||||
}
|
||||
}
|
||||
|
@ -93,15 +93,15 @@ pub struct FatalAbort;
|
|||
impl EmissionGuarantee for FatalAbort {
|
||||
type EmitResult = !;
|
||||
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
|
||||
db.emit_producing_nothing();
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult {
|
||||
diag.emit_producing_nothing();
|
||||
crate::FatalError.raise()
|
||||
}
|
||||
}
|
||||
|
||||
impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
|
||||
db.emit_producing_nothing();
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult {
|
||||
diag.emit_producing_nothing();
|
||||
rustc_span::fatal_error::FatalError
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
|
|||
pub trait IntoDiagnostic<'a, G: EmissionGuarantee = ErrorGuaranteed> {
|
||||
/// Write out as a diagnostic out of `DiagCtxt`.
|
||||
#[must_use]
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G>;
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G>;
|
||||
}
|
||||
|
||||
impl<'a, T, G> IntoDiagnostic<'a, G> for Spanned<T>
|
||||
|
@ -120,7 +120,7 @@ where
|
|||
T: IntoDiagnostic<'a, G>,
|
||||
G: EmissionGuarantee,
|
||||
{
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
|
||||
self.node.into_diagnostic(dcx, level).with_span(self.span)
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ where
|
|||
Self: Sized,
|
||||
{
|
||||
/// Add a subdiagnostic to an existing diagnostic.
|
||||
fn add_to_diagnostic<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
|
||||
fn add_to_diagnostic<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
self.add_to_diagnostic_with(diag, |_, m| m);
|
||||
}
|
||||
|
||||
|
@ -165,20 +165,20 @@ where
|
|||
/// (to optionally perform eager translation).
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
f: F,
|
||||
);
|
||||
}
|
||||
|
||||
pub trait SubdiagnosticMessageOp<G> =
|
||||
Fn(&mut DiagnosticBuilder<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage;
|
||||
Fn(&mut Diag<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage;
|
||||
|
||||
/// Trait implemented by lint types. This should not be implemented manually. Instead, use
|
||||
/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
|
||||
#[rustc_diagnostic_item = "DecorateLint"]
|
||||
pub trait DecorateLint<'a, G: EmissionGuarantee> {
|
||||
/// Decorate and emit a lint.
|
||||
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, G>);
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>);
|
||||
|
||||
fn msg(&self) -> DiagnosticMessage;
|
||||
}
|
||||
|
@ -261,10 +261,10 @@ impl StringPart {
|
|||
}
|
||||
}
|
||||
|
||||
/// The main part of a diagnostic. Note that `DiagnosticBuilder`, which wraps
|
||||
/// this type, is used for most operations, and should be used instead whenever
|
||||
/// possible. This type should only be used when `DiagnosticBuilder`'s lifetime
|
||||
/// causes difficulties, e.g. when storing diagnostics within `DiagCtxt`.
|
||||
/// The main part of a diagnostic. Note that `Diag`, which wraps this type, is
|
||||
/// used for most operations, and should be used instead whenever possible.
|
||||
/// This type should only be used when `Diag`'s lifetime causes difficulties,
|
||||
/// e.g. when storing diagnostics within `DiagCtxt`.
|
||||
#[must_use]
|
||||
#[derive(Clone, Debug, Encodable, Decodable)]
|
||||
pub struct DiagInner {
|
||||
|
@ -374,7 +374,7 @@ impl DiagInner {
|
|||
}
|
||||
}
|
||||
|
||||
// See comment on `DiagnosticBuilder::subdiagnostic_message_to_diagnostic_message`.
|
||||
// See comment on `Diag::subdiagnostic_message_to_diagnostic_message`.
|
||||
pub(crate) fn subdiagnostic_message_to_diagnostic_message(
|
||||
&self,
|
||||
attr: impl Into<SubdiagnosticMessage>,
|
||||
|
@ -463,42 +463,37 @@ pub struct Subdiag {
|
|||
/// that it has been emitted or cancelled.
|
||||
/// - The `EmissionGuarantee`, which determines the type returned from `emit`.
|
||||
///
|
||||
/// Each constructed `DiagnosticBuilder` must be consumed by a function such as
|
||||
/// `emit`, `cancel`, `delay_as_bug`, or `into_diagnostic`. A panic occurrs if a
|
||||
/// `DiagnosticBuilder` is dropped without being consumed by one of these
|
||||
/// functions.
|
||||
/// Each constructed `Diag` must be consumed by a function such as `emit`,
|
||||
/// `cancel`, `delay_as_bug`, or `into_diagnostic`. A panic occurrs if a `Diag`
|
||||
/// is dropped without being consumed by one of these functions.
|
||||
///
|
||||
/// If there is some state in a downstream crate you would like to
|
||||
/// access in the methods of `DiagnosticBuilder` here, consider
|
||||
/// extending `DiagCtxtFlags`.
|
||||
/// If there is some state in a downstream crate you would like to access in
|
||||
/// the methods of `Diag` here, consider extending `DiagCtxtFlags`.
|
||||
#[must_use]
|
||||
pub struct DiagnosticBuilder<'a, G: EmissionGuarantee = ErrorGuaranteed> {
|
||||
pub struct Diag<'a, G: EmissionGuarantee = ErrorGuaranteed> {
|
||||
pub dcx: &'a DiagCtxt,
|
||||
|
||||
/// Why the `Option`? It is always `Some` until the `DiagnosticBuilder` is
|
||||
/// consumed via `emit`, `cancel`, etc. At that point it is consumed and
|
||||
/// replaced with `None`. Then `drop` checks that it is `None`; if not, it
|
||||
/// panics because a diagnostic was built but not used.
|
||||
/// Why the `Option`? It is always `Some` until the `Diag` is consumed via
|
||||
/// `emit`, `cancel`, etc. At that point it is consumed and replaced with
|
||||
/// `None`. Then `drop` checks that it is `None`; if not, it panics because
|
||||
/// a diagnostic was built but not used.
|
||||
///
|
||||
/// Why the Box? `DiagInner` is a large type, and `DiagnosticBuilder` is
|
||||
/// often used as a return value, especially within the frequently-used
|
||||
/// `PResult` type. In theory, return value optimization (RVO) should avoid
|
||||
/// unnecessary copying. In practice, it does not (at the time of writing).
|
||||
/// Why the Box? `DiagInner` is a large type, and `Diag` is often used as a
|
||||
/// return value, especially within the frequently-used `PResult` type. In
|
||||
/// theory, return value optimization (RVO) should avoid unnecessary
|
||||
/// copying. In practice, it does not (at the time of writing).
|
||||
diag: Option<Box<DiagInner>>,
|
||||
|
||||
_marker: PhantomData<G>,
|
||||
}
|
||||
|
||||
// Cloning a `DiagnosticBuilder` is a recipe for a diagnostic being emitted
|
||||
// twice, which would be bad.
|
||||
impl<G> !Clone for DiagnosticBuilder<'_, G> {}
|
||||
// Cloning a `Diag` is a recipe for a diagnostic being emitted twice, which
|
||||
// would be bad.
|
||||
impl<G> !Clone for Diag<'_, G> {}
|
||||
|
||||
rustc_data_structures::static_assert_size!(
|
||||
DiagnosticBuilder<'_, ()>,
|
||||
2 * std::mem::size_of::<usize>()
|
||||
);
|
||||
rustc_data_structures::static_assert_size!(Diag<'_, ()>, 2 * std::mem::size_of::<usize>());
|
||||
|
||||
impl<G: EmissionGuarantee> Deref for DiagnosticBuilder<'_, G> {
|
||||
impl<G: EmissionGuarantee> Deref for Diag<'_, G> {
|
||||
type Target = DiagInner;
|
||||
|
||||
fn deref(&self) -> &DiagInner {
|
||||
|
@ -506,20 +501,20 @@ impl<G: EmissionGuarantee> Deref for DiagnosticBuilder<'_, G> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<G: EmissionGuarantee> DerefMut for DiagnosticBuilder<'_, G> {
|
||||
impl<G: EmissionGuarantee> DerefMut for Diag<'_, G> {
|
||||
fn deref_mut(&mut self) -> &mut DiagInner {
|
||||
self.diag.as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G> {
|
||||
impl<G: EmissionGuarantee> Debug for Diag<'_, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.diag.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
/// `DiagnosticBuilder` impls many `&mut self -> &mut Self` methods. Each one
|
||||
/// modifies an existing diagnostic, either in a standalone fashion, e.g.
|
||||
/// `Diag` impls many `&mut self -> &mut Self` methods. Each one modifies an
|
||||
/// existing diagnostic, either in a standalone fashion, e.g.
|
||||
/// `err.code(code);`, or in a chained fashion to make multiple modifications,
|
||||
/// e.g. `err.code(code).span(span);`.
|
||||
///
|
||||
|
@ -546,14 +541,14 @@ macro_rules! with_fn {
|
|||
} => {
|
||||
// The original function.
|
||||
$(#[$attrs])*
|
||||
#[doc = concat!("See [`DiagnosticBuilder::", stringify!($f), "()`].")]
|
||||
#[doc = concat!("See [`Diag::", stringify!($f), "()`].")]
|
||||
pub fn $f(&mut $self, $($name: $ty),*) -> &mut Self {
|
||||
$($body)*
|
||||
}
|
||||
|
||||
// The `with_*` variant.
|
||||
$(#[$attrs])*
|
||||
#[doc = concat!("See [`DiagnosticBuilder::", stringify!($f), "()`].")]
|
||||
#[doc = concat!("See [`Diag::", stringify!($f), "()`].")]
|
||||
pub fn $with_f(mut $self, $($name: $ty),*) -> Self {
|
||||
$self.$f($($name),*);
|
||||
$self
|
||||
|
@ -561,15 +556,14 @@ macro_rules! with_fn {
|
|||
};
|
||||
}
|
||||
|
||||
impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
impl<'a, G: EmissionGuarantee> Diag<'a, G> {
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn new<M: Into<DiagnosticMessage>>(dcx: &'a DiagCtxt, level: Level, message: M) -> Self {
|
||||
Self::new_diagnostic(dcx, DiagInner::new(level, message))
|
||||
}
|
||||
|
||||
/// Creates a new `DiagnosticBuilder` with an already constructed
|
||||
/// diagnostic.
|
||||
/// Creates a new `Diag` with an already constructed diagnostic.
|
||||
#[track_caller]
|
||||
pub(crate) fn new_diagnostic(dcx: &'a DiagCtxt, diag: DiagInner) -> Self {
|
||||
debug!("Created new diagnostic");
|
||||
|
@ -715,7 +709,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
self
|
||||
}
|
||||
|
||||
/// This is like [`DiagnosticBuilder::note()`], but it's only printed once.
|
||||
/// This is like [`Diag::note()`], but it's only printed once.
|
||||
pub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
|
||||
self.sub(Level::OnceNote, msg, MultiSpan::new());
|
||||
self
|
||||
|
@ -723,7 +717,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
|
||||
with_fn! { with_span_note,
|
||||
/// Prints the span with a note above it.
|
||||
/// This is like [`DiagnosticBuilder::note()`], but it gets its own span.
|
||||
/// This is like [`Diag::note()`], but it gets its own span.
|
||||
#[rustc_lint_diagnostics]
|
||||
pub fn span_note(
|
||||
&mut self,
|
||||
|
@ -735,7 +729,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
} }
|
||||
|
||||
/// Prints the span with a note above it.
|
||||
/// This is like [`DiagnosticBuilder::note_once()`], but it gets its own span.
|
||||
/// This is like [`Diag::note_once()`], but it gets its own span.
|
||||
pub fn span_note_once<S: Into<MultiSpan>>(
|
||||
&mut self,
|
||||
sp: S,
|
||||
|
@ -754,7 +748,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
} }
|
||||
|
||||
/// Prints the span with a warning above it.
|
||||
/// This is like [`DiagnosticBuilder::warn()`], but it gets its own span.
|
||||
/// This is like [`Diag::warn()`], but it gets its own span.
|
||||
#[rustc_lint_diagnostics]
|
||||
pub fn span_warn<S: Into<MultiSpan>>(
|
||||
&mut self,
|
||||
|
@ -773,7 +767,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
self
|
||||
} }
|
||||
|
||||
/// This is like [`DiagnosticBuilder::help()`], but it's only printed once.
|
||||
/// This is like [`Diag::help()`], but it's only printed once.
|
||||
pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
|
||||
self.sub(Level::OnceHelp, msg, MultiSpan::new());
|
||||
self
|
||||
|
@ -786,7 +780,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
}
|
||||
|
||||
/// Prints the span with some help above it.
|
||||
/// This is like [`DiagnosticBuilder::help()`], but it gets its own span.
|
||||
/// This is like [`Diag::help()`], but it gets its own span.
|
||||
#[rustc_lint_diagnostics]
|
||||
pub fn span_help<S: Into<MultiSpan>>(
|
||||
&mut self,
|
||||
|
@ -856,7 +850,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
)
|
||||
}
|
||||
|
||||
/// [`DiagnosticBuilder::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
|
||||
/// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
|
||||
pub fn multipart_suggestion_with_style(
|
||||
&mut self,
|
||||
msg: impl Into<SubdiagnosticMessage>,
|
||||
|
@ -948,7 +942,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
self
|
||||
} }
|
||||
|
||||
/// [`DiagnosticBuilder::span_suggestion()`] but you can set the [`SuggestionStyle`].
|
||||
/// [`Diag::span_suggestion()`] but you can set the [`SuggestionStyle`].
|
||||
pub fn span_suggestion_with_style(
|
||||
&mut self,
|
||||
sp: Span,
|
||||
|
@ -993,7 +987,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
|
||||
with_fn! { with_span_suggestions,
|
||||
/// Prints out a message with multiple suggested edits of the code.
|
||||
/// See also [`DiagnosticBuilder::span_suggestion()`].
|
||||
/// See also [`Diag::span_suggestion()`].
|
||||
pub fn span_suggestions(
|
||||
&mut self,
|
||||
sp: Span,
|
||||
|
@ -1039,7 +1033,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
|
||||
/// Prints out a message with multiple suggested edits of the code, where each edit consists of
|
||||
/// multiple parts.
|
||||
/// See also [`DiagnosticBuilder::multipart_suggestion()`].
|
||||
/// See also [`Diag::multipart_suggestion()`].
|
||||
pub fn multipart_suggestions(
|
||||
&mut self,
|
||||
msg: impl Into<SubdiagnosticMessage>,
|
||||
|
@ -1235,9 +1229,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
self.children.push(sub);
|
||||
}
|
||||
|
||||
/// Takes the diagnostic. For use by methods that consume the
|
||||
/// DiagnosticBuilder: `emit`, `cancel`, etc. Afterwards, `drop` is the
|
||||
/// only code that will be run on `self`.
|
||||
/// Takes the diagnostic. For use by methods that consume the Diag: `emit`,
|
||||
/// `cancel`, etc. Afterwards, `drop` is the only code that will be run on
|
||||
/// `self`.
|
||||
fn take_diag(&mut self) -> DiagInner {
|
||||
Box::into_inner(self.diag.take().unwrap())
|
||||
}
|
||||
|
@ -1319,9 +1313,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Destructor bomb: every `DiagnosticBuilder` must be consumed (emitted,
|
||||
/// cancelled, etc.) or we emit a bug.
|
||||
impl<G: EmissionGuarantee> Drop for DiagnosticBuilder<'_, G> {
|
||||
/// Destructor bomb: every `Diag` must be consumed (emitted, cancelled, etc.)
|
||||
/// or we emit a bug.
|
||||
impl<G: EmissionGuarantee> Drop for Diag<'_, G> {
|
||||
fn drop(&mut self) {
|
||||
match self.diag.take() {
|
||||
Some(diag) if !panicking() => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::diagnostic::DiagnosticLocation;
|
||||
use crate::{fluent_generated as fluent, AddToDiagnostic};
|
||||
use crate::{
|
||||
DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, ErrCode, IntoDiagnostic,
|
||||
Diag, DiagCtxt, DiagnosticArgValue, EmissionGuarantee, ErrCode, IntoDiagnostic,
|
||||
IntoDiagnosticArg, Level, SubdiagnosticMessageOp,
|
||||
};
|
||||
use rustc_ast as ast;
|
||||
|
@ -250,44 +250,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> {
|
||||
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
|
||||
match self {
|
||||
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_address_space)
|
||||
Diag::new(dcx, level, fluent::errors_target_invalid_address_space)
|
||||
.with_arg("addr_space", addr_space)
|
||||
.with_arg("cause", cause)
|
||||
.with_arg("err", err)
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits)
|
||||
Diag::new(dcx, level, fluent::errors_target_invalid_bits)
|
||||
.with_arg("kind", kind)
|
||||
.with_arg("bit", bit)
|
||||
.with_arg("cause", cause)
|
||||
.with_arg("err", err)
|
||||
}
|
||||
TargetDataLayoutErrors::MissingAlignment { cause } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_missing_alignment)
|
||||
Diag::new(dcx, level, fluent::errors_target_missing_alignment)
|
||||
.with_arg("cause", cause)
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidAlignment { cause, err } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_alignment)
|
||||
Diag::new(dcx, level, fluent::errors_target_invalid_alignment)
|
||||
.with_arg("cause", cause)
|
||||
.with_arg("err_kind", err.diag_ident())
|
||||
.with_arg("align", err.align())
|
||||
}
|
||||
TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_inconsistent_architecture)
|
||||
Diag::new(dcx, level, fluent::errors_target_inconsistent_architecture)
|
||||
.with_arg("dl", dl)
|
||||
.with_arg("target", target)
|
||||
}
|
||||
TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_inconsistent_pointer_width)
|
||||
Diag::new(dcx, level, fluent::errors_target_inconsistent_pointer_width)
|
||||
.with_arg("pointer_size", pointer_size)
|
||||
.with_arg("target", target)
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidBitsSize { err } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits_size)
|
||||
.with_arg("err", err)
|
||||
Diag::new(dcx, level, fluent::errors_target_invalid_bits_size).with_arg("err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -301,7 +300,7 @@ pub struct SingleLabelManySpans {
|
|||
impl AddToDiagnostic for SingleLabelManySpans {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_: F,
|
||||
) {
|
||||
diag.span_labels(self.spans, self.label);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! The current rustc diagnostics emitter.
|
||||
//!
|
||||
//! An `Emitter` takes care of generating the output from a `DiagnosticBuilder` struct.
|
||||
//! An `Emitter` takes care of generating the output from a `Diag` struct.
|
||||
//!
|
||||
//! There are various `Emitter` implementations that generate different output formats such as
|
||||
//! JSON and human readable output.
|
||||
|
|
|
@ -37,10 +37,9 @@ extern crate self as rustc_errors;
|
|||
|
||||
pub use codes::*;
|
||||
pub use diagnostic::{
|
||||
AddToDiagnostic, BugAbort, DecorateLint, DiagInner, DiagnosticArg, DiagnosticArgMap,
|
||||
DiagnosticArgName, DiagnosticArgValue, DiagnosticBuilder, DiagnosticStyledString,
|
||||
EmissionGuarantee, FatalAbort, IntoDiagnostic, IntoDiagnosticArg, StringPart, Subdiag,
|
||||
SubdiagnosticMessageOp,
|
||||
AddToDiagnostic, BugAbort, DecorateLint, Diag, DiagInner, DiagnosticArg, DiagnosticArgMap,
|
||||
DiagnosticArgName, DiagnosticArgValue, DiagnosticStyledString, EmissionGuarantee, FatalAbort,
|
||||
IntoDiagnostic, IntoDiagnosticArg, StringPart, Subdiag, SubdiagnosticMessageOp,
|
||||
};
|
||||
pub use diagnostic_impls::{
|
||||
DiagnosticArgFromDisplay, DiagnosticSymbolList, ExpectedLifetimeParameter,
|
||||
|
@ -98,7 +97,7 @@ mod styled_buffer;
|
|||
mod tests;
|
||||
pub mod translation;
|
||||
|
||||
pub type PErr<'a> = DiagnosticBuilder<'a>;
|
||||
pub type PErr<'a> = Diag<'a>;
|
||||
pub type PResult<'a, T> = Result<T, PErr<'a>>;
|
||||
|
||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
||||
|
@ -736,7 +735,7 @@ impl DiagCtxt {
|
|||
}
|
||||
|
||||
/// Steal a previously stashed diagnostic with the given `Span` and [`StashKey`] as the key.
|
||||
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<DiagnosticBuilder<'_, ()>> {
|
||||
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<Diag<'_, ()>> {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let key = (span.with_parent(None), key);
|
||||
// FIXME(#120456) - is `swap_remove` correct?
|
||||
|
@ -746,7 +745,7 @@ impl DiagCtxt {
|
|||
inner.stashed_err_count -= 1;
|
||||
}
|
||||
}
|
||||
Some(DiagnosticBuilder::new_diagnostic(self, diag))
|
||||
Some(Diag::new_diagnostic(self, diag))
|
||||
}
|
||||
|
||||
pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool {
|
||||
|
@ -1000,8 +999,8 @@ impl DiagCtxt {
|
|||
impl DiagCtxt {
|
||||
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
|
||||
#[track_caller]
|
||||
pub fn struct_bug(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, BugAbort> {
|
||||
DiagnosticBuilder::new(self, Bug, msg)
|
||||
pub fn struct_bug(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, BugAbort> {
|
||||
Diag::new(self, Bug, msg)
|
||||
}
|
||||
|
||||
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
|
||||
|
@ -1016,7 +1015,7 @@ impl DiagCtxt {
|
|||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, BugAbort> {
|
||||
) -> Diag<'_, BugAbort> {
|
||||
self.struct_bug(msg).with_span(span)
|
||||
}
|
||||
|
||||
|
@ -1027,10 +1026,7 @@ impl DiagCtxt {
|
|||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn create_bug<'a>(
|
||||
&'a self,
|
||||
bug: impl IntoDiagnostic<'a, BugAbort>,
|
||||
) -> DiagnosticBuilder<'a, BugAbort> {
|
||||
pub fn create_bug<'a>(&'a self, bug: impl IntoDiagnostic<'a, BugAbort>) -> Diag<'a, BugAbort> {
|
||||
bug.into_diagnostic(self, Bug)
|
||||
}
|
||||
|
||||
|
@ -1041,11 +1037,8 @@ impl DiagCtxt {
|
|||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_fatal(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, FatalAbort> {
|
||||
DiagnosticBuilder::new(self, Fatal, msg)
|
||||
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, FatalAbort> {
|
||||
Diag::new(self, Fatal, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
|
@ -1060,7 +1053,7 @@ impl DiagCtxt {
|
|||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, FatalAbort> {
|
||||
) -> Diag<'_, FatalAbort> {
|
||||
self.struct_fatal(msg).with_span(span)
|
||||
}
|
||||
|
||||
|
@ -1074,7 +1067,7 @@ impl DiagCtxt {
|
|||
pub fn create_fatal<'a>(
|
||||
&'a self,
|
||||
fatal: impl IntoDiagnostic<'a, FatalAbort>,
|
||||
) -> DiagnosticBuilder<'a, FatalAbort> {
|
||||
) -> Diag<'a, FatalAbort> {
|
||||
fatal.into_diagnostic(self, Fatal)
|
||||
}
|
||||
|
||||
|
@ -1087,7 +1080,7 @@ impl DiagCtxt {
|
|||
pub fn create_almost_fatal<'a>(
|
||||
&'a self,
|
||||
fatal: impl IntoDiagnostic<'a, FatalError>,
|
||||
) -> DiagnosticBuilder<'a, FatalError> {
|
||||
) -> Diag<'a, FatalError> {
|
||||
fatal.into_diagnostic(self, Fatal)
|
||||
}
|
||||
|
||||
|
@ -1102,8 +1095,8 @@ impl DiagCtxt {
|
|||
// FIXME: This method should be removed (every error should have an associated error code).
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_> {
|
||||
DiagnosticBuilder::new(self, Error, msg)
|
||||
pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_> {
|
||||
Diag::new(self, Error, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
|
@ -1118,7 +1111,7 @@ impl DiagCtxt {
|
|||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
) -> Diag<'_> {
|
||||
self.struct_err(msg).with_span(span)
|
||||
}
|
||||
|
||||
|
@ -1133,7 +1126,7 @@ impl DiagCtxt {
|
|||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> {
|
||||
pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> Diag<'a> {
|
||||
err.into_diagnostic(self, Error)
|
||||
}
|
||||
|
||||
|
@ -1146,7 +1139,7 @@ impl DiagCtxt {
|
|||
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
|
||||
#[track_caller]
|
||||
pub fn delayed_bug(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
|
||||
DiagnosticBuilder::<ErrorGuaranteed>::new(self, DelayedBug, msg).emit()
|
||||
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).emit()
|
||||
}
|
||||
|
||||
/// Ensures that an error is printed. See `Level::DelayedBug`.
|
||||
|
@ -1160,13 +1153,13 @@ impl DiagCtxt {
|
|||
sp: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> ErrorGuaranteed {
|
||||
DiagnosticBuilder::<ErrorGuaranteed>::new(self, DelayedBug, msg).with_span(sp).emit()
|
||||
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).with_span(sp).emit()
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, Warning, msg)
|
||||
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> {
|
||||
Diag::new(self, Warning, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
|
@ -1181,7 +1174,7 @@ impl DiagCtxt {
|
|||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
) -> Diag<'_, ()> {
|
||||
self.struct_warn(msg).with_span(span)
|
||||
}
|
||||
|
||||
|
@ -1192,10 +1185,7 @@ impl DiagCtxt {
|
|||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn create_warn<'a>(
|
||||
&'a self,
|
||||
warning: impl IntoDiagnostic<'a, ()>,
|
||||
) -> DiagnosticBuilder<'a, ()> {
|
||||
pub fn create_warn<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) -> Diag<'a, ()> {
|
||||
warning.into_diagnostic(self, Warning)
|
||||
}
|
||||
|
||||
|
@ -1206,8 +1196,8 @@ impl DiagCtxt {
|
|||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_note(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, Note, msg)
|
||||
pub fn struct_note(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> {
|
||||
Diag::new(self, Note, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
|
@ -1222,7 +1212,7 @@ impl DiagCtxt {
|
|||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
) -> Diag<'_, ()> {
|
||||
self.struct_note(msg).with_span(span)
|
||||
}
|
||||
|
||||
|
@ -1233,10 +1223,7 @@ impl DiagCtxt {
|
|||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn create_note<'a>(
|
||||
&'a self,
|
||||
note: impl IntoDiagnostic<'a, ()>,
|
||||
) -> DiagnosticBuilder<'a, ()> {
|
||||
pub fn create_note<'a>(&'a self, note: impl IntoDiagnostic<'a, ()>) -> Diag<'a, ()> {
|
||||
note.into_diagnostic(self, Note)
|
||||
}
|
||||
|
||||
|
@ -1247,23 +1234,20 @@ impl DiagCtxt {
|
|||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_help(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, Help, msg)
|
||||
pub fn struct_help(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> {
|
||||
Diag::new(self, Help, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_failure_note(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, FailureNote, msg)
|
||||
pub fn struct_failure_note(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> {
|
||||
Diag::new(self, FailureNote, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, Allow, msg)
|
||||
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> {
|
||||
Diag::new(self, Allow, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
|
@ -1272,8 +1256,8 @@ impl DiagCtxt {
|
|||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
id: LintExpectationId,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, Expect(id), msg)
|
||||
) -> Diag<'_, ()> {
|
||||
Diag::new(self, Expect(id), msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1552,8 +1536,8 @@ impl DiagCtxtInner {
|
|||
// an ICE, and the more information the merrier.
|
||||
//
|
||||
// We are at the `DiagInner`/`DiagCtxtInner` level rather than
|
||||
// the usual `DiagnosticBuilder`/`DiagCtxt` level, so we must
|
||||
// augment `bug` in a lower-level fashion.
|
||||
// the usual `Diag`/`DiagCtxt` level, so we must augment `bug`
|
||||
// in a lower-level fashion.
|
||||
bug.arg("level", bug.level);
|
||||
let msg = crate::fluent_generated::errors_invalid_flushed_delayed_diagnostic_level;
|
||||
let msg = self.eagerly_translate_for_subdiag(&bug, msg); // after the `arg` call
|
||||
|
@ -1593,8 +1577,8 @@ impl DelayedDiagInner {
|
|||
|
||||
fn decorate(self, dcx: &DiagCtxtInner) -> DiagInner {
|
||||
// We are at the `DiagInner`/`DiagCtxtInner` level rather than the
|
||||
// usual `DiagnosticBuilder`/`DiagCtxt` level, so we must construct
|
||||
// `diag` in a lower-level fashion.
|
||||
// usual `Diag`/`DiagCtxt` level, so we must construct `diag` in a
|
||||
// lower-level fashion.
|
||||
let mut diag = self.inner;
|
||||
let msg = match self.note.status() {
|
||||
BacktraceStatus::Captured => crate::fluent_generated::errors_delayed_at_with_newline,
|
||||
|
@ -1750,7 +1734,7 @@ impl Level {
|
|||
// FIXME(eddyb) this doesn't belong here AFAICT, should be moved to callsite.
|
||||
pub fn add_elided_lifetime_in_path_suggestion<G: EmissionGuarantee>(
|
||||
source_map: &SourceMap,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
n: usize,
|
||||
path_span: Span,
|
||||
incl_angl_brckt: bool,
|
||||
|
@ -1772,18 +1756,18 @@ pub fn add_elided_lifetime_in_path_suggestion<G: EmissionGuarantee>(
|
|||
}
|
||||
|
||||
pub fn report_ambiguity_error<'a, G: EmissionGuarantee>(
|
||||
db: &mut DiagnosticBuilder<'a, G>,
|
||||
diag: &mut Diag<'a, G>,
|
||||
ambiguity: rustc_lint_defs::AmbiguityErrorDiag,
|
||||
) {
|
||||
db.span_label(ambiguity.label_span, ambiguity.label_msg);
|
||||
db.note(ambiguity.note_msg);
|
||||
db.span_note(ambiguity.b1_span, ambiguity.b1_note_msg);
|
||||
diag.span_label(ambiguity.label_span, ambiguity.label_msg);
|
||||
diag.note(ambiguity.note_msg);
|
||||
diag.span_note(ambiguity.b1_span, ambiguity.b1_note_msg);
|
||||
for help_msg in ambiguity.b1_help_msgs {
|
||||
db.help(help_msg);
|
||||
diag.help(help_msg);
|
||||
}
|
||||
db.span_note(ambiguity.b2_span, ambiguity.b2_note_msg);
|
||||
diag.span_note(ambiguity.b2_span, ambiguity.b2_note_msg);
|
||||
for help_msg in ambiguity.b2_help_msgs {
|
||||
db.help(help_msg);
|
||||
diag.help(help_msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue