Rename Handler
as DiagCtxt
.
This commit is contained in:
parent
321b6565a5
commit
cde19c016e
58 changed files with 216 additions and 204 deletions
|
@ -886,7 +886,7 @@ impl Diagnostic {
|
|||
/// interpolated variables).
|
||||
pub fn eager_subdiagnostic(
|
||||
&mut self,
|
||||
handler: &crate::Handler,
|
||||
handler: &crate::DiagCtxt,
|
||||
subdiagnostic: impl AddToDiagnostic,
|
||||
) -> &mut Self {
|
||||
subdiagnostic.add_to_diagnostic_with(self, |diag, msg| {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::diagnostic::IntoDiagnosticArg;
|
||||
use crate::{DiagCtxt, Level, MultiSpan, StashKey};
|
||||
use crate::{
|
||||
Diagnostic, DiagnosticId, DiagnosticMessage, DiagnosticStyledString, ErrorGuaranteed,
|
||||
ExplicitBug, SubdiagnosticMessage,
|
||||
};
|
||||
use crate::{Handler, Level, MultiSpan, StashKey};
|
||||
use rustc_lint_defs::Applicability;
|
||||
use rustc_span::source_map::Spanned;
|
||||
|
||||
|
@ -19,9 +19,9 @@ use std::thread::panicking;
|
|||
/// `#[derive(Diagnostic)]` -- see [rustc_macros::Diagnostic].
|
||||
#[rustc_diagnostic_item = "IntoDiagnostic"]
|
||||
pub trait IntoDiagnostic<'a, G: EmissionGuarantee = ErrorGuaranteed> {
|
||||
/// Write out as a diagnostic out of `Handler`.
|
||||
/// Write out as a diagnostic out of `DiagCtxt`.
|
||||
#[must_use]
|
||||
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, G>;
|
||||
fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, G>;
|
||||
}
|
||||
|
||||
impl<'a, T, G> IntoDiagnostic<'a, G> for Spanned<T>
|
||||
|
@ -29,7 +29,7 @@ where
|
|||
T: IntoDiagnostic<'a, G>,
|
||||
G: EmissionGuarantee,
|
||||
{
|
||||
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, G> {
|
||||
fn into_diagnostic(self, handler: &'a DiagCtxt) -> DiagnosticBuilder<'a, G> {
|
||||
let mut diag = self.node.into_diagnostic(handler);
|
||||
diag.set_span(self.span);
|
||||
diag
|
||||
|
@ -74,8 +74,8 @@ struct DiagnosticBuilderInner<'a> {
|
|||
enum DiagnosticBuilderState<'a> {
|
||||
/// Initial state of a `DiagnosticBuilder`, before `.emit()` or `.cancel()`.
|
||||
///
|
||||
/// The `Diagnostic` will be emitted through this `Handler`.
|
||||
Emittable(&'a Handler),
|
||||
/// The `Diagnostic` will be emitted through this `DiagCtxt`.
|
||||
Emittable(&'a DiagCtxt),
|
||||
|
||||
/// State of a `DiagnosticBuilder`, after `.emit()` or *during* `.cancel()`.
|
||||
///
|
||||
|
@ -95,7 +95,7 @@ enum DiagnosticBuilderState<'a> {
|
|||
// `DiagnosticBuilderState` should be pointer-sized.
|
||||
rustc_data_structures::static_assert_size!(
|
||||
DiagnosticBuilderState<'_>,
|
||||
std::mem::size_of::<&Handler>()
|
||||
std::mem::size_of::<&DiagCtxt>()
|
||||
);
|
||||
|
||||
/// Trait for types that `DiagnosticBuilder::emit` can return as a "guarantee"
|
||||
|
@ -110,7 +110,7 @@ pub trait EmissionGuarantee: Sized {
|
|||
/// Creates a new `DiagnosticBuilder` that will return this type of guarantee.
|
||||
#[track_caller]
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
handler: &DiagCtxt,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self>;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ impl<'a> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
|||
impl EmissionGuarantee for ErrorGuaranteed {
|
||||
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||
match db.inner.state {
|
||||
// First `.emit()` call, the `&Handler` is still available.
|
||||
// First `.emit()` call, the `&DiagCtxt` is still available.
|
||||
DiagnosticBuilderState::Emittable(handler) => {
|
||||
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||
|
||||
|
@ -166,7 +166,7 @@ impl EmissionGuarantee for ErrorGuaranteed {
|
|||
|
||||
#[track_caller]
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
handler: &DiagCtxt,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self> {
|
||||
DiagnosticBuilder::new(handler, Level::Error { lint: false }, msg)
|
||||
|
@ -177,7 +177,7 @@ impl EmissionGuarantee for ErrorGuaranteed {
|
|||
impl EmissionGuarantee for () {
|
||||
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||
match db.inner.state {
|
||||
// First `.emit()` call, the `&Handler` is still available.
|
||||
// First `.emit()` call, the `&DiagCtxt` is still available.
|
||||
DiagnosticBuilderState::Emittable(handler) => {
|
||||
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||
|
||||
|
@ -189,7 +189,7 @@ impl EmissionGuarantee for () {
|
|||
}
|
||||
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
handler: &DiagCtxt,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self> {
|
||||
DiagnosticBuilder::new(handler, Level::Warning(None), msg)
|
||||
|
@ -204,7 +204,7 @@ pub struct Noted;
|
|||
impl EmissionGuarantee for Noted {
|
||||
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||
match db.inner.state {
|
||||
// First `.emit()` call, the `&Handler` is still available.
|
||||
// First `.emit()` call, the `&DiagCtxt` is still available.
|
||||
DiagnosticBuilderState::Emittable(handler) => {
|
||||
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||
handler.emit_diagnostic_without_consuming(&mut db.inner.diagnostic);
|
||||
|
@ -217,7 +217,7 @@ impl EmissionGuarantee for Noted {
|
|||
}
|
||||
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
handler: &DiagCtxt,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self> {
|
||||
DiagnosticBuilder::new(handler, Level::Note, msg)
|
||||
|
@ -232,7 +232,7 @@ pub struct Bug;
|
|||
impl EmissionGuarantee for Bug {
|
||||
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||
match db.inner.state {
|
||||
// First `.emit()` call, the `&Handler` is still available.
|
||||
// First `.emit()` call, the `&DiagCtxt` is still available.
|
||||
DiagnosticBuilderState::Emittable(handler) => {
|
||||
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||
|
||||
|
@ -246,7 +246,7 @@ impl EmissionGuarantee for Bug {
|
|||
}
|
||||
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
handler: &DiagCtxt,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self> {
|
||||
DiagnosticBuilder::new(handler, Level::Bug, msg)
|
||||
|
@ -256,7 +256,7 @@ impl EmissionGuarantee for Bug {
|
|||
impl EmissionGuarantee for ! {
|
||||
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||
match db.inner.state {
|
||||
// First `.emit()` call, the `&Handler` is still available.
|
||||
// First `.emit()` call, the `&DiagCtxt` is still available.
|
||||
DiagnosticBuilderState::Emittable(handler) => {
|
||||
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||
|
||||
|
@ -270,7 +270,7 @@ impl EmissionGuarantee for ! {
|
|||
}
|
||||
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
handler: &DiagCtxt,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self> {
|
||||
DiagnosticBuilder::new(handler, Level::Fatal, msg)
|
||||
|
@ -280,7 +280,7 @@ impl EmissionGuarantee for ! {
|
|||
impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
|
||||
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||
match db.inner.state {
|
||||
// First `.emit()` call, the `&Handler` is still available.
|
||||
// First `.emit()` call, the `&DiagCtxt` is still available.
|
||||
DiagnosticBuilderState::Emittable(handler) => {
|
||||
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||
|
||||
|
@ -294,7 +294,7 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
|
|||
}
|
||||
|
||||
fn make_diagnostic_builder(
|
||||
handler: &Handler,
|
||||
handler: &DiagCtxt,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, Self> {
|
||||
DiagnosticBuilder::new(handler, Level::Fatal, msg)
|
||||
|
@ -340,10 +340,10 @@ impl<G: EmissionGuarantee> DerefMut for DiagnosticBuilder<'_, G> {
|
|||
|
||||
impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
/// Convenience function for internal use, clients should use one of the
|
||||
/// `struct_*` methods on [`Handler`].
|
||||
/// `struct_*` methods on [`DiagCtxt`].
|
||||
#[track_caller]
|
||||
pub(crate) fn new<M: Into<DiagnosticMessage>>(
|
||||
handler: &'a Handler,
|
||||
handler: &'a DiagCtxt,
|
||||
level: Level,
|
||||
message: M,
|
||||
) -> Self {
|
||||
|
@ -354,7 +354,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
/// Creates a new `DiagnosticBuilder` with an already constructed
|
||||
/// diagnostic.
|
||||
#[track_caller]
|
||||
pub(crate) fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic) -> Self {
|
||||
pub(crate) fn new_diagnostic(handler: &'a DiagCtxt, diagnostic: Diagnostic) -> Self {
|
||||
debug!("Created new diagnostic");
|
||||
Self {
|
||||
inner: DiagnosticBuilderInner {
|
||||
|
@ -398,7 +398,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
|
||||
/// Stashes diagnostic for possible later improvement in a different,
|
||||
/// later stage of the compiler. The diagnostic can be accessed with
|
||||
/// the provided `span` and `key` through [`Handler::steal_diagnostic()`].
|
||||
/// the provided `span` and `key` through [`DiagCtxt::steal_diagnostic()`].
|
||||
///
|
||||
/// As with `buffer`, this is unless the handler has disabled such buffering.
|
||||
pub fn stash(self, span: Span, key: StashKey) {
|
||||
|
@ -409,9 +409,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
|
||||
/// Converts the builder to a `Diagnostic` for later emission,
|
||||
/// unless handler has disabled such buffering, or `.emit()` was called.
|
||||
pub fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a Handler)> {
|
||||
pub fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a DiagCtxt)> {
|
||||
let handler = match self.inner.state {
|
||||
// No `.emit()` calls, the `&Handler` is still available.
|
||||
// No `.emit()` calls, the `&DiagCtxt` is still available.
|
||||
DiagnosticBuilderState::Emittable(handler) => handler,
|
||||
// `.emit()` was previously called, nothing we can do.
|
||||
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {
|
||||
|
@ -440,8 +440,8 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
|||
Some((diagnostic, handler))
|
||||
}
|
||||
|
||||
/// Retrieves the [`Handler`] if available
|
||||
pub fn handler(&self) -> Option<&Handler> {
|
||||
/// Retrieves the [`DiagCtxt`] if available
|
||||
pub fn handler(&self) -> Option<&DiagCtxt> {
|
||||
match self.inner.state {
|
||||
DiagnosticBuilderState::Emittable(handler) => Some(handler),
|
||||
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => None,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::diagnostic::DiagnosticLocation;
|
||||
use crate::{fluent_generated as fluent, AddToDiagnostic};
|
||||
use crate::{DiagnosticArgValue, DiagnosticBuilder, Handler, IntoDiagnostic, IntoDiagnosticArg};
|
||||
use crate::{DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, IntoDiagnostic, IntoDiagnosticArg};
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_hir as hir;
|
||||
|
@ -246,7 +246,7 @@ impl<Id> IntoDiagnosticArg for hir::def::Res<Id> {
|
|||
}
|
||||
|
||||
impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
|
||||
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
|
||||
fn into_diagnostic(self, handler: &DiagCtxt) -> DiagnosticBuilder<'_, !> {
|
||||
let mut diag;
|
||||
match self {
|
||||
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
|
||||
|
|
|
@ -16,8 +16,8 @@ use crate::snippet::{
|
|||
use crate::styled_buffer::StyledBuffer;
|
||||
use crate::translation::{to_fluent_args, Translate};
|
||||
use crate::{
|
||||
diagnostic::DiagnosticLocation, CodeSuggestion, Diagnostic, DiagnosticId, DiagnosticMessage,
|
||||
FluentBundle, Handler, LazyFallbackBundle, Level, MultiSpan, SubDiagnostic,
|
||||
diagnostic::DiagnosticLocation, CodeSuggestion, DiagCtxt, Diagnostic, DiagnosticId,
|
||||
DiagnosticMessage, FluentBundle, LazyFallbackBundle, Level, MultiSpan, SubDiagnostic,
|
||||
SubstitutionHighlight, SuggestionStyle, TerminalUrl,
|
||||
};
|
||||
use rustc_lint_defs::pluralize;
|
||||
|
@ -556,7 +556,7 @@ impl Emitter for EmitterWriter {
|
|||
/// Fatal diagnostics are forwarded to `fatal_handler` to avoid silent
|
||||
/// failures of rustc, as witnessed e.g. in issue #89358.
|
||||
pub struct SilentEmitter {
|
||||
pub fatal_handler: Handler,
|
||||
pub fatal_handler: DiagCtxt,
|
||||
pub fatal_note: Option<String>,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::*;
|
||||
|
||||
use crate::emitter::ColorConfig;
|
||||
use crate::Handler;
|
||||
use crate::DiagCtxt;
|
||||
use rustc_span::BytePos;
|
||||
|
||||
use std::str;
|
||||
|
@ -61,7 +61,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
|
|||
);
|
||||
|
||||
let span = Span::with_root_ctxt(BytePos(span.0), BytePos(span.1));
|
||||
let handler = Handler::with_emitter(Box::new(je));
|
||||
let handler = DiagCtxt::with_emitter(Box::new(je));
|
||||
handler.span_err(span, "foo");
|
||||
|
||||
let bytes = output.lock().unwrap();
|
||||
|
|
|
@ -412,7 +412,7 @@ use std::backtrace::{Backtrace, BacktraceStatus};
|
|||
/// A handler deals with errors and other compiler output.
|
||||
/// Certain errors (fatal, bug, unimpl) may cause immediate exit,
|
||||
/// others log errors for later reporting.
|
||||
pub struct Handler {
|
||||
pub struct DiagCtxt {
|
||||
inner: Lock<HandlerInner>,
|
||||
}
|
||||
|
||||
|
@ -572,7 +572,7 @@ impl Drop for HandlerInner {
|
|||
}
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
impl DiagCtxt {
|
||||
pub fn with_tty_emitter(
|
||||
sm: Option<Lrc<SourceMap>>,
|
||||
fallback_bundle: LazyFallbackBundle,
|
||||
|
@ -1413,9 +1413,9 @@ impl Handler {
|
|||
}
|
||||
}
|
||||
|
||||
// Note: we prefer implementing operations on `Handler`, rather than
|
||||
// Note: we prefer implementing operations on `DiagCtxt`, rather than
|
||||
// `HandlerInner`, whenever possible. This minimizes functions where
|
||||
// `Handler::foo()` just borrows `inner` and forwards a call to
|
||||
// `DiagCtxt::foo()` just borrows `inner` and forwards a call to
|
||||
// `HanderInner::foo`.
|
||||
impl HandlerInner {
|
||||
/// Emit all stashed diagnostics.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue