Struct rustc_errors::DiagCtxt

source ·
pub struct DiagCtxt {
    pub(crate) inner: Lock<DiagCtxtInner>,
}
Expand description

A DiagCtxt deals with errors and other compiler output. Certain errors (fatal, bug, unimpl) may cause immediate exit, others log errors for later reporting.

Fields§

§inner: Lock<DiagCtxtInner>

Implementations§

source§

impl DiagCtxt

source

pub fn disable_warnings(self) -> Self

source

pub fn with_flags(self, flags: DiagCtxtFlags) -> Self

source

pub fn with_ice_file(self, ice_file: PathBuf) -> Self

source

pub fn new(emitter: Box<DynEmitter>) -> Self

source

pub fn make_silent( &mut self, fallback_bundle: LazyFallbackBundle, fatal_note: Option<String>, emit_fatal_diagnostic: bool )

source

pub(crate) fn wrap_emitter<F>(&mut self, f: F)

source

pub fn eagerly_translate<'a>( &self, message: DiagMessage, args: impl Iterator<Item = DiagArg<'a>> ) -> SubdiagMessage

Translate message eagerly with args to SubdiagMessage::Eager.

source

pub fn eagerly_translate_to_string<'a>( &self, message: DiagMessage, args: impl Iterator<Item = DiagArg<'a>> ) -> String

Translate message eagerly with args to String.

source

pub fn can_emit_warnings(&self) -> bool

source

pub fn reset_err_count(&self)

Resets the diagnostic error count as well as the cached emitted diagnostics.

NOTE: do not call this function from rustc. It is only meant to be called from external tools that want to reuse a Parser cleaning the previously emitted diagnostics as well as the overall count of emitted error diagnostics.

source

pub fn stash_diagnostic( &self, span: Span, key: StashKey, diag: DiagInner ) -> Option<ErrorGuaranteed>

Stashes a diagnostic for possible later improvement in a different, later stage of the compiler. Possible actions depend on the diagnostic level:

  • Level::Bug, Level:Fatal: not allowed, will trigger a panic.
  • Level::Error: immediately counted as an error that has occurred, because it is guaranteed to be emitted eventually. Can be later accessed with the provided span and key through DiagCtxt::try_steal_modify_and_emit_err or DiagCtxt::try_steal_replace_and_emit_err. These do not allow cancellation or downgrading of the error. Returns Some(ErrorGuaranteed).
  • Level::DelayedBug: this does happen occasionally with errors that are downgraded to delayed bugs. It is not stashed, but immediately emitted as a delayed bug. This is because stashing it would cause it to be counted by err_count which we don’t want. It doesn’t matter that we cannot steal and improve it later, because it’s not a user-facing error. Returns Some(ErrorGuaranteed) as is normal for delayed bugs.
  • Level::Warning and lower (i.e. !is_error()): can be accessed with the provided span and key through DiagCtxt::steal_non_err(). This allows cancelling and downgrading of the diagnostic. Returns None.
source

pub fn steal_non_err(&self, span: Span, key: StashKey) -> Option<Diag<'_, ()>>

Steal a previously stashed non-error diagnostic with the given Span and StashKey as the key. Panics if the found diagnostic is an error.

source

pub fn try_steal_modify_and_emit_err<F>( &self, span: Span, key: StashKey, modify_err: F ) -> Option<ErrorGuaranteed>
where F: FnMut(&mut Diag<'_>),

Steals a previously stashed error with the given Span and StashKey as the key, modifies it, and emits it. Returns None if no matching diagnostic is found. Panics if the found diagnostic’s level isn’t Level::Error.

source

pub fn try_steal_replace_and_emit_err( &self, span: Span, key: StashKey, new_err: Diag<'_> ) -> ErrorGuaranteed

Steals a previously stashed error with the given Span and StashKey as the key, cancels it if found, and emits new_err. Panics if the found diagnostic’s level isn’t Level::Error.

source

pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool

source

pub fn emit_stashed_diagnostics(&self) -> Option<ErrorGuaranteed>

Emit all stashed diagnostics.

source

pub fn err_count_excluding_lint_errs(&self) -> usize

This excludes lint errors, and delayed bugs.

source

pub fn err_count(&self) -> usize

This excludes delayed bugs.

source

pub fn has_errors_excluding_lint_errors(&self) -> Option<ErrorGuaranteed>

This excludes lint errors and delayed bugs. Unless absolutely necessary, prefer has_errors to this method.

source

pub fn has_errors(&self) -> Option<ErrorGuaranteed>

This excludes delayed bugs.

source

pub fn has_errors_or_delayed_bugs(&self) -> Option<ErrorGuaranteed>

This excludes nothing. Unless absolutely necessary, prefer has_errors to this method.

source

pub fn print_error_count(&self, registry: &Registry)

source

pub fn abort_if_errors(&self)

This excludes delayed bugs. Used for early aborts after errors occurred – e.g. because continuing in the face of errors is likely to lead to bad results, such as spurious/uninteresting additional errors – when returning an error Result is difficult.

source

pub fn must_teach(&self, code: ErrCode) -> bool

true if we haven’t taught a diagnostic with this code already. The caller must then teach the user about such a diagnostic.

Used to suppress emitting the same error multiple times with extended explanation when calling -Zteach.

source

pub fn emit_diagnostic(&self, diagnostic: DiagInner) -> Option<ErrorGuaranteed>

source

pub fn emit_artifact_notification(&self, path: &Path, artifact_type: &str)

source

pub fn emit_future_breakage_report(&self)

source

pub fn emit_unused_externs( &self, lint_level: Level, loud: bool, unused_externs: &[&str] )

source

pub fn update_unstable_expectation_id( &self, unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId> )

source

pub fn steal_fulfilled_expectation_ids(&self) -> FxHashSet<LintExpectationId>

This methods steals all LintExpectationIds that are stored inside DiagCtxtInner and indicate that the linked expectation has been fulfilled.

source

pub fn flush_delayed(&self)

source

pub fn set_must_produce_diag(&self)

Used when trimmed_def_paths is called and we must produce a diagnostic to justify its cost.

source§

impl DiagCtxt

source

pub fn struct_bug( &self, msg: impl Into<Cow<'static, str>> ) -> Diag<'_, BugAbort>

source

pub fn bug(&self, msg: impl Into<Cow<'static, str>>) -> !

source

pub fn struct_span_bug( &self, span: impl Into<MultiSpan>, msg: impl Into<Cow<'static, str>> ) -> Diag<'_, BugAbort>

source

pub fn span_bug( &self, span: impl Into<MultiSpan>, msg: impl Into<Cow<'static, str>> ) -> !

source

pub fn create_bug<'a>( &'a self, bug: impl Diagnostic<'a, BugAbort> ) -> Diag<'a, BugAbort>

source

pub fn emit_bug<'a>(&'a self, bug: impl Diagnostic<'a, BugAbort>) -> !

source

pub fn struct_fatal(&self, msg: impl Into<DiagMessage>) -> Diag<'_, FatalAbort>

source

pub fn fatal(&self, msg: impl Into<DiagMessage>) -> !

source

pub fn struct_span_fatal( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> Diag<'_, FatalAbort>

source

pub fn span_fatal( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> !

source

pub fn create_fatal<'a>( &'a self, fatal: impl Diagnostic<'a, FatalAbort> ) -> Diag<'a, FatalAbort>

source

pub fn emit_fatal<'a>(&'a self, fatal: impl Diagnostic<'a, FatalAbort>) -> !

source

pub fn create_almost_fatal<'a>( &'a self, fatal: impl Diagnostic<'a, FatalError> ) -> Diag<'a, FatalError>

source

pub fn emit_almost_fatal<'a>( &'a self, fatal: impl Diagnostic<'a, FatalError> ) -> FatalError

source

pub fn struct_err(&self, msg: impl Into<DiagMessage>) -> Diag<'_>

source

pub fn err(&self, msg: impl Into<DiagMessage>) -> ErrorGuaranteed

source

pub fn struct_span_err( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> Diag<'_>

source

pub fn span_err( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> ErrorGuaranteed

source

pub fn create_err<'a>(&'a self, err: impl Diagnostic<'a>) -> Diag<'a>

source

pub fn emit_err<'a>(&'a self, err: impl Diagnostic<'a>) -> ErrorGuaranteed

source

pub fn delayed_bug(&self, msg: impl Into<Cow<'static, str>>) -> ErrorGuaranteed

Ensures that an error is printed. See Level::DelayedBug.

source

pub fn span_delayed_bug( &self, sp: impl Into<MultiSpan>, msg: impl Into<Cow<'static, str>> ) -> ErrorGuaranteed

Ensures that an error is printed. See Level::DelayedBug.

Note: this function used to be called delay_span_bug. It was renamed to match similar functions like span_err, span_warn, etc.

source

pub fn struct_warn(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()>

source

pub fn warn(&self, msg: impl Into<DiagMessage>)

source

pub fn struct_span_warn( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> Diag<'_, ()>

source

pub fn span_warn(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>)

source

pub fn create_warn<'a>( &'a self, warning: impl Diagnostic<'a, ()> ) -> Diag<'a, ()>

source

pub fn emit_warn<'a>(&'a self, warning: impl Diagnostic<'a, ()>)

source

pub fn struct_note(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()>

source

pub fn note(&self, msg: impl Into<DiagMessage>)

source

pub fn struct_span_note( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> Diag<'_, ()>

source

pub fn span_note(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>)

source

pub fn create_note<'a>(&'a self, note: impl Diagnostic<'a, ()>) -> Diag<'a, ()>

source

pub fn emit_note<'a>(&'a self, note: impl Diagnostic<'a, ()>)

source

pub fn struct_help(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()>

source

pub fn struct_failure_note(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()>

source

pub fn struct_allow(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()>

source

pub fn struct_expect( &self, msg: impl Into<DiagMessage>, id: LintExpectationId ) -> Diag<'_, ()>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Aligned for T

source§

const ALIGN: Alignment = _

Alignment of Self.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, R> CollectAndApply<T, R> for T

source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

source§

impl<T> Filterable for T

source§

fn filterable( self, filter_name: &'static str ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

source§

impl<T> ErasedDestructor for T
where T: 'static,

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 464 bytes