Expand description

Diagnostics creation and emission for rustc.

This module contains the code for creating and emitting diagnostics.


pub use emitter::ColorConfig;


Emit diagnostics using the annotate-snippets library

diagnostic 🔒

The current rustc diagnostics emitter.

A JSON emitter for errors.

lock 🔒

Bindings to acquire a global named lock.

snippet 🔒



Used for emitting structured error messages and other diagnostic information.

Useful type to use with Result<> indicate that an error has already been reported to the user, so no need to continue checking.

Signifies that the compiler died with an explicit call to .bug or .span_bug rather than a failed assertion, etc.

Used as a return value to signify a fatal error occurred. (It is also used as the argument to panic at the moment, but that will eventually not be true.)

A handler deals with errors and other compiler output. Certain errors (fatal, bug, unimpl) may cause immediate exit, others log errors for later reporting.

This inner struct exists to keep it all behind a single lock; this is done to prevent possible deadlocks in a multi-threaded compiler, as well as inconsistent state observation.

LanguageIdentifier is a core struct representing a Unicode Language Identifier.

A collection of Spans.

A span together with some additional data.

A “sub”-diagnostic attached to a parent diagnostic. For example, a note attached to an error.

See the docs on CodeSuggestion::substitutions

Used to translate between Spans and byte positions within a single output line in highlighted code of structured suggestions.


Indicates the confidence in the correctness of a suggestion.

Simplified version of FluentValue that can implement Encodable and Decodable. Converted to a FluentValue by the emitter to be used in diagnostic translation.

Abstraction over a message in a diagnostic to support both translatable and non-translatable diagnostic messages.

A key denoting where from a diagnostic was stashed.



Trait implemented by error types. This should not be implemented manually. Instead, use #[derive(SessionSubdiagnostic)] – see rustc_macros::SessionSubdiagnostic.

Trait for types that DiagnosticBuilder::emit can return as a “guarantee” (or “proof”) token that the emission happened.

Converts a value of a type into a DiagnosticArg (typically a field of a SessionDiagnostic struct). Implemented as a custom trait rather than From so that it is implemented on the type being converted rather than on DiagnosticArgValue, which enables types from other rustc_* crates to implement this.


Return the default FluentBundle with standard “en-US” diagnostic messages.

Returns Fluent bundle with the user’s locale resources from $sysroot/share/locale/$requested_locale/*.ftl.

Type Definitions

Simplified version of FluentArg that can implement Encodable and Decodable. Collection of DiagnosticArg are converted to FluentArgs (consuming the collection) at the start of diagnostic emission.

Type alias for the result of fallback_fluent_bundle - a reference-counted pointer to a lazily evaluated fluent bundle.