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
impl DiagCtxt
pub fn disable_warnings(self) -> Self
pub fn with_flags(self, flags: DiagCtxtFlags) -> Self
pub fn with_ice_file(self, ice_file: PathBuf) -> Self
pub fn new(emitter: Box<DynEmitter>) -> Self
pub fn make_silent( &mut self, fallback_bundle: LazyFallbackBundle, fatal_note: Option<String> )
pub(crate) fn wrap_emitter<F>(&mut 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.
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
throughDiagCtxt::try_steal_modify_and_emit_err
orDiagCtxt::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
throughDiagCtxt::steal_non_err()
. This allows cancelling and downgrading of the diagnostic. ReturnsNone
.
sourcepub fn steal_non_err(&self, span: Span, key: StashKey) -> Option<Diag<'_, ()>>
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.
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 err_count_excluding_lint_errs(&self) -> usize
pub fn err_count_excluding_lint_errs(&self) -> usize
This excludes lint errors, and delayed bugs.
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] )
pub fn update_unstable_expectation_id( &self, unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId> )
sourcepub fn steal_fulfilled_expectation_ids(&self) -> FxHashSet<LintExpectationId>
pub fn steal_fulfilled_expectation_ids(&self) -> FxHashSet<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 DiagCtxt
impl DiagCtxt
pub fn struct_bug( &self, msg: impl Into<Cow<'static, str>> ) -> Diag<'_, 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<'_, BugAbort>
pub fn span_bug( &self, span: impl Into<MultiSpan>, msg: impl Into<Cow<'static, str>> ) -> !
pub fn create_bug<'a>( &'a self, bug: impl Diagnostic<'a, BugAbort> ) -> Diag<'a, BugAbort>
pub fn emit_bug<'a>(&'a self, bug: impl Diagnostic<'a, BugAbort>) -> !
pub fn struct_fatal(&self, msg: impl Into<DiagMessage>) -> Diag<'_, FatalAbort>
pub fn fatal(&self, msg: impl Into<DiagMessage>) -> !
pub fn struct_span_fatal( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> Diag<'_, FatalAbort>
pub fn span_fatal( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> !
pub fn create_fatal<'a>( &'a self, fatal: impl Diagnostic<'a, FatalAbort> ) -> Diag<'a, FatalAbort>
pub fn emit_fatal<'a>(&'a self, fatal: impl Diagnostic<'a, FatalAbort>) -> !
pub fn create_almost_fatal<'a>( &'a self, fatal: impl Diagnostic<'a, FatalError> ) -> Diag<'a, FatalError>
pub fn emit_almost_fatal<'a>( &'a self, fatal: impl Diagnostic<'a, FatalError> ) -> FatalError
pub fn struct_err(&self, msg: impl Into<DiagMessage>) -> Diag<'_>
pub fn err(&self, msg: impl Into<DiagMessage>) -> ErrorGuaranteed
pub fn struct_span_err( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> Diag<'_>
pub fn span_err( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> ErrorGuaranteed
pub fn create_err<'a>(&'a self, err: impl Diagnostic<'a>) -> Diag<'a>
pub fn emit_err<'a>(&'a 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<'_, ()>
pub fn warn(&self, msg: impl Into<DiagMessage>)
pub fn struct_span_warn( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> Diag<'_, ()>
pub fn span_warn(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>)
pub fn create_warn<'a>( &'a self, warning: impl Diagnostic<'a, ()> ) -> Diag<'a, ()>
pub fn emit_warn<'a>(&'a self, warning: impl Diagnostic<'a, ()>)
pub fn struct_note(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()>
pub fn note(&self, msg: impl Into<DiagMessage>)
pub fn struct_span_note( &self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage> ) -> Diag<'_, ()>
pub fn span_note(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>)
pub fn create_note<'a>(&'a self, note: impl Diagnostic<'a, ()>) -> Diag<'a, ()>
pub fn emit_note<'a>(&'a self, note: impl Diagnostic<'a, ()>)
pub fn struct_help(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()>
pub fn struct_failure_note(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()>
pub fn struct_allow(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()>
pub fn struct_expect( &self, msg: impl Into<DiagMessage>, id: LintExpectationId ) -> Diag<'_, ()>
Auto Trait Implementations§
impl DynSend for DiagCtxt
impl DynSync for DiagCtxt
impl !Freeze for DiagCtxt
impl !RefUnwindSafe for DiagCtxt
impl !Send for DiagCtxt
impl !Sync for DiagCtxt
impl Unpin for DiagCtxt
impl !UnwindSafe for DiagCtxt
Blanket Implementations§
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, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§impl<T> Filterable for T
impl<T> Filterable for T
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>
§impl<T> Pointable for T
impl<T> Pointable for 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: 464 bytes