1
Fork 0

clarify span_label documentation

This commit is contained in:
Andy Russell 2020-11-15 22:39:51 -05:00
parent 603ab5bd6e
commit a78966df83
No known key found for this signature in database
GPG key ID: BE2221033EDBC374

View file

@ -184,16 +184,18 @@ impl<'a> DiagnosticBuilder<'a> {
self.cancel(); self.cancel();
} }
/// Adds a span/label to be included in the resulting snippet. /// Appends a labeled span to the diagnostic.
/// ///
/// This is pushed onto the [`MultiSpan`] that was created when the diagnostic /// Labels are used to convey additional context for the diagnostic's primary span. They will
/// was first built. That means it will be shown together with the original /// be shown together with the original diagnostic's span, *not* with spans added by
/// span/label, *not* a span added by one of the `span_{note,warn,help,suggestions}` methods. /// `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.
/// ///
/// This span is *not* considered a ["primary span"][`MultiSpan`]; only /// Implementation-wise, the label span is pushed onto the [`MultiSpan`] that was created when
/// the `Span` supplied when creating the diagnostic is primary. /// the diagnostic was constructed. However, the label span is *not* considered a
/// /// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is
/// [`MultiSpan`]: ../rustc_span/struct.MultiSpan.html /// primary.
pub fn span_label(&mut self, span: Span, label: impl Into<String>) -> &mut Self { pub fn span_label(&mut self, span: Span, label: impl Into<String>) -> &mut Self {
self.0.diagnostic.span_label(span, label); self.0.diagnostic.span_label(span, label);
self self