Struct rustc_errors::DiagCtxtHandle

source ·
pub struct DiagCtxtHandle<'a> {
    pub(crate) dcx: &'a DiagCtxt,
    pub(crate) tainted_with_errors: Option<&'a Cell<Option<ErrorGuaranteed>>>,
}

Fields§

§dcx: &'a DiagCtxt§tainted_with_errors: Option<&'a Cell<Option<ErrorGuaranteed>>>

Some contexts create DiagCtxtHandle with this field set, and thus all errors emitted with it will automatically taint when emitting errors.

Implementations§

source§

impl<'a> DiagCtxtHandle<'a>

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 DiagCtxtHandle::try_steal_modify_and_emit_err or DiagCtxtHandle::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 DiagCtxtHandle::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<'a, ()>>

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<'a> DiagCtxtHandle<'a>

source

pub fn struct_bug(self, msg: impl Into<Cow<'static, str>>) -> Diag<'a, 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<'a, BugAbort>

source

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

source

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

source

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

source

pub fn struct_fatal(self, msg: impl Into<DiagMessage>) -> Diag<'a, 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<'a, FatalAbort>

source

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

source

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

source

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

source

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

source

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

source

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

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<'a>

source

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

source

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

source

pub fn emit_err(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<'a, ()>

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<'a, ()>

source

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

source

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

source

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

source

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

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<'a, ()>

source

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

source

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

source

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

source

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

source

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

source

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

source

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

Methods from Deref<Target = &'a DiagCtxt>§

source

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

source

pub(crate) fn wrap_emitter<F>(&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 handle<'a>(&'a self) -> DiagCtxtHandle<'a>

source

pub fn taintable_handle<'a>( &'a self, tainted_with_errors: &'a Cell<Option<ErrorGuaranteed>>, ) -> DiagCtxtHandle<'a>

Link this to a taintable context so that emitting errors will automatically set the Option<ErrorGuaranteed> instead of having to do that manually at every error emission site.

Trait Implementations§

source§

impl<'a> Clone for DiagCtxtHandle<'a>

source§

fn clone(&self) -> DiagCtxtHandle<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Deref for DiagCtxtHandle<'a>

source§

type Target = &'a DiagCtxt

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'a> Copy for DiagCtxtHandle<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for DiagCtxtHandle<'a>

§

impl<'a> !RefUnwindSafe for DiagCtxtHandle<'a>

§

impl<'a> !Send for DiagCtxtHandle<'a>

§

impl<'a> !Sync for DiagCtxtHandle<'a>

§

impl<'a> Unpin for DiagCtxtHandle<'a>

§

impl<'a> !UnwindSafe for DiagCtxtHandle<'a>

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<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for T
where T: Copy,

source§

fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut T

source§

fn allocate_from_iter<'a>( arena: &'a Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'a mut [T]

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<_>>()).

source§

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

source§

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>,

source§

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<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

source§

fn upcast(self, interner: I) -> U

source§

impl<I, T> UpcastFrom<I, T> for T

source§

fn upcast_from(from: T, _tcx: I) -> T

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,

source§

impl<T> MaybeSendSync for T

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: 16 bytes