DiagCtxt

Struct DiagCtxt 

Source
pub struct DiagCtxt { /* private fields */ }
Expand description

A handler that deals with errors and other compiler output.

Certain errors (fatal, bug) may cause immediate exit, others log errors for later reporting.

Implementations§

Source§

impl DiagCtxt

Source

pub fn new(emitter: Box<dyn Emitter + Send>) -> DiagCtxt

Creates a new DiagCtxt with the given diagnostics emitter.

Source

pub fn new_early() -> DiagCtxt

Creates a new DiagCtxt with a stderr emitter for emitting one-off/early fatal errors that contain no source information.

Source

pub fn with_test_emitter(source_map: Option<Arc<SourceMap>>) -> DiagCtxt

Creates a new DiagCtxt with a test emitter.

Source

pub fn with_stderr_emitter(source_map: Option<Arc<SourceMap>>) -> DiagCtxt

Creates a new DiagCtxt with a stderr emitter.

Source

pub fn with_stderr_emitter_and_color( source_map: Option<Arc<SourceMap>>, color_choice: ColorChoice, ) -> DiagCtxt

Creates a new DiagCtxt with a stderr emitter and a color choice.

Source

pub fn with_silent_emitter(fatal_note: Option<String>) -> DiagCtxt

Creates a new DiagCtxt with a silent emitter.

Fatal diagnostics will still be emitted, optionally with the given note.

Source

pub fn with_buffer_emitter( source_map: Option<Arc<SourceMap>>, color_choice: ColorChoice, ) -> DiagCtxt

Creates a new DiagCtxt with a human emitter that emits diagnostics to a local buffer.

Source

pub fn from_opts(opts: &Opts) -> DiagCtxt

Creates a new DiagCtxt from the given options.

This is the default DiagCtxt used by the Session if one is not provided manually. It looks at the following options:

  • error_format
  • color
  • unstable.ui_testing
  • unstable.track_diagnostics
  • no_warnings
  • error_format_human
  • diagnostic_width

The default is human emitter to stderr.

See also DiagCtxtFlags::update_from_opts.

Source

pub fn make_silent(&self, fatal_note: Option<String>, emit_fatal: bool)

Sets the emitter to SilentEmitter.

Source

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

Sets the inner emitter. Returns the previous emitter.

Source

pub fn wrap_emitter( &self, f: impl FnOnce(Box<dyn Emitter + Send>) -> Box<dyn Emitter + Send>, )

Wraps the current emitter with the given closure.

Source

pub fn source_map(&self) -> Option<Arc<SourceMap>>

Gets the source map associated with this context.

Source

pub fn source_map_mut(&mut self) -> Option<&Arc<SourceMap>>

Gets the source map associated with this context.

Source

pub fn with_flags(self, f: impl FnOnce(&mut DiagCtxtFlags)) -> DiagCtxt

Sets flags.

Source

pub fn set_flags(&self, f: impl FnOnce(&mut DiagCtxtFlags))

Sets flags.

Source

pub fn set_flags_mut(&mut self, f: impl FnOnce(&mut DiagCtxtFlags))

Sets flags.

Source

pub fn disable_warnings(self) -> DiagCtxt

Disables emitting warnings.

Source

pub fn track_diagnostics(&self) -> bool

Returns true if diagnostics are being tracked.

Source

pub fn emit_diagnostic(&self, diagnostic: Diag) -> Result<(), ErrorGuaranteed>

Emits the given diagnostic with this context.

Source

pub fn err_count(&self) -> usize

Returns the number of errors that have been emitted, including duplicates.

Source

pub fn has_errors(&self) -> Result<(), ErrorGuaranteed>

Returns Err if any errors have been emitted.

Source

pub fn warn_count(&self) -> usize

Returns the number of warnings that have been emitted, including duplicates.

Source

pub fn note_count(&self) -> usize

Returns the number of notes that have been emitted, including duplicates.

Source

pub fn emitted_diagnostics_result( &self, ) -> Option<Result<EmittedDiagnostics, EmittedDiagnostics>>

Returns the emitted diagnostics as a result. Can be empty.

Returns None if the underlying emitter is not a human buffer emitter created with with_buffer_emitter.

Results Ok if there are no errors, Err otherwise.

§Examples

Print diagnostics to stdout if there are no errors, otherwise propagate with ?:

println!("{}", dcx.emitted_diagnostics_result().unwrap()?);
Source

pub fn emitted_diagnostics(&self) -> Option<EmittedDiagnostics>

Returns the emitted diagnostics. Can be empty.

Returns None if the underlying emitter is not a human buffer emitter created with with_buffer_emitter.

Source

pub fn emitted_errors(&self) -> Option<Result<(), EmittedDiagnostics>>

Returns Err with the printed diagnostics if any errors have been emitted.

Returns None if the underlying emitter is not a human buffer emitter created with with_buffer_emitter.

Source

pub fn print_error_count(&self) -> Result<(), ErrorGuaranteed>

Emits a diagnostic if any warnings or errors have been emitted.

Source§

impl DiagCtxt

Diag constructors.

Note that methods returning a DiagBuilder must also marked with #[track_caller].

Source

pub fn diag<G>( &self, level: Level, msg: impl Into<DiagMsg>, ) -> DiagBuilder<'_, G>

Creates a builder at the given level with the given msg.

Source

pub fn bug(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, BugAbort>

Creates a builder at the Bug level with the given msg.

Source

pub fn fatal(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, FatalAbort>

Creates a builder at the Fatal level with the given msg.

Source

pub fn err(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ErrorGuaranteed>

Creates a builder at the Error level with the given msg.

Source

pub fn warn(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ()>

Creates a builder at the Warning level with the given msg.

Attempting to .emit() the builder will only emit if can_emit_warnings is true.

Source

pub fn help(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ()>

Creates a builder at the Help level with the given msg.

Source

pub fn note(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ()>

Creates a builder at the Note level with the given msg.

Trait Implementations§

Source§

impl Debug for DiagCtxt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

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