Struct rustc_ap_rustc_errors::DiagnosticBuilder [−][src]
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
.
Implementations
impl<'a> DiagnosticBuilder<'a>
[src]
pub fn emit(&mut self)
[src]
Emit the diagnostic.
pub fn emit_unless(&mut self, delay: bool)
[src]
Emit the diagnostic unless delay
is true,
in which case the emission will be delayed as a bug.
See emit
and delay_as_bug
for details.
pub fn stash(self, span: Span, key: StashKey)
[src]
Stashes diagnostic for possible later improvement in a different,
later stage of the compiler. The diagnostic can be accessed with
the provided span
and key
through Handler::steal_diagnostic()
.
As with buffer
, this is unless the handler has disabled such buffering.
pub fn into_diagnostic(self) -> Option<(Diagnostic, &'a Handler)>
[src]
Converts the builder to a Diagnostic
for later emission,
unless handler has disabled such buffering.
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: Into<MultiSpan>>(
&mut self,
level: Level,
message: &str,
span: Option<S>
) -> &mut Self
[src]
&mut self,
level: Level,
message: &str,
span: Option<S>
) -> &mut Self
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(&mut self, span: Span, label: impl Into<String>) -> &mut Self
[src]
Appends a labeled span to the diagnostic.
Labels are used to convey additional context for the diagnostic's primary span. They will
be shown together with the original diagnostic's span, not with spans added by
span_note
, span_help
, etc. Therefore, if the primary span is not displayable (because
the span is DUMMY_SP
or the source code isn't found), labels will not be displayed
either.
Implementation-wise, the label span is pushed onto the MultiSpan
that was created when
the diagnostic was constructed. However, the label span is not considered a
"primary span"; only the Span
supplied when creating the diagnostic is
primary.
pub fn span_labels(
&mut self,
spans: impl IntoIterator<Item = Span>,
label: impl AsRef<str>
) -> &mut Self
[src]
&mut self,
spans: impl IntoIterator<Item = Span>,
label: impl AsRef<str>
) -> &mut Self
Labels all the given spans with the provided label.
See Diagnostic::span_label()
for more information.
pub fn note_expected_found(
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString
) -> &mut Self
[src]
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString
) -> &mut Self
pub fn note_expected_found_extra(
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString,
expected_extra: &dyn Display,
found_extra: &dyn Display
) -> &mut Self
[src]
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString,
expected_extra: &dyn Display,
found_extra: &dyn Display
) -> &mut Self
pub fn note_unsuccessful_coercion(
&mut self,
expected: DiagnosticStyledString,
found: DiagnosticStyledString
) -> &mut Self
[src]
&mut self,
expected: DiagnosticStyledString,
found: DiagnosticStyledString
) -> &mut Self
pub fn note(&mut self, msg: &str) -> &mut Self
[src]
See Diagnostic::note()
.
pub fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
[src]
pub fn warn(&mut self, msg: &str) -> &mut Self
[src]
See Diagnostic::warn()
.
pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
[src]
pub fn help(&mut self, msg: &str) -> &mut Self
[src]
See Diagnostic::help()
.
pub fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
[src]
pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn multipart_suggestions(
&mut self,
msg: &str,
suggestions: Vec<Vec<(Span, String)>>,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
msg: &str,
suggestions: Vec<Vec<(Span, String)>>,
applicability: Applicability
) -> &mut Self
pub fn tool_only_multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn span_suggestions(
&mut self,
sp: Span,
msg: &str,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_verbose(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn span_suggestion_hidden(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
pub fn tool_only_span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
See Diagnostic::tool_only_span_suggestion()
for more information.
pub fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self
[src]
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self
[src]
pub fn code(&mut self, s: DiagnosticId) -> &mut Self
[src]
See Diagnostic::code()
.
pub fn allow_suggestions(&mut self, allow: bool) -> &mut Self
[src]
Allow attaching suggestions this diagnostic.
If this is set to false
, then any suggestions attached with the span_suggestion_*
methods after this is set to false
will be ignored.
Methods from Deref<Target = Diagnostic>
pub fn is_error(&self) -> bool
[src]
pub fn has_future_breakage(&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]
Check if this diagnostic was cancelled.
pub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self
[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. That means it will be shown together with the original
span/label, not a span added by one of the span_{note,warn,help,suggestions}
methods.
This span is not considered a "primary span"; only
the Span
supplied when creating the diagnostic is primary.
pub fn replace_span_with(&mut self, after: Span) -> &mut Self
[src]
pub fn note_expected_found(
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString
) -> &mut Self
[src]
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString
) -> &mut Self
pub fn note_unsuccessful_coercion(
&mut self,
expected: DiagnosticStyledString,
found: DiagnosticStyledString
) -> &mut Self
[src]
&mut self,
expected: DiagnosticStyledString,
found: DiagnosticStyledString
) -> &mut Self
pub fn note_expected_found_extra(
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString,
expected_extra: &dyn Display,
found_extra: &dyn Display
) -> &mut Self
[src]
&mut self,
expected_label: &dyn Display,
expected: DiagnosticStyledString,
found_label: &dyn Display,
found: DiagnosticStyledString,
expected_extra: &dyn Display,
found_extra: &dyn Display
) -> &mut Self
pub fn note_trait_signature(
&mut self,
name: String,
signature: String
) -> &mut Self
[src]
&mut self,
name: String,
signature: String
) -> &mut Self
pub fn note(&mut self, msg: &str) -> &mut Self
[src]
Add a note attached to this diagnostic.
pub fn highlighted_note(&mut self, msg: Vec<(String, Style)>) -> &mut Self
[src]
pub fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
[src]
Prints the span with a note above it.
This is like Diagnostic::note()
, but it gets its own span.
pub fn warn(&mut self, msg: &str) -> &mut Self
[src]
Add a warning attached to this diagnostic.
pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
[src]
Prints the span with a warning above it.
This is like Diagnostic::warn()
, but it gets its own span.
pub fn help(&mut self, msg: &str) -> &mut Self
[src]
Add a help message attached to this diagnostic.
pub fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self
[src]
Prints the span with some help above it.
This is like Diagnostic::help()
, but it gets its own span.
pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
Show a suggestion that has multiple parts to it. In other words, multiple changes need to be applied as part of this suggestion.
pub fn multipart_suggestions(
&mut self,
msg: &str,
suggestions: Vec<Vec<(Span, String)>>,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
msg: &str,
suggestions: Vec<Vec<(Span, String)>>,
applicability: Applicability
) -> &mut Self
Show multiple suggestions that have multiple parts.
See also Diagnostic::multipart_suggestion()
.
pub fn tool_only_multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability
) -> &mut Self
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 Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
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_suggestion_with_style(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability,
style: SuggestionStyle
) -> &mut Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability,
style: SuggestionStyle
) -> &mut Self
Diagnostic::span_suggestion()
but you can set the SuggestionStyle
.
pub fn span_suggestion_verbose(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
Always show the suggested change.
pub fn span_suggestions(
&mut self,
sp: Span,
msg: &str,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestions: impl Iterator<Item = String>,
applicability: Applicability
) -> &mut Self
Prints out a message with multiple suggested edits of the code.
See also Diagnostic::span_suggestion()
.
pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
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 Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
Prints out a message 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 Self
[src]
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability
) -> &mut Self
Adds a suggestion to the JSON output that will not be shown 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 tool_only_suggestion_with_metadata(
&mut self,
msg: &str,
applicability: Applicability,
tool_metadata: Json
)
[src]
&mut self,
msg: &str,
applicability: Applicability,
tool_metadata: Json
)
Adds a suggestion intended only for a tool. The intent is that the metadata encodes the suggestion in a tool-specific way, as it may not even directly involve Rust code.
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self
[src]
pub fn code(&mut self, s: DiagnosticId) -> &mut Self
[src]
pub fn clear_code(&mut self) -> &mut Self
[src]
pub fn get_code(&self) -> Option<DiagnosticId>
[src]
pub fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self
[src]
pub fn message(&self) -> String
[src]
pub fn styled_message(&self) -> &Vec<(String, Style)>
[src]
pub fn sub(
&mut self,
level: Level,
message: &str,
span: MultiSpan,
render_span: Option<MultiSpan>
)
[src]
&mut self,
level: Level,
message: &str,
span: MultiSpan,
render_span: Option<MultiSpan>
)
Convenience function for internal use, clients should use one of the public methods above.
Trait Implementations
impl<'a> Clone for DiagnosticBuilder<'a>
[src]
fn clone(&self) -> DiagnosticBuilder<'a>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Debug for DiagnosticBuilder<'a>
[src]
impl<'a> Deref for DiagnosticBuilder<'a>
[src]
impl<'a> DerefMut for DiagnosticBuilder<'a>
[src]
fn deref_mut(&mut self) -> &mut Diagnostic
[src]
impl<'a> Drop for DiagnosticBuilder<'a>
[src]
Destructor bomb - a DiagnosticBuilder
must be either emitted or canceled
or we emit a bug.
Auto Trait Implementations
impl<'a> !RefUnwindSafe for DiagnosticBuilder<'a>
impl<'a> !Send for DiagnosticBuilder<'a>
impl<'a> !Sync for DiagnosticBuilder<'a>
impl<'a> Unpin for DiagnosticBuilder<'a>
impl<'a> !UnwindSafe for DiagnosticBuilder<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<'a, T> Captures<'a> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Erased for T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> MaybeResult<T> for T
[src]
type Error = !
pub fn from(Result<T, <T as MaybeResult<T>>::Error>) -> T
[src]
pub fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>
[src]
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,