[][src]Struct syntax::diagnostics::plugin::DiagnosticBuilder

#[must_use]
pub struct DiagnosticBuilder<'a> { pub handler: &'a Handler, // some fields omitted }

Used for emitting structured error messages and other diagnostic information.

If there is some state in a downstream crate you would like to access in the methods of DiagnosticBuilder here, consider extending HandlerFlags, accessed via self.handler.flags.

Fields

handler: &'a Handler

Methods

impl<'a> DiagnosticBuilder<'a>[src]

pub fn emit(&mut self)[src]

Emit the diagnostic.

pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>)[src]

Buffers the diagnostic for later emission, unless handler has disabled such buffering.

pub fn sub<S>(
    &mut self,
    level: Level,
    message: &str,
    span: Option<S>
) -> &mut DiagnosticBuilder<'a> where
    S: Into<MultiSpan>, 
[src]

Convenience function for internal use, clients should use one of the span_* methods instead.

pub fn delay_as_bug(&mut self)[src]

Delay emission of this diagnostic as a bug.

This can be useful in contexts where an error indicates a bug but typically this only happens when other compilation errors have already happened. In those cases this can be used to defer emission of this diagnostic as a bug in the compiler only if no other errors have been emitted.

In the meantime, though, callsites are required to deal with the "bug" locally in whichever way makes the most sense.

pub fn span_label<T>(
    &mut self,
    span: Span,
    label: T
) -> &mut DiagnosticBuilder<'a> where
    T: Into<String>, 
[src]

Adds a span/label to be included in the resulting snippet. This is pushed onto the MultiSpan that was created when the diagnostic was first built. If you don't call this function at all, and you just supplied a Span to create the diagnostic, then the snippet will just include that Span, which is called the primary span.

pub fn note_expected_found(
    &mut self,
    label: &dyn Display,
    expected: DiagnosticStyledString,
    found: DiagnosticStyledString
) -> &mut DiagnosticBuilder<'a>
[src]

pub fn note_expected_found_extra(
    &mut self,
    label: &dyn Display,
    expected: DiagnosticStyledString,
    found: DiagnosticStyledString,
    expected_extra: &dyn Display,
    found_extra: &dyn Display
) -> &mut DiagnosticBuilder<'a>
[src]

pub fn note(&mut self, msg: &str) -> &mut DiagnosticBuilder<'a>[src]

pub fn span_note<S>(&mut self, sp: S, msg: &str) -> &mut DiagnosticBuilder<'a> where
    S: Into<MultiSpan>, 
[src]

pub fn warn(&mut self, msg: &str) -> &mut DiagnosticBuilder<'a>[src]

pub fn span_warn<S>(&mut self, sp: S, msg: &str) -> &mut DiagnosticBuilder<'a> where
    S: Into<MultiSpan>, 
[src]

pub fn help(&mut self, msg: &str) -> &mut DiagnosticBuilder<'a>[src]

pub fn span_help<S>(&mut self, sp: S, msg: &str) -> &mut DiagnosticBuilder<'a> where
    S: Into<MultiSpan>, 
[src]

pub fn multipart_suggestion(
    &mut self,
    msg: &str,
    suggestion: Vec<(Span, String)>,
    applicability: Applicability
) -> &mut DiagnosticBuilder<'a>
[src]

pub fn tool_only_multipart_suggestion(
    &mut self,
    msg: &str,
    suggestion: Vec<(Span, String)>,
    applicability: Applicability
) -> &mut DiagnosticBuilder<'a>
[src]

pub fn span_suggestion(
    &mut self,
    sp: Span,
    msg: &str,
    suggestion: String,
    applicability: Applicability
) -> &mut DiagnosticBuilder<'a>
[src]

pub fn span_suggestions<impl Iterator>(
    &mut self,
    sp: Span,
    msg: &str,
    suggestions: impl Iterator,
    applicability: Applicability
) -> &mut DiagnosticBuilder<'a> where
    impl Iterator: Iterator<Item = String>, 
[src]

pub fn span_suggestion_short(
    &mut self,
    sp: Span,
    msg: &str,
    suggestion: String,
    applicability: Applicability
) -> &mut DiagnosticBuilder<'a>
[src]

pub fn span_suggestion_hidden(
    &mut self,
    sp: Span,
    msg: &str,
    suggestion: String,
    applicability: Applicability
) -> &mut DiagnosticBuilder<'a>
[src]

pub fn tool_only_span_suggestion(
    &mut self,
    sp: Span,
    msg: &str,
    suggestion: String,
    applicability: Applicability
) -> &mut DiagnosticBuilder<'a>
[src]

pub fn set_span<S>(&mut self, sp: S) -> &mut DiagnosticBuilder<'a> where
    S: Into<MultiSpan>, 
[src]

pub fn code(&mut self, s: DiagnosticId) -> &mut DiagnosticBuilder<'a>[src]

pub fn allow_suggestions(&mut self, allow: bool) -> &mut DiagnosticBuilder<'a>[src]

pub fn new(
    handler: &'a Handler,
    level: Level,
    message: &str
) -> DiagnosticBuilder<'a>
[src]

Convenience function for internal use, clients should use one of the struct_* methods on Handler.

pub fn new_with_code(
    handler: &'a Handler,
    level: Level,
    code: Option<DiagnosticId>,
    message: &str
) -> DiagnosticBuilder<'a>
[src]

Convenience function for internal use, clients should use one of the struct_* methods on Handler.

pub fn new_diagnostic(
    handler: &'a Handler,
    diagnostic: Diagnostic
) -> DiagnosticBuilder<'a>
[src]

Creates a new DiagnosticBuilder with an already constructed diagnostic.

Methods from Deref<Target = Diagnostic>

pub fn is_error(&self) -> bool[src]

pub fn cancel(&mut self)[src]

Cancel the diagnostic (a structured diagnostic must either be emitted or canceled or it will panic when dropped).

pub fn cancelled(&self) -> bool[src]

pub fn span_label<T>(&mut self, span: Span, label: T) -> &mut Diagnostic where
    T: Into<String>, 
[src]

Adds a span/label to be included in the resulting snippet. This is pushed onto the MultiSpan that was created when the diagnostic was first built. If you don't call this function at all, and you just supplied a Span to create the diagnostic, then the snippet will just include that Span, which is called the primary span.

pub fn replace_span_with(&mut self, after: Span) -> &mut Diagnostic[src]

pub fn note_expected_found(
    &mut self,
    label: &dyn Display,
    expected: DiagnosticStyledString,
    found: DiagnosticStyledString
) -> &mut Diagnostic
[src]

pub fn note_expected_found_extra(
    &mut self,
    label: &dyn Display,
    expected: DiagnosticStyledString,
    found: DiagnosticStyledString,
    expected_extra: &dyn Display,
    found_extra: &dyn Display
) -> &mut Diagnostic
[src]

pub fn note_trait_signature(
    &mut self,
    name: String,
    signature: String
) -> &mut Diagnostic
[src]

pub fn note(&mut self, msg: &str) -> &mut Diagnostic[src]

pub fn highlighted_note(&mut self, msg: Vec<(String, Style)>) -> &mut Diagnostic[src]

pub fn span_note<S>(&mut self, sp: S, msg: &str) -> &mut Diagnostic where
    S: Into<MultiSpan>, 
[src]

pub fn warn(&mut self, msg: &str) -> &mut Diagnostic[src]

pub fn span_warn<S>(&mut self, sp: S, msg: &str) -> &mut Diagnostic where
    S: Into<MultiSpan>, 
[src]

pub fn help(&mut self, msg: &str) -> &mut Diagnostic[src]

pub fn span_help<S>(&mut self, sp: S, msg: &str) -> &mut Diagnostic where
    S: Into<MultiSpan>, 
[src]

pub fn multipart_suggestion(
    &mut self,
    msg: &str,
    suggestion: Vec<(Span, String)>,
    applicability: Applicability
) -> &mut Diagnostic
[src]

pub fn tool_only_multipart_suggestion(
    &mut self,
    msg: &str,
    suggestion: Vec<(Span, String)>,
    applicability: Applicability
) -> &mut Diagnostic
[src]

Prints out a message with for a multipart suggestion without showing the suggested code.

This is intended to be used for suggestions that are obvious in what the changes need to be from the message, showing the span label inline would be visually unpleasant (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't improve understandability.

pub fn span_suggestion(
    &mut self,
    sp: Span,
    msg: &str,
    suggestion: String,
    applicability: Applicability
) -> &mut Diagnostic
[src]

Prints out a message with a suggested edit of the code.

In case of short messages and a simple suggestion, rustc displays it as a label:

try adding parentheses: `(tup.0).1`

The message

  • should not end in any punctuation (a : is added automatically)
  • should not be a question (avoid language like "did you mean")
  • should not contain any phrases like "the following", "as shown", etc.
  • may look like "to do xyz, use" or "to do xyz, use abc"
  • may contain a name of a function, variable, or type, but not whole expressions

See CodeSuggestion for more information.

pub fn span_suggestions<impl Iterator>(
    &mut self,
    sp: Span,
    msg: &str,
    suggestions: impl Iterator,
    applicability: Applicability
) -> &mut Diagnostic where
    impl Iterator: Iterator<Item = String>, 
[src]

Prints out a message with multiple suggested edits of the code.

pub fn span_suggestion_short(
    &mut self,
    sp: Span,
    msg: &str,
    suggestion: String,
    applicability: Applicability
) -> &mut Diagnostic
[src]

Prints out a message with a suggested edit of the code. If the suggestion is presented inline, it will only show the message and not the suggestion.

See CodeSuggestion for more information.

pub fn span_suggestion_hidden(
    &mut self,
    sp: Span,
    msg: &str,
    suggestion: String,
    applicability: Applicability
) -> &mut Diagnostic
[src]

Prints out a message with for a suggestion without showing the suggested code.

This is intended to be used for suggestions that are obvious in what the changes need to be from the message, showing the span label inline would be visually unpleasant (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't improve understandability.

pub fn tool_only_span_suggestion(
    &mut self,
    sp: Span,
    msg: &str,
    suggestion: String,
    applicability: Applicability
) -> &mut Diagnostic
[src]

Adds a suggestion to the json output, but otherwise remains silent/undisplayed in the cli.

This is intended to be used for suggestions that are very obvious in what the changes need to be from the message, but we still want other tools to be able to apply them.

pub fn set_span<S>(&mut self, sp: S) -> &mut Diagnostic where
    S: Into<MultiSpan>, 
[src]

pub fn code(&mut self, s: DiagnosticId) -> &mut Diagnostic[src]

pub fn get_code(&self) -> Option<DiagnosticId>[src]

pub fn message(&self) -> String[src]

pub fn styled_message(&self) -> &Vec<(String, Style)>[src]

pub fn copy_details_not_message(&mut self, from: &Diagnostic)[src]

Used by a lint. Copies over all details but the "main message".

pub fn sub(
    &mut self,
    level: Level,
    message: &str,
    span: MultiSpan,
    render_span: Option<MultiSpan>
)
[src]

Convenience function for internal use, clients should use one of the public methods above.

Trait Implementations

impl<'a> DerefMut for DiagnosticBuilder<'a>[src]

impl<'a> Deref for DiagnosticBuilder<'a>[src]

type Target = Diagnostic

The resulting type after dereferencing.

impl<'a> Drop for DiagnosticBuilder<'a>[src]

Destructor bomb - a DiagnosticBuilder must be either emitted or canceled or we emit a bug.

impl<'a> Clone for DiagnosticBuilder<'a>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'a> Debug for DiagnosticBuilder<'a>[src]

Auto Trait Implementations

impl<'a> !Send for DiagnosticBuilder<'a>

impl<'a> !Sync for DiagnosticBuilder<'a>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<E> SpecializationError for E[src]

impl<T> Send for T where
    T: ?Sized
[src]

impl<T> Sync for T where
    T: ?Sized
[src]

impl<T> Erased for T[src]