feat(source): Allow inner source type of a NamedSource to be borrowed (#254)

BREAKING CHANGE: This makes the `NamedSource` type generic over its `Source` type, instead of boxing it.
This commit is contained in:
Adam Curtis 2024-02-03 22:40:17 -05:00 committed by GitHub
parent fad0e76ad2
commit 1df3b1a537
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 78 additions and 75 deletions

View File

@ -110,7 +110,7 @@ struct MyBad {
// The Source that we're gonna be printing snippets out of. // The Source that we're gonna be printing snippets out of.
// This can be a String if you don't have or care about file names. // This can be a String if you don't have or care about file names.
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
// Snippets and highlights can be included in the diagnostic! // Snippets and highlights can be included in the diagnostic!
#[label("This bit here")] #[label("This bit here")]
bad_bit: SourceSpan, bad_bit: SourceSpan,

View File

@ -109,7 +109,7 @@
//! // The Source that we're gonna be printing snippets out of. //! // The Source that we're gonna be printing snippets out of.
//! // This can be a String if you don't have or care about file names. //! // This can be a String if you don't have or care about file names.
//! #[source_code] //! #[source_code]
//! src: NamedSource, //! src: NamedSource<String>,
//! // Snippets and highlights can be included in the diagnostic! //! // Snippets and highlights can be included in the diagnostic!
//! #[label("This bit here")] //! #[label("This bit here")]
//! bad_bit: SourceSpan, //! bad_bit: SourceSpan,

View File

@ -3,12 +3,12 @@ use crate::{MietteError, MietteSpanContents, SourceCode, SpanContents};
/// Utility struct for when you have a regular [`SourceCode`] type that doesn't /// Utility struct for when you have a regular [`SourceCode`] type that doesn't
/// implement `name`. For example [`String`]. Or if you want to override the /// implement `name`. For example [`String`]. Or if you want to override the
/// `name` returned by the `SourceCode`. /// `name` returned by the `SourceCode`.
pub struct NamedSource { pub struct NamedSource<S: SourceCode + 'static> {
source: Box<dyn SourceCode + 'static>, source: S,
name: String, name: String,
} }
impl std::fmt::Debug for NamedSource { impl<S: SourceCode> std::fmt::Debug for NamedSource<S> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("NamedSource") f.debug_struct("NamedSource")
.field("name", &self.name) .field("name", &self.name)
@ -17,12 +17,15 @@ impl std::fmt::Debug for NamedSource {
} }
} }
impl NamedSource { impl<S: SourceCode + 'static> NamedSource<S> {
/// Create a new `NamedSource` using a regular [`SourceCode`] and giving /// Create a new `NamedSource` using a regular [`SourceCode`] and giving
/// its returned [`SpanContents`] a name. /// its returned [`SpanContents`] a name.
pub fn new(name: impl AsRef<str>, source: impl SourceCode + Send + Sync + 'static) -> Self { pub fn new(name: impl AsRef<str>, source: S) -> Self
where
S: Send + Sync,
{
Self { Self {
source: Box::new(source), source,
name: name.as_ref().to_string(), name: name.as_ref().to_string(),
} }
} }
@ -34,12 +37,12 @@ impl NamedSource {
/// Returns a reference the inner [`SourceCode`] type for this /// Returns a reference the inner [`SourceCode`] type for this
/// `NamedSource`. /// `NamedSource`.
pub fn inner(&self) -> &(dyn SourceCode + 'static) { pub fn inner(&self) -> &S {
&*self.source &self.source
} }
} }
impl SourceCode for NamedSource { impl<S: SourceCode + 'static> SourceCode for NamedSource<S> {
fn read_span<'a>( fn read_span<'a>(
&'a self, &'a self,
span: &crate::SourceSpan, span: &crate::SourceSpan,

View File

@ -269,7 +269,7 @@ fn empty_source() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -348,7 +348,7 @@ fn single_line_highlight_span_full_line() {
#[diagnostic(severity(Error))] #[diagnostic(severity(Error))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<&'static str>,
#[label("This bit here")] #[label("This bit here")]
bad_bit: SourceSpan, bad_bit: SourceSpan,
} }
@ -379,7 +379,7 @@ fn single_line_with_wide_char() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -416,7 +416,7 @@ fn single_line_with_two_tabs() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -455,7 +455,7 @@ fn single_line_with_tab_in_middle() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -494,7 +494,7 @@ fn single_line_highlight() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -566,7 +566,7 @@ fn single_line_highlight_offset_zero() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -602,7 +602,7 @@ fn single_line_highlight_offset_end_of_line() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -638,7 +638,7 @@ fn single_line_highlight_include_end_of_line() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -675,7 +675,7 @@ fn single_line_highlight_include_end_of_line_crlf() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -712,7 +712,7 @@ fn single_line_highlight_with_empty_span() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -749,7 +749,7 @@ fn single_line_highlight_no_label() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label] #[label]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -785,7 +785,7 @@ fn single_line_highlight_at_line_start() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -910,7 +910,7 @@ fn multiple_same_line_highlights() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "x"] #[label = "x"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "y"] #[label = "y"]
@ -955,7 +955,7 @@ fn multiple_same_line_highlights_with_tabs_in_middle() -> Result<(), MietteError
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "x"] #[label = "x"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "y"] #[label = "y"]
@ -1002,7 +1002,7 @@ fn multiline_highlight_adjacent() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "these two lines"] #[label = "these two lines"]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -1075,7 +1075,7 @@ fn multiline_highlight_flyby() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "block 1"] #[label = "block 1"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "block 2"] #[label = "block 2"]
@ -1126,7 +1126,7 @@ fn multiline_highlight_no_label() -> Result<(), MietteError> {
#[source] #[source]
source: Inner, source: Inner,
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "block 1"] #[label = "block 1"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label] #[label]
@ -1190,7 +1190,7 @@ fn multiple_multiline_highlights_adjacent() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "this bit here"] #[label = "this bit here"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "also this bit"] #[label = "also this bit"]
@ -1236,7 +1236,7 @@ fn multiple_multiline_highlights_overlapping_lines() -> Result<(), MietteError>
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "this bit here"] #[label = "this bit here"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "also this bit"] #[label = "also this bit"]
@ -1264,7 +1264,7 @@ fn multiple_multiline_highlights_overlapping_offsets() -> Result<(), MietteError
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "this bit here"] #[label = "this bit here"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "also this bit"] #[label = "also this bit"]
@ -1346,7 +1346,7 @@ fn related() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
#[related] #[related]
@ -1402,7 +1402,7 @@ fn related_source_code_propagation() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
#[related] #[related]
@ -1462,7 +1462,7 @@ fn related_severity() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
#[related] #[related]
@ -1479,7 +1479,7 @@ fn related_severity() -> Result<(), MietteError> {
)] )]
Error { Error {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
}, },
@ -1492,7 +1492,7 @@ fn related_severity() -> Result<(), MietteError> {
)] )]
Warning { Warning {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
}, },
@ -1505,7 +1505,7 @@ fn related_severity() -> Result<(), MietteError> {
)] )]
Advice { Advice {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
}, },
@ -1588,7 +1588,7 @@ fn zero_length_eol_span() {
#[diagnostic(severity(Error))] #[diagnostic(severity(Error))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<&'static str>,
#[label("This bit here")] #[label("This bit here")]
bad_bit: SourceSpan, bad_bit: SourceSpan,
} }

View File

@ -29,7 +29,7 @@ fn single_line_with_wide_char() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -65,7 +65,7 @@ fn single_line_highlight() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -101,7 +101,7 @@ fn single_line_highlight_offset_zero() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -136,7 +136,7 @@ fn single_line_highlight_with_empty_span() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -172,7 +172,7 @@ fn single_line_highlight_no_label() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label] #[label]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -208,7 +208,7 @@ fn single_line_highlight_at_line_start() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -244,7 +244,7 @@ fn multiple_same_line_highlights() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "x"] #[label = "x"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "y"] #[label = "y"]
@ -288,7 +288,7 @@ fn multiline_highlight_adjacent() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "these two lines"] #[label = "these two lines"]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -325,7 +325,7 @@ fn multiline_highlight_flyby() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "block 1"] #[label = "block 1"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "block 2"] #[label = "block 2"]
@ -378,7 +378,7 @@ fn multiline_highlight_no_label() -> Result<(), MietteError> {
#[source] #[source]
source: Inner, source: Inner,
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "block 1"] #[label = "block 1"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label] #[label]
@ -444,7 +444,7 @@ fn multiple_multiline_highlights_adjacent() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "this bit here"] #[label = "this bit here"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "also this bit"] #[label = "also this bit"]
@ -492,7 +492,7 @@ fn multiple_multiline_highlights_overlapping_lines() -> Result<(), MietteError>
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "this bit here"] #[label = "this bit here"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "also this bit"] #[label = "also this bit"]
@ -520,7 +520,7 @@ fn multiple_multiline_highlights_overlapping_offsets() -> Result<(), MietteError
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "this bit here"] #[label = "this bit here"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "also this bit"] #[label = "also this bit"]
@ -559,7 +559,7 @@ fn related() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
#[related] #[related]
@ -614,7 +614,7 @@ fn related_source_code_propagation() -> Result<(), MietteError> {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
#[related] #[related]

View File

@ -10,7 +10,7 @@ fn enum_uses_base_attr() {
enum MyBad { enum MyBad {
Only { Only {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
}, },
@ -32,7 +32,7 @@ fn enum_uses_variant_attr() {
#[diagnostic(code(error::on::variant))] #[diagnostic(code(error::on::variant))]
Only { Only {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
}, },
@ -55,7 +55,7 @@ fn multiple_attrs_allowed_on_item() {
enum MyBad { enum MyBad {
Only { Only {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
}, },
@ -79,7 +79,7 @@ fn multiple_attrs_allowed_on_variant() {
#[diagnostic(help("try doing it correctly"))] #[diagnostic(help("try doing it correctly"))]
Only { Only {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
}, },
@ -104,7 +104,7 @@ fn attrs_can_be_split_between_item_and_variants() {
#[diagnostic(url("https://example.com/foo/bar"))] #[diagnostic(url("https://example.com/foo/bar"))]
Only { Only {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
}, },
@ -130,7 +130,7 @@ fn attr_not_required() {
enum MyBad { enum MyBad {
Only { Only {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
}, },

View File

@ -20,7 +20,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -65,7 +65,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -110,7 +110,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -155,7 +155,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -200,7 +200,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label] #[label]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -244,7 +244,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -289,7 +289,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "x"] #[label = "x"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "y"] #[label = "y"]
@ -354,7 +354,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "these two lines"] #[label = "these two lines"]
highlight: SourceSpan, highlight: SourceSpan,
} }
@ -399,7 +399,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "block 1"] #[label = "block 1"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "block 2"] #[label = "block 2"]
@ -463,7 +463,7 @@ mod json_report_handler {
#[source] #[source]
source: Inner, source: Inner,
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "block 1"] #[label = "block 1"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label] #[label]
@ -536,7 +536,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "this bit here"] #[label = "this bit here"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "also this bit"] #[label = "also this bit"]
@ -591,7 +591,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "this bit here"] #[label = "this bit here"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "also this bit"] #[label = "also this bit"]
@ -646,7 +646,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label = "this bit here"] #[label = "this bit here"]
highlight1: SourceSpan, highlight1: SourceSpan,
#[label = "also this bit"] #[label = "also this bit"]
@ -728,7 +728,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
#[related] #[related]
@ -821,7 +821,7 @@ mod json_report_handler {
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))] #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
struct MyBad { struct MyBad {
#[source_code] #[source_code]
src: NamedSource, src: NamedSource<String>,
#[label("this bit here")] #[label("this bit here")]
highlight: SourceSpan, highlight: SourceSpan,
#[related] #[related]