Struct rustc_errors::Handler
source · pub struct Handler {
pub(crate) flags: HandlerFlags,
pub(crate) inner: Lock<HandlerInner>,
}
Expand description
A handler deals with errors and other compiler output. Certain errors (fatal, bug, unimpl) may cause immediate exit, others log errors for later reporting.
Fields
flags: HandlerFlags
inner: Lock<HandlerInner>
Implementations
sourceimpl Handler
impl Handler
pub fn with_tty_emitter(
color_config: ColorConfig,
can_emit_warnings: bool,
treat_err_as_bug: Option<NonZeroUsize>,
sm: Option<Lrc<SourceMap>>,
fluent_bundle: Option<Lrc<FluentBundle>>,
fallback_bundle: LazyFallbackBundle
) -> Self
pub fn with_tty_emitter_and_flags(
color_config: ColorConfig,
sm: Option<Lrc<SourceMap>>,
fluent_bundle: Option<Lrc<FluentBundle>>,
fallback_bundle: LazyFallbackBundle,
flags: HandlerFlags
) -> Self
pub fn with_emitter(
can_emit_warnings: bool,
treat_err_as_bug: Option<NonZeroUsize>,
emitter: Box<dyn Emitter + Send>
) -> Self
pub fn with_emitter_and_flags(
emitter: Box<dyn Emitter + Send>,
flags: HandlerFlags
) -> Self
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: Diagnostic)
pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic)
Stash a given diagnostic with the given Span
and StashKey
as the key for later stealing.
sourcepub fn steal_diagnostic(
&self,
span: Span,
key: StashKey
) -> Option<DiagnosticBuilder<'_, ()>>
pub fn steal_diagnostic(
&self,
span: Span,
key: StashKey
) -> Option<DiagnosticBuilder<'_, ()>>
Steal a previously stashed diagnostic with the given Span
and StashKey
as the key.
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 struct_diagnostic<G: EmissionGuarantee>(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, G>
pub fn struct_diagnostic<G: EmissionGuarantee>(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, G>
Construct a builder with the msg
at the level appropriate for the specific EmissionGuarantee
.
sourcepub fn struct_span_warn(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
pub fn struct_span_warn(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Warning
level at the given span
and with the msg
.
Attempting to .emit()
the builder will only emit if either:
can_emit_warnings
istrue
is_force_warn
was set inDiagnosticId::Lint
sourcepub fn struct_span_warn_with_expectation(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
id: LintExpectationId
) -> DiagnosticBuilder<'_, ()>
pub fn struct_span_warn_with_expectation(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
id: LintExpectationId
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Warning
level at the given span
and with the msg
.
The id
is used for lint emissions which should also fulfill a lint expectation.
Attempting to .emit()
the builder will only emit if either:
can_emit_warnings
istrue
is_force_warn
was set inDiagnosticId::Lint
sourcepub fn struct_span_allow(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
pub fn struct_span_allow(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Allow
level at the given span
and with the msg
.
sourcepub fn struct_span_warn_with_code(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> DiagnosticBuilder<'_, ()>
pub fn struct_span_warn_with_code(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Warning
level at the given span
and with the msg
.
Also include a code.
sourcepub fn struct_warn(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
pub fn struct_warn(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Warning
level with the msg
.
Attempting to .emit()
the builder will only emit if either:
can_emit_warnings
istrue
is_force_warn
was set inDiagnosticId::Lint
sourcepub fn struct_warn_with_expectation(
&self,
msg: impl Into<DiagnosticMessage>,
id: LintExpectationId
) -> DiagnosticBuilder<'_, ()>
pub fn struct_warn_with_expectation(
&self,
msg: impl Into<DiagnosticMessage>,
id: LintExpectationId
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Warning
level with the msg
. The id
is used for
lint emissions which should also fulfill a lint expectation.
Attempting to .emit()
the builder will only emit if either:
can_emit_warnings
istrue
is_force_warn
was set inDiagnosticId::Lint
sourcepub fn struct_allow(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
pub fn struct_allow(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Allow
level with the msg
.
sourcepub fn struct_expect(
&self,
msg: impl Into<DiagnosticMessage>,
id: LintExpectationId
) -> DiagnosticBuilder<'_, ()>
pub fn struct_expect(
&self,
msg: impl Into<DiagnosticMessage>,
id: LintExpectationId
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Expect
level with the msg
.
sourcepub fn struct_span_err(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ErrorGuaranteed>
pub fn struct_span_err(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ErrorGuaranteed>
Construct a builder at the Error
level at the given span
and with the msg
.
sourcepub fn struct_span_err_with_code(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> DiagnosticBuilder<'_, ErrorGuaranteed>
pub fn struct_span_err_with_code(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> DiagnosticBuilder<'_, ErrorGuaranteed>
Construct a builder at the Error
level at the given span
, with the msg
, and code
.
sourcepub fn struct_err(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ErrorGuaranteed>
pub fn struct_err(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ErrorGuaranteed>
Construct a builder at the Error
level with the msg
.
sourcepub fn struct_err_with_code(
&self,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> DiagnosticBuilder<'_, ErrorGuaranteed>
pub fn struct_err_with_code(
&self,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> DiagnosticBuilder<'_, ErrorGuaranteed>
Construct a builder at the Error
level with the msg
and the code
.
sourcepub fn struct_warn_with_code(
&self,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> DiagnosticBuilder<'_, ()>
pub fn struct_warn_with_code(
&self,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Warn
level with the msg
and the code
.
sourcepub fn struct_span_fatal(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, !>
pub fn struct_span_fatal(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, !>
Construct a builder at the Fatal
level at the given span
and with the msg
.
sourcepub fn struct_span_fatal_with_code(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> DiagnosticBuilder<'_, !>
pub fn struct_span_fatal_with_code(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> DiagnosticBuilder<'_, !>
Construct a builder at the Fatal
level at the given span
, with the msg
, and code
.
sourcepub fn struct_fatal(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, !>
pub fn struct_fatal(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, !>
Construct a builder at the Error
level with the msg
.
sourcepub fn struct_help(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
pub fn struct_help(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Help
level with the msg
.
sourcepub fn struct_note_without_error(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
pub fn struct_note_without_error(
&self,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
Construct a builder at the Note
level with the msg
.
pub fn span_fatal(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> !
pub fn span_fatal_with_code(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
) -> !
pub fn span_err(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> ErrorGuaranteed
pub fn span_err_with_code(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
)
pub fn span_warn(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
)
pub fn span_warn_with_code(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId
)
pub fn span_bug(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> !
pub fn delay_span_bug(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
) -> ErrorGuaranteed
pub fn delay_good_path_bug(&self, msg: impl Into<DiagnosticMessage>)
pub fn span_bug_no_panic(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
)
pub fn span_note_without_error(
&self,
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>
)
pub fn span_note_diag(
&self,
span: Span,
msg: impl Into<DiagnosticMessage>
) -> DiagnosticBuilder<'_, ()>
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> FatalError
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed
pub fn warn(&self, msg: impl Into<DiagnosticMessage>)
pub fn note_without_error(&self, msg: impl Into<DiagnosticMessage>)
pub fn bug(&self, msg: impl Into<DiagnosticMessage>) -> !
pub fn err_count(&self) -> usize
pub fn has_errors(&self) -> Option<ErrorGuaranteed>
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed>
pub fn has_errors_or_delayed_span_bugs(&self) -> bool
pub fn print_error_count(&self, registry: &Registry)
pub fn take_future_breakage_diagnostics(&self) -> Vec<Diagnostic>
pub fn abort_if_errors(&self)
sourcepub fn must_teach(&self, code: &DiagnosticId) -> bool
pub fn must_teach(&self, code: &DiagnosticId) -> 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 force_print_diagnostic(&self, db: Diagnostic)
pub fn emit_diagnostic(
&self,
diagnostic: &mut Diagnostic
) -> Option<ErrorGuaranteed>
pub(crate) fn emit_diag_at_span(
&self,
diag: Diagnostic,
sp: impl Into<MultiSpan>
) -> Option<ErrorGuaranteed>
pub fn emit_artifact_notification(&self, path: &Path, artifact_type: &str)
pub fn emit_future_breakage_report(&self, diags: Vec<Diagnostic>)
pub fn emit_unused_externs(
&self,
lint_level: Level,
loud: bool,
unused_externs: &[&str]
)
pub fn update_unstable_expectation_id(
&self,
unstable_to_stable: &FxHashMap<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
HandlerInner
and indicate that the linked expectation has been fulfilled.
Auto Trait Implementations
impl !RefUnwindSafe for Handler
impl !Send for Handler
impl !Sync for Handler
impl Unpin for Handler
impl !UnwindSafe for Handler
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut 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: 408 bytes