Skip to main content

## DiagCtxtHandle

# Struct 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(&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)

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_timing_section_start(&self, record: TimingRecord)

Source

#### pub fn emit_timing_section_end(&self, record: TimingRecord)

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 steal_fulfilled_expectation_ids(&self) -> FxIndexSet<LintExpectationId>

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

Source

#### pub fn flush_delayed(&self)

Trigger an ICE if there are any delayed bugs and no hard errors.

This will panic if there are any stashed diagnostics. You can call `emit_stashed_diagnostics` to emit those before calling `flush_delayed`.

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)

Source

#### pub fn set_emitter(&self, emitter: Box<dyn Emitter + DynSend>)

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 duplicate 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> !DynSend for DiagCtxtHandle<'a>

§

### impl<'a> !DynSync for DiagCtxtHandle<'a>

§

### 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> UnsafeUnpin 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<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, dest: *mut u8)

🔬This is a nightly-only experimental API. (`clone_to_uninit`)
Performs copy-assignment from `self` to `dest`. 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> Pointable for T

Source§

#### const ALIGN: usize

The alignment of pointer.
Source§

#### 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

#### type Target = T

🔬This is a nightly-only experimental API. (`arbitrary_self_types`)
The target type on which the method may be called.
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<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<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: 16 bytes