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>
impl<'a> DiagCtxtHandle<'a>
Sourcepub fn stash_diagnostic(
&self,
span: Span,
key: StashKey,
diag: DiagInner,
) -> Option<ErrorGuaranteed>
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
andkey
throughDiagCtxtHandle::try_steal_modify_and_emit_err
orDiagCtxtHandle::try_steal_replace_and_emit_err
. These do not allow cancellation or downgrading of the error. ReturnsSome(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. ReturnsSome(ErrorGuaranteed)
as is normal for delayed bugs. - Level::Warning and lower (i.e. !is_error()): can be accessed with the
provided
span
andkey
throughDiagCtxtHandle::steal_non_err()
. This allows cancelling and downgrading of the diagnostic. ReturnsNone
.
Sourcepub fn steal_non_err(self, span: Span, key: StashKey) -> Option<Diag<'a, ()>>
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.
Sourcepub fn try_steal_modify_and_emit_err<F>(
self,
span: Span,
key: StashKey,
modify_err: F,
) -> Option<ErrorGuaranteed>
pub fn try_steal_modify_and_emit_err<F>( self, span: Span, key: StashKey, modify_err: F, ) -> Option<ErrorGuaranteed>
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
.
Sourcepub fn try_steal_replace_and_emit_err(
self,
span: Span,
key: StashKey,
new_err: Diag<'_>,
) -> ErrorGuaranteed
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
.
pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool
Sourcepub fn emit_stashed_diagnostics(&self) -> Option<ErrorGuaranteed>
pub fn emit_stashed_diagnostics(&self) -> Option<ErrorGuaranteed>
Emit all stashed diagnostics.
Sourcepub fn has_errors_excluding_lint_errors(&self) -> Option<ErrorGuaranteed>
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.
Sourcepub fn has_errors(&self) -> Option<ErrorGuaranteed>
pub fn has_errors(&self) -> Option<ErrorGuaranteed>
This excludes delayed bugs.
Sourcepub fn has_errors_or_delayed_bugs(&self) -> Option<ErrorGuaranteed>
pub fn has_errors_or_delayed_bugs(&self) -> Option<ErrorGuaranteed>
This excludes nothing. Unless absolutely necessary, prefer has_errors
to this method.
pub fn print_error_count(&self, registry: &Registry)
Sourcepub fn abort_if_errors(&self)
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.
Sourcepub fn must_teach(&self, code: ErrCode) -> bool
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
.
pub fn emit_diagnostic(&self, diagnostic: DiagInner) -> Option<ErrorGuaranteed>
pub fn emit_artifact_notification(&self, path: &Path, artifact_type: &str)
pub fn emit_future_breakage_report(&self)
pub fn emit_unused_externs( &self, lint_level: Level, loud: bool, unused_externs: &[&str], )
Sourcepub fn steal_fulfilled_expectation_ids(&self) -> FxIndexSet<LintExpectationId>
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.
pub fn flush_delayed(&self)
Sourcepub fn set_must_produce_diag(&self)
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>
impl<'a> DiagCtxtHandle<'a>
pub fn struct_bug(self, msg: impl Into<Cow<'static, str>>) -> Diag<'a, BugAbort>
pub fn bug(self, msg: impl Into<Cow<'static, str>>) -> !
pub fn struct_span_bug( self, span: impl Into<MultiSpan>, msg: impl Into<Cow<'static, str>>, ) -> Diag<'a, BugAbort>
pub fn span_bug( self, span: impl Into<MultiSpan>, msg: impl Into<Cow<'static, str>>, ) -> !
pub fn create_bug( self, bug: impl Diagnostic<'a, BugAbort>, ) -> Diag<'a, BugAbort>
pub fn emit_bug(self, bug: impl Diagnostic<'a, BugAbort>) -> !
pub fn struct_fatal(self, msg: impl Into<DiagMessage>) -> Diag<'a, FatalAbort>
pub fn fatal(self, msg: impl Into<DiagMessage>) -> !
pub fn struct_span_fatal( self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>, ) -> Diag<'a, FatalAbort>
pub fn span_fatal( self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>, ) -> !
pub fn create_fatal( self, fatal: impl Diagnostic<'a, FatalAbort>, ) -> Diag<'a, FatalAbort>
pub fn emit_fatal(self, fatal: impl Diagnostic<'a, FatalAbort>) -> !
pub fn create_almost_fatal( self, fatal: impl Diagnostic<'a, FatalError>, ) -> Diag<'a, FatalError>
pub fn emit_almost_fatal( self, fatal: impl Diagnostic<'a, FatalError>, ) -> FatalError
pub fn struct_err(self, msg: impl Into<DiagMessage>) -> Diag<'a>
pub fn err(self, msg: impl Into<DiagMessage>) -> ErrorGuaranteed
pub fn struct_span_err( self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>, ) -> Diag<'a>
pub fn span_err( self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>, ) -> ErrorGuaranteed
pub fn create_err(self, err: impl Diagnostic<'a>) -> Diag<'a>
pub fn emit_err(self, err: impl Diagnostic<'a>) -> ErrorGuaranteed
Sourcepub fn delayed_bug(self, msg: impl Into<Cow<'static, str>>) -> ErrorGuaranteed
pub fn delayed_bug(self, msg: impl Into<Cow<'static, str>>) -> ErrorGuaranteed
Ensures that an error is printed. See Level::DelayedBug
.
Sourcepub fn span_delayed_bug(
self,
sp: impl Into<MultiSpan>,
msg: impl Into<Cow<'static, str>>,
) -> ErrorGuaranteed
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.
pub fn struct_warn(self, msg: impl Into<DiagMessage>) -> Diag<'a, ()>
pub fn warn(self, msg: impl Into<DiagMessage>)
pub fn struct_span_warn( self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>, ) -> Diag<'a, ()>
pub fn span_warn(self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>)
pub fn create_warn(self, warning: impl Diagnostic<'a, ()>) -> Diag<'a, ()>
pub fn emit_warn(self, warning: impl Diagnostic<'a, ()>)
pub fn struct_note(self, msg: impl Into<DiagMessage>) -> Diag<'a, ()>
pub fn note(&self, msg: impl Into<DiagMessage>)
pub fn struct_span_note( self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>, ) -> Diag<'a, ()>
pub fn span_note(self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>)
pub fn create_note(self, note: impl Diagnostic<'a, ()>) -> Diag<'a, ()>
pub fn emit_note(self, note: impl Diagnostic<'a, ()>)
pub fn struct_help(self, msg: impl Into<DiagMessage>) -> Diag<'a, ()>
pub fn struct_failure_note(self, msg: impl Into<DiagMessage>) -> Diag<'a, ()>
pub fn struct_allow(self, msg: impl Into<DiagMessage>) -> Diag<'a, ()>
pub fn struct_expect( self, msg: impl Into<DiagMessage>, id: LintExpectationId, ) -> Diag<'a, ()>
Methods from Deref<Target = &'a DiagCtxt>§
pub fn make_silent( &self, fallback_bundle: LazyFallbackBundle, fatal_note: Option<String>, emit_fatal_diagnostic: bool, )
pub(crate) fn wrap_emitter<F>(&self, f: F)
Sourcepub fn eagerly_translate<'a>(
&self,
message: DiagMessage,
args: impl Iterator<Item = DiagArg<'a>>,
) -> SubdiagMessage
pub fn eagerly_translate<'a>( &self, message: DiagMessage, args: impl Iterator<Item = DiagArg<'a>>, ) -> SubdiagMessage
Translate message
eagerly with args
to SubdiagMessage::Eager
.
Sourcepub fn eagerly_translate_to_string<'a>(
&self,
message: DiagMessage,
args: impl Iterator<Item = DiagArg<'a>>,
) -> String
pub fn eagerly_translate_to_string<'a>( &self, message: DiagMessage, args: impl Iterator<Item = DiagArg<'a>>, ) -> String
Translate message
eagerly with args
to String
.
pub fn can_emit_warnings(&self) -> bool
Sourcepub fn reset_err_count(&self)
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.
pub fn handle<'a>(&'a self) -> DiagCtxtHandle<'a>
Sourcepub fn taintable_handle<'a>(
&'a self,
tainted_with_errors: &'a Cell<Option<ErrorGuaranteed>>,
) -> DiagCtxtHandle<'a>
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>
impl<'a> Clone for DiagCtxtHandle<'a>
Source§fn clone(&self) -> DiagCtxtHandle<'a>
fn clone(&self) -> DiagCtxtHandle<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'a> Deref for DiagCtxtHandle<'a>
impl<'a> Deref for DiagCtxtHandle<'a>
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> !UnwindSafe for DiagCtxtHandle<'a>
Blanket Implementations§
§impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut T
fn allocate_from_iter( arena: &'tcx Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'tcx mut [T]
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
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