diff --git a/benches/bench.rs b/benches/bench.rs index 2adcc185..0df00ac4 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -25,7 +25,7 @@ fn simple() -> String { } }"#; let message = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element( Snippet::source(source) .line_start(51) .path("src/format.rs") @@ -69,15 +69,17 @@ fn fold(bencher: divan::Bencher<'_, '_>, context: usize) { (input, span) }) .bench_values(|(input, span)| { - let message = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element( - Snippet::source(&input).path("src/format.rs").annotation( - AnnotationKind::Context - .span(span) - .label("expected `Option` because of return type"), - ), - ), - ]; + let message = + &[ + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) + .element( + Snippet::source(&input).path("src/format.rs").annotation( + AnnotationKind::Context + .span(span) + .label("expected `Option` because of return type"), + ), + ), + ]; let renderer = Renderer::plain(); let rendered = renderer.render(message); diff --git a/examples/custom_error.rs b/examples/custom_error.rs index dde6e3f3..545f3a0e 100644 --- a/examples/custom_error.rs +++ b/examples/custom_error.rs @@ -18,7 +18,7 @@ pub static C: u32 = 0 - 1; let message = &[Group::with_title( Level::ERROR .with_name(Some("error: internal compiler error")) - .title("could not evaluate static initializer") + .primary_title("could not evaluate static initializer") .id("E0080"), ) .element( diff --git a/examples/custom_level.rs b/examples/custom_level.rs index 97ec9ab3..9cfc6c80 100644 --- a/examples/custom_level.rs +++ b/examples/custom_level.rs @@ -32,7 +32,7 @@ fn main() { let message = &[ Group::with_title( Level::ERROR - .title("`break` with value from a `while` loop") + .primary_title("`break` with value from a `while` loop") .id("E0571"), ) .element( @@ -53,7 +53,7 @@ fn main() { Group::with_title( Level::HELP .with_name(Some("suggestion")) - .title("use `break` on its own without a value inside this `while` loop"), + .primary_title("use `break` on its own without a value inside this `while` loop"), ) .element( Snippet::source(source) diff --git a/examples/expected_type.rs b/examples/expected_type.rs index 37120b38..c8f1c8cd 100644 --- a/examples/expected_type.rs +++ b/examples/expected_type.rs @@ -7,7 +7,7 @@ fn main() { range: <22, 25>,"#; let message = &[ - Group::with_title(Level::ERROR.title("expected type, found `22`")).element( + Group::with_title(Level::ERROR.primary_title("expected type, found `22`")).element( Snippet::source(source) .line_start(26) .path("examples/footer.rs") diff --git a/examples/footer.rs b/examples/footer.rs index e9d6b7ee..77854b2d 100644 --- a/examples/footer.rs +++ b/examples/footer.rs @@ -3,7 +3,7 @@ use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet}; fn main() { let message = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element( Snippet::source(" slices: vec![\"A\",") .line_start(13) .path("src/multislice.rs") @@ -11,7 +11,7 @@ fn main() { "expected struct `annotate_snippets::snippet::Slice`, found reference", )), ), - Group::with_title(Level::NOTE.title( + Group::with_title(Level::NOTE.primary_title( "expected type: `snippet::Annotation`\n found type: `__&__snippet::Annotation`", )), ]; diff --git a/examples/format.rs b/examples/format.rs index 5f9bad3f..072552eb 100644 --- a/examples/format.rs +++ b/examples/format.rs @@ -24,7 +24,7 @@ fn main() { } }"#; let message = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element( Snippet::source(source) .line_start(51) .path("src/format.rs") diff --git a/examples/highlight_message.rs b/examples/highlight_message.rs index 4ebe5f50..32a1cc82 100644 --- a/examples/highlight_message.rs +++ b/examples/highlight_message.rs @@ -34,7 +34,7 @@ fn main() { ); let message = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) .element( Snippet::source(source) .path("$DIR/highlighting.rs") @@ -50,7 +50,7 @@ fn main() { ), ) .element(Level::NOTE.message(&message)), - Group::with_title(Level::NOTE.title("function defined here")).element( + Group::with_title(Level::NOTE.primary_title("function defined here")).element( Snippet::source(source) .path("$DIR/highlighting.rs") .annotation(AnnotationKind::Context.span(200..333).label("")) diff --git a/examples/highlight_source.rs b/examples/highlight_source.rs index 5cedfa5b..c50250ac 100644 --- a/examples/highlight_source.rs +++ b/examples/highlight_source.rs @@ -9,7 +9,7 @@ const CON: Vec = vec![1, 2, 3]; //~ ERROR E0010 //~| ERROR cannot call non-const method fn main() {} "#; - let message = &[Group::with_title(Level::ERROR.title("allocations are not allowed in constants") + let message = &[Group::with_title(Level::ERROR.primary_title("allocations are not allowed in constants") .id("E0010")) .element( Snippet::source(source) diff --git a/examples/id_hyperlink.rs b/examples/id_hyperlink.rs index 9070b260..cca0c452 100644 --- a/examples/id_hyperlink.rs +++ b/examples/id_hyperlink.rs @@ -9,7 +9,7 @@ fn main() { "#; let message = &[Group::with_title( Level::ERROR - .title("mismatched types") + .primary_title("mismatched types") .id("E0308") .id_url("https://doc.rust-lang.org/error_codes/E0308.html"), ) diff --git a/examples/multislice.rs b/examples/multislice.rs index c494afa3..575bb6f7 100644 --- a/examples/multislice.rs +++ b/examples/multislice.rs @@ -1,19 +1,21 @@ use annotate_snippets::{Annotation, Group, Level, Renderer, Snippet}; fn main() { - let message = &[Group::with_title(Level::ERROR.title("mismatched types")) - .element( - Snippet::>::source("Foo") - .line_start(51) - .fold(false) - .path("src/format.rs"), - ) - .element( - Snippet::>::source("Faa") - .line_start(129) - .fold(false) - .path("src/display.rs"), - )]; + let message = &[ + Group::with_title(Level::ERROR.primary_title("mismatched types")) + .element( + Snippet::>::source("Foo") + .line_start(51) + .fold(false) + .path("src/format.rs"), + ) + .element( + Snippet::>::source("Faa") + .line_start(129) + .fold(false) + .path("src/display.rs"), + ), + ]; let renderer = Renderer::styled(); anstream::println!("{}", renderer.render(message)); diff --git a/examples/struct_name_as_context.rs b/examples/struct_name_as_context.rs index 94a3d521..6c25f1b4 100644 --- a/examples/struct_name_as_context.rs +++ b/examples/struct_name_as_context.rs @@ -9,23 +9,18 @@ fn main() { field6: usize, } "#; - let message = - &[ - Group::with_title( - Level::ERROR.title("functions are not allowed in struct definitions"), - ) - .element( - Snippet::source(source) - .path("$DIR/struct_name_as_context.rs") - .annotation(AnnotationKind::Primary.span(91..102)) - .annotation(AnnotationKind::Visible.span(0..8)), - ) - .element( - Level::HELP.message( - "unlike in C++, Java, and C#, functions are declared in `impl` blocks", - ), - ), - ]; + let message = &[Group::with_title( + Level::ERROR.primary_title("functions are not allowed in struct definitions"), + ) + .element( + Snippet::source(source) + .path("$DIR/struct_name_as_context.rs") + .annotation(AnnotationKind::Primary.span(91..102)) + .annotation(AnnotationKind::Visible.span(0..8)), + ) + .element( + Level::HELP.message("unlike in C++, Java, and C#, functions are declared in `impl` blocks"), + )]; let renderer = Renderer::styled(); anstream::println!("{}", renderer.render(message)); diff --git a/src/level.rs b/src/level.rs index 7aafe838..bc15f24c 100644 --- a/src/level.rs +++ b/src/level.rs @@ -53,14 +53,16 @@ impl<'a> Level<'a> { } impl<'a> Level<'a> { - /// A text [`Element`][crate::Element] to start a [`Group`][crate::Group] + /// Creates a [`Title`] that has bolded text, and is + /// intended to be used with the "primary" (first) + /// [`Group`][crate::Group] in a [`Report`][crate::Report]. /// /// See [`Group::with_title`][crate::Group::with_title] /// ///
/// /// Text passed to this function is considered "untrusted input", as such - /// all text is passed through a normalization function. Pre-styled text is + /// all text is passed through a normalization function. Styled text is /// not allowed to be passed to this function. /// ///
@@ -70,14 +72,37 @@ impl<'a> Level<'a> { /// ```rust /// # use annotate_snippets::{Group, Snippet, AnnotationKind, Level}; /// let input = &[ - /// Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) + /// Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) /// ]; /// ``` - pub fn title(self, text: impl Into>) -> Title<'a> { + pub fn primary_title(self, text: impl Into>) -> Title<'a> { + Title { + level: self, + id: None, + text: text.into(), + allows_styling: false, + } + } + + /// Creates a [`Title`] that is allowed to be styled, for more info see the + /// warning below. + /// + /// See [`Group::with_title`][crate::Group::with_title] + /// + ///
+ /// + /// Text passed to this function is allowed to be styled, as such all + /// text is considered "trusted input" and has no normalizations applied to + /// it. [`normalize_untrusted_str`](crate::normalize_untrusted_str) can be + /// used to normalize untrusted text before it is passed to this function. + /// + ///
+ pub fn secondary_title(self, text: impl Into>) -> Title<'a> { Title { level: self, id: None, text: text.into(), + allows_styling: true, } } @@ -85,7 +110,7 @@ impl<'a> Level<'a> { /// ///
/// - /// Text passed to this function is allowed to be pre-styled, as such all + /// Text passed to this function is allowed to be styled, as such all /// text is considered "trusted input" and has no normalizations applied to /// it. [`normalize_untrusted_str`](crate::normalize_untrusted_str) can be /// used to normalize untrusted text before it is passed to this function. @@ -97,7 +122,7 @@ impl<'a> Level<'a> { /// ```rust /// # use annotate_snippets::{Group, Snippet, AnnotationKind, Level}; /// let input = &[ - /// Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) + /// Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) /// .element( /// Level::NOTE /// .no_name() @@ -166,7 +191,7 @@ impl<'a> Level<'a> { /// let s: &str = include_bytes!("file.txt"); //~ ERROR mismatched types /// }"#; /// let input = &[ - /// Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) + /// Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) /// .element( /// Snippet::source(source) /// .path("$DIR/mismatched-types.rs") diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index c82907ca..ddc3045e 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -22,7 +22,7 @@ //! //! Group::with_title( //! Level::ERROR -//! .title("unresolved import `baz::zed`") +//! .primary_title("unresolved import `baz::zed`") //! .id("E0432") //! ) //! .element( @@ -596,7 +596,7 @@ impl Renderer { label_width }); - let (title_str, style) = if title.is_pre_styled() { + let (title_str, style) = if title.allows_styling() { (title.text().to_owned(), ElementStyle::NoStyle) } else { (normalize_whitespace(title.text()), title_element_style) @@ -2609,7 +2609,7 @@ trait MessageOrTitle { fn level(&self) -> &Level<'_>; fn id(&self) -> Option<&Id<'_>>; fn text(&self) -> &str; - fn is_pre_styled(&self) -> bool; + fn allows_styling(&self) -> bool; } impl MessageOrTitle for Title<'_> { @@ -2622,8 +2622,8 @@ impl MessageOrTitle for Title<'_> { fn text(&self) -> &str { self.text.as_ref() } - fn is_pre_styled(&self) -> bool { - false + fn allows_styling(&self) -> bool { + self.allows_styling } } @@ -2637,7 +2637,7 @@ impl MessageOrTitle for Message<'_> { fn text(&self) -> &str { self.text.as_ref() } - fn is_pre_styled(&self) -> bool { + fn allows_styling(&self) -> bool { true } } diff --git a/src/snippet.rs b/src/snippet.rs index 9bb44020..78ad264a 100644 --- a/src/snippet.rs +++ b/src/snippet.rs @@ -132,12 +132,13 @@ pub struct Padding; /// A text [`Element`] to start a [`Group`] /// -/// See [`Level::title`] to create this. +/// See [`Level::primary_title`] to create this. #[derive(Clone, Debug)] pub struct Title<'a> { pub(crate) level: Level<'a>, pub(crate) id: Option>, pub(crate) text: Cow<'a, str>, + pub(crate) allows_styling: bool, } impl<'a> Title<'a> { @@ -433,7 +434,7 @@ impl<'a> Patch<'a> { /// ```rust /// # use annotate_snippets::{Group, Snippet, AnnotationKind, Level, Origin}; /// let input = &[ -/// Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) +/// Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) /// .element( /// Origin::path("$DIR/mismatched-types.rs") /// ) diff --git a/tests/color/ann_eof.rs b/tests/color/ann_eof.rs index d188fd1a..6f192b9c 100644 --- a/tests/color/ann_eof.rs +++ b/tests/color/ann_eof.rs @@ -5,7 +5,7 @@ use snapbox::{assert_data_eq, file}; #[test] fn case() { let input = &[ - Group::with_title(Level::ERROR.title("expected `.`, `=`")).element( + Group::with_title(Level::ERROR.primary_title("expected `.`, `=`")).element( Snippet::source("asdf") .path("Cargo.toml") .line_start(1) diff --git a/tests/color/ann_insertion.rs b/tests/color/ann_insertion.rs index a0748e59..453cdc7c 100644 --- a/tests/color/ann_insertion.rs +++ b/tests/color/ann_insertion.rs @@ -5,7 +5,7 @@ use snapbox::{assert_data_eq, file}; #[test] fn case() { let input = &[ - Group::with_title(Level::ERROR.title("expected `.`, `=`")).element( + Group::with_title(Level::ERROR.primary_title("expected `.`, `=`")).element( Snippet::source("asf") .path("Cargo.toml") .line_start(1) diff --git a/tests/color/ann_multiline.rs b/tests/color/ann_multiline.rs index 1801c3bc..d855de82 100644 --- a/tests/color/ann_multiline.rs +++ b/tests/color/ann_multiline.rs @@ -11,7 +11,7 @@ fn case() { let input = &[Group::with_title( Level::ERROR - .title("pattern does not mention fields `lineno`, `content`") + .primary_title("pattern does not mention fields `lineno`, `content`") .id("E0027"), ) .element( diff --git a/tests/color/ann_multiline2.rs b/tests/color/ann_multiline2.rs index b8fa6152..fe1a1751 100644 --- a/tests/color/ann_multiline2.rs +++ b/tests/color/ann_multiline2.rs @@ -9,19 +9,22 @@ of an edge case of an annotation overflowing to exactly one character on next line. "#; - let input = &[ - Group::with_title(Level::ERROR.title("spacing error found").id("E####")).element( - Snippet::source(source) - .path("foo.txt") - .line_start(26) - .fold(false) - .annotation( - AnnotationKind::Primary - .span(11..19) - .label("this should not be on separate lines"), - ), - ), - ]; + let input = &[Group::with_title( + Level::ERROR + .primary_title("spacing error found") + .id("E####"), + ) + .element( + Snippet::source(source) + .path("foo.txt") + .line_start(26) + .fold(false) + .annotation( + AnnotationKind::Primary + .span(11..19) + .label("this should not be on separate lines"), + ), + )]; let expected = file!["ann_multiline2.term.svg"]; let renderer = Renderer::styled(); assert_data_eq!(renderer.render(input), expected); diff --git a/tests/color/ann_removed_nl.rs b/tests/color/ann_removed_nl.rs index e13b4bd5..ff5a717f 100644 --- a/tests/color/ann_removed_nl.rs +++ b/tests/color/ann_removed_nl.rs @@ -5,7 +5,7 @@ use snapbox::{assert_data_eq, file}; #[test] fn case() { let input = &[ - Group::with_title(Level::ERROR.title("expected `.`, `=`")).element( + Group::with_title(Level::ERROR.primary_title("expected `.`, `=`")).element( Snippet::source("asdf") .path("Cargo.toml") .line_start(1) diff --git a/tests/color/ensure_emoji_highlight_width.rs b/tests/color/ensure_emoji_highlight_width.rs index c454e238..c3662f1e 100644 --- a/tests/color/ensure_emoji_highlight_width.rs +++ b/tests/color/ensure_emoji_highlight_width.rs @@ -7,7 +7,7 @@ fn case() { let source = r#""haha this isn't a valid name 🐛" = { package = "libc", version = "0.1" } "#; - let input = &[Group::with_title(Level::ERROR.title("invalid character ` ` in package name: `haha this isn't a valid name 🐛`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)")) + let input = &[Group::with_title(Level::ERROR.primary_title("invalid character ` ` in package name: `haha this isn't a valid name 🐛`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)")) .element( Snippet::source(source) .path("") diff --git a/tests/color/first_snippet_is_primary.rs b/tests/color/first_snippet_is_primary.rs index e5bf71bd..537ec871 100644 --- a/tests/color/first_snippet_is_primary.rs +++ b/tests/color/first_snippet_is_primary.rs @@ -12,7 +12,7 @@ fn case() { }"#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) .element( Snippet::source(file_txt_source) .line_start(3) diff --git a/tests/color/fold_ann_multiline.rs b/tests/color/fold_ann_multiline.rs index 5115b951..9ce7dd70 100644 --- a/tests/color/fold_ann_multiline.rs +++ b/tests/color/fold_ann_multiline.rs @@ -29,7 +29,7 @@ fn case() { "#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element( Snippet::source(source) .path("src/format.rs") .line_start(51) diff --git a/tests/color/fold_bad_origin_line.rs b/tests/color/fold_bad_origin_line.rs index 1a04adbd..de2f255e 100644 --- a/tests/color/fold_bad_origin_line.rs +++ b/tests/color/fold_bad_origin_line.rs @@ -9,7 +9,7 @@ fn case() { invalid syntax "#; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("path/to/error.rs") .line_start(1) diff --git a/tests/color/fold_leading.rs b/tests/color/fold_leading.rs index f4d29e3a..dffa05d6 100644 --- a/tests/color/fold_leading.rs +++ b/tests/color/fold_leading.rs @@ -19,7 +19,7 @@ workspace = 20 let input = &[Group::with_title( Level::ERROR - .title("invalid type: integer `20`, expected a bool") + .primary_title("invalid type: integer `20`, expected a bool") .id("E0308"), ) .element( diff --git a/tests/color/fold_trailing.rs b/tests/color/fold_trailing.rs index 59455c02..408f00ab 100644 --- a/tests/color/fold_trailing.rs +++ b/tests/color/fold_trailing.rs @@ -18,7 +18,7 @@ edition = "2021" let input = &[Group::with_title( Level::ERROR - .title("invalid type: integer `20`, expected a lints table") + .primary_title("invalid type: integer `20`, expected a lints table") .id("E0308"), ) .element( diff --git a/tests/color/issue_9.rs b/tests/color/issue_9.rs index 162a9c4e..9acb1693 100644 --- a/tests/color/issue_9.rs +++ b/tests/color/issue_9.rs @@ -12,7 +12,7 @@ let y = x; x; "#; - let input = &[Group::with_title(Level::ERROR.title("expected one of `.`, `;`, `?`, or an operator, found `for`")) + let input = &[Group::with_title(Level::ERROR.primary_title("expected one of `.`, `;`, `?`, or an operator, found `for`")) .element( Snippet::source(source) .path("/code/rust/src/test/ui/annotate-snippet/suggestion.rs") diff --git a/tests/color/main.rs b/tests/color/main.rs index 0bc932f4..fe088acf 100644 --- a/tests/color/main.rs +++ b/tests/color/main.rs @@ -16,3 +16,4 @@ mod simple; mod strip_line; mod strip_line_char; mod strip_line_non_ws; +mod styled_title; diff --git a/tests/color/multiline_removal_suggestion.rs b/tests/color/multiline_removal_suggestion.rs index c5b7ecbd..4dcd61fe 100644 --- a/tests/color/multiline_removal_suggestion.rs +++ b/tests/color/multiline_removal_suggestion.rs @@ -67,7 +67,7 @@ fn main() {} let input = &[ Group::with_title( Level::ERROR - .title("`(bool, HashSet)` is not an iterator") + .primary_title("`(bool, HashSet)` is not an iterator") .id("E0277"), ) .element( @@ -86,13 +86,13 @@ fn main() {} .element( Level::NOTE.message("required for `(bool, HashSet)` to implement `IntoIterator`"), ), - Group::with_title(Level::NOTE.title("required by a bound in `flatten`")) + Group::with_title(Level::NOTE.primary_title("required by a bound in `flatten`")) .element( Origin::path("/rustc/FAKE_PREFIX/library/core/src/iter/traits/iterator.rs") .line(1556) .char_column(4), ), - Group::with_title(Level::HELP.title("consider removing this method call, as the receiver has type `std::vec::IntoIter>` and `std::vec::IntoIter>: Iterator` trivially holds")).element( + Group::with_title(Level::HELP.primary_title("consider removing this method call, as the receiver has type `std::vec::IntoIter>` and `std::vec::IntoIter>: Iterator` trivially holds")).element( Snippet::source(source) .path("$DIR/multiline-removal-suggestion.rs") diff --git a/tests/color/multiple_annotations.rs b/tests/color/multiple_annotations.rs index a92c72f6..23f0ac9e 100644 --- a/tests/color/multiple_annotations.rs +++ b/tests/color/multiple_annotations.rs @@ -15,7 +15,7 @@ fn case() { } "#; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .line_start(96) .fold(false) diff --git a/tests/color/simple.rs b/tests/color/simple.rs index 9e35cf58..9e0002b8 100644 --- a/tests/color/simple.rs +++ b/tests/color/simple.rs @@ -10,7 +10,7 @@ fn case() { "#; let input = &[Group::with_title( - Level::ERROR.title("expected one of `.`, `;`, `?`, or an operator, found `for`"), + Level::ERROR.primary_title("expected one of `.`, `;`, `?`, or an operator, found `for`"), ) .element( Snippet::source(source) diff --git a/tests/color/strip_line.rs b/tests/color/strip_line.rs index 8e30ac4e..1718d2d6 100644 --- a/tests/color/strip_line.rs +++ b/tests/color/strip_line.rs @@ -7,7 +7,7 @@ fn case() { let source = r#" let _: () = 42;"#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element( Snippet::source(source) .path("$DIR/whitespace-trimming.rs") .line_start(4) diff --git a/tests/color/strip_line_char.rs b/tests/color/strip_line_char.rs index e78b530b..b0c87767 100644 --- a/tests/color/strip_line_char.rs +++ b/tests/color/strip_line_char.rs @@ -7,7 +7,7 @@ fn case() { let source = r#" let _: () = 42ñ"#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element( Snippet::source(source) .path("$DIR/whitespace-trimming.rs") .line_start(4) diff --git a/tests/color/strip_line_non_ws.rs b/tests/color/strip_line_non_ws.rs index 7ef3ad57..b9600bbc 100644 --- a/tests/color/strip_line_non_ws.rs +++ b/tests/color/strip_line_non_ws.rs @@ -8,7 +8,7 @@ fn case() { "#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element( Snippet::source(source) .path("$DIR/non-whitespace-trimming.rs") .line_start(4) diff --git a/tests/color/styled_title.rs b/tests/color/styled_title.rs new file mode 100644 index 00000000..caf554ec --- /dev/null +++ b/tests/color/styled_title.rs @@ -0,0 +1,43 @@ +use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet}; +use anstyle::{AnsiColor, Effects, Style}; + +use snapbox::{assert_data_eq, file}; + +const MAGENTA: Style = AnsiColor::Magenta.on_default().effects(Effects::BOLD); +const BOLD: Style = Style::new().effects(Effects::BOLD); +#[test] +fn case() { + let source = r#"use b::CustomErrorHandler; +use c::cnb_runtime; + + + cnb_runtime(CustomErrorHandler {}); +"#; + + let title_1 = "the trait bound `CustomErrorHandler: ErrorHandler` is not satisfied"; + let title_2 = format!("{BOLD}there are {BOLD:#}{MAGENTA}multiple different versions{MAGENTA:#}{BOLD} of crate `{BOLD:#}{MAGENTA}c{MAGENTA:#}{BOLD}` in the dependency graph{BOLD:#}"); + + let label_1 = "the trait `ErrorHandler` is not implemented for `CustomErrorHandler`"; + let label_2 = "required by a bound introduced by this call"; + let label_3 = "one version of crate `c` is used here, as a dependency of crate `b`"; + let label_4 = + "one version of crate `c` is used here, as a direct dependency of the current crate"; + + let input = &[ + Group::with_title(Level::ERROR.primary_title(title_1).id("E0277")).element( + Snippet::source(source) + .path("src/main.rs") + .annotation(AnnotationKind::Primary.span(65..86).label(label_1)) + .annotation(AnnotationKind::Context.span(53..64).label(label_2)), + ), + Group::with_title(Level::HELP.secondary_title(title_2)).element( + Snippet::source(source) + .path("src/main.rs") + .annotation(AnnotationKind::Primary.span(4..5).label(label_3)) + .annotation(AnnotationKind::Primary.span(31..32).label(label_4)), + ), + ]; + let expected = file!["styled_title.term.svg"]; + let renderer = Renderer::styled(); + assert_data_eq!(renderer.render(input), expected); +} diff --git a/tests/color/styled_title.term.svg b/tests/color/styled_title.term.svg new file mode 100644 index 00000000..421370b3 --- /dev/null +++ b/tests/color/styled_title.term.svg @@ -0,0 +1,56 @@ + + + + + + + error[E0277]: the trait bound `CustomErrorHandler: ErrorHandler` is not satisfied + + --> src/main.rs:5:17 + + | + + 5 | cnb_runtime(CustomErrorHandler {}); + + | ----------- ^^^^^^^^^^^^^^^^^^^^^ the trait `ErrorHandler` is not implemented for `CustomErrorHandler` + + | | + + | required by a bound introduced by this call + + | + + help: there are multiple different versions of crate `c` in the dependency graph + + --> src/main.rs:1:5 + + | + + 1 | use b::CustomErrorHandler; + + | ^ one version of crate `c` is used here, as a dependency of crate `b` + + 2 | use c::cnb_runtime; + + | ^ one version of crate `c` is used here, as a direct dependency of the current crate + + + + diff --git a/tests/formatter.rs b/tests/formatter.rs index 1df32123..edab0c37 100644 --- a/tests/formatter.rs +++ b/tests/formatter.rs @@ -7,11 +7,13 @@ use snapbox::{assert_data_eq, str}; #[test] fn test_i_29() { - let snippets = &[Group::with_title(Level::ERROR.title("oops")).element( - Snippet::source("First line\r\nSecond oops line") - .path("") - .annotation(AnnotationKind::Primary.span(19..23).label("oops")), - )]; + let snippets = &[ + Group::with_title(Level::ERROR.primary_title("oops")).element( + Snippet::source("First line\r\nSecond oops line") + .path("") + .annotation(AnnotationKind::Primary.span(19..23).label("oops")), + ), + ]; let expected = str![[r#" error: oops --> :2:8 @@ -26,7 +28,7 @@ error: oops #[test] fn test_point_to_double_width_characters() { - let snippets = &[Group::with_title(Level::ERROR.title("")).element( + let snippets = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source("こんにちは、世界") .path("") .annotation(AnnotationKind::Primary.span(18..24).label("world")), @@ -46,7 +48,7 @@ error: #[test] fn test_point_to_double_width_characters_across_lines() { - let snippets = &[Group::with_title(Level::ERROR.title("")).element( + let snippets = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source("おはよう\nございます") .path("") .annotation(AnnotationKind::Primary.span(6..22).label("Good morning")), @@ -68,7 +70,7 @@ error: #[test] fn test_point_to_double_width_characters_multiple() { - let snippets = &[Group::with_title(Level::ERROR.title("")).element( + let snippets = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source("お寿司\n食べたい🍣") .path("") .annotation(AnnotationKind::Primary.span(0..9).label("Sushi1")) @@ -91,7 +93,7 @@ error: #[test] fn test_point_to_double_width_characters_mixed() { - let snippets = &[Group::with_title(Level::ERROR.title("")).element( + let snippets = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source("こんにちは、新しいWorld!") .path("") .annotation(AnnotationKind::Primary.span(18..32).label("New world")), @@ -112,7 +114,7 @@ error: #[test] fn test_format_title() { let input = &[Group::with_title( - Level::ERROR.title("This is a title").id("E0001"), + Level::ERROR.primary_title("This is a title").id("E0001"), )]; let expected = str![r#"error[E0001]: This is a title"#]; @@ -123,7 +125,7 @@ fn test_format_title() { #[test] fn test_format_snippet_only() { let source = "This is line 1\nThis is line 2"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::>::source(source) .line_start(5402) .fold(false), @@ -143,7 +145,7 @@ error: fn test_format_snippets_continuation() { let src_0 = "This is slice 1"; let src_1 = "This is slice 2"; - let input = &[Group::with_title(Level::ERROR.title("")) + let input = &[Group::with_title(Level::ERROR.primary_title("")) .element( Snippet::>::source(src_0) .line_start(5402) @@ -177,7 +179,7 @@ fn test_format_snippet_annotation_standalone() { let source = [line_1, line_2].join("\n"); // In line 2 let range = 22..24; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(&source) .line_start(5402) .fold(false) @@ -200,7 +202,7 @@ error: #[test] fn test_format_footer_title() { - let input = &[Group::with_title(Level::ERROR.title("")) + let input = &[Group::with_title(Level::ERROR.primary_title("")) .element(Level::ERROR.message("This __is__ a title"))]; let expected = str![[r#" error: @@ -216,7 +218,7 @@ error: fn test_i26() { let source = "short"; let label = "label"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source).line_start(0).annotation( AnnotationKind::Primary .span(0..source.len() + 2) @@ -230,7 +232,7 @@ fn test_i26() { #[test] fn test_source_content() { let source = "This is an example\nof content lines"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::>::source(source) .line_start(56) .fold(false), @@ -248,7 +250,7 @@ error: #[test] fn test_source_annotation_standalone_singleline() { let source = "tests"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .line_start(1) .annotation(AnnotationKind::Context.span(0..5).label("Example string")), @@ -266,7 +268,7 @@ error: #[test] fn test_source_annotation_standalone_multiline() { let source = "tests"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .line_start(1) .annotation(AnnotationKind::Context.span(0..5).label("Example string")) @@ -287,7 +289,7 @@ error: #[test] fn test_only_source() { - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::>::source("") .path("file.rs") .fold(false), @@ -305,7 +307,7 @@ error: #[test] fn test_anon_lines() { let source = "This is an example\nof content lines\n\nabc"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::>::source(source) .line_start(56) .fold(false), @@ -324,13 +326,15 @@ LL | abc #[test] fn issue_130() { - let input = &[Group::with_title(Level::ERROR.title("dummy")).element( - Snippet::source("foo\nbar\nbaz") - .path("file/path") - .line_start(3) - .annotation(AnnotationKind::Primary.span(4..11)), - // bar\nbaz - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("dummy")).element( + Snippet::source("foo\nbar\nbaz") + .path("file/path") + .line_start(3) + .annotation(AnnotationKind::Primary.span(4..11)), + // bar\nbaz + ), + ]; let expected = str![[r#" error: dummy @@ -350,7 +354,7 @@ fn unterminated_string_multiline() { a\" // ... "; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -372,7 +376,7 @@ error: #[test] fn char_and_nl_annotate_char() { let source = "a\r\nb"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -395,7 +399,7 @@ error: #[test] fn char_eol_annotate_char() { let source = "a\r\nb"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -416,7 +420,7 @@ error: #[test] fn char_eol_annotate_char_double_width() { - let snippets = &[Group::with_title(Level::ERROR.title("")).element( + let snippets = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source("こん\r\nにちは\r\n世界") .path("") .fold(false) @@ -441,11 +445,13 @@ error: #[test] fn annotate_newline_empty_span() { - let message = &[Group::with_title(Level::ERROR.title("bad")).element( - Snippet::source("\n\n\n\n\n\n\n") - .path("test.txt") - .annotation(AnnotationKind::Primary.span(0..0)), - )]; + let message = &[ + Group::with_title(Level::ERROR.primary_title("bad")).element( + Snippet::source("\n\n\n\n\n\n\n") + .path("test.txt") + .annotation(AnnotationKind::Primary.span(0..0)), + ), + ]; let expected_ascii = str![[r#" error: bad @@ -473,7 +479,7 @@ error: bad #[test] fn annotate_eol() { let source = "a\r\nb"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -496,7 +502,7 @@ error: #[test] fn annotate_eol2() { let source = "a\r\nb"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -519,7 +525,7 @@ error: #[test] fn annotate_eol3() { let source = "a\r\nb"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -542,7 +548,7 @@ error: #[test] fn annotate_eol4() { let source = "a\r\nb"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -564,7 +570,7 @@ error: #[test] fn annotate_eol_double_width() { - let snippets = &[Group::with_title(Level::ERROR.title("")).element( + let snippets = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source("こん\r\nにちは\r\n世界") .path("") .fold(false) @@ -590,7 +596,7 @@ error: #[test] fn multiline_eol_start() { let source = "a\r\nb"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -613,7 +619,7 @@ error: #[test] fn multiline_eol_start2() { let source = "a\r\nb"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -636,7 +642,7 @@ error: #[test] fn multiline_eol_start3() { let source = "a\nb"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -658,7 +664,7 @@ error: #[test] fn multiline_eol_start_double_width() { - let snippets = &[Group::with_title(Level::ERROR.title("")).element( + let snippets = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source("こん\r\nにちは\r\n世界") .path("") .fold(false) @@ -684,7 +690,7 @@ error: #[test] fn multiline_eol_start_eol_end() { let source = "a\nb\nc"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -708,7 +714,7 @@ error: #[test] fn multiline_eol_start_eol_end2() { let source = "a\r\nb\r\nc"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -733,7 +739,7 @@ error: #[test] fn multiline_eol_start_eol_end3() { let source = "a\r\nb\r\nc"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -757,7 +763,7 @@ error: #[test] fn multiline_eol_start_eof_end() { let source = "a\r\nb"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -780,7 +786,7 @@ error: #[test] fn multiline_eol_start_eof_end_double_width() { let source = "ん\r\nに"; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source) .path("file/path") .line_start(3) @@ -804,7 +810,7 @@ error: fn two_single_line_same_line() { let source = r#"bar = { version = "0.1.0", optional = true }"#; let input = &[ - Group::with_title(Level::ERROR.title("unused optional dependency")).element( + Group::with_title(Level::ERROR.primary_title("unused optional dependency")).element( Snippet::source(source) .path("Cargo.toml") .line_start(4) @@ -841,7 +847,7 @@ so is this bar = { version = "0.1.0", optional = true } "#; let input = &[ - Group::with_title(Level::ERROR.title("unused optional dependency")).element( + Group::with_title(Level::ERROR.primary_title("unused optional dependency")).element( Snippet::source(source) .line_start(4) .annotation( @@ -880,7 +886,7 @@ so is this bar = { version = "0.1.0", optional = true } "#; let input = &[ - Group::with_title(Level::ERROR.title("unused optional dependency")).element( + Group::with_title(Level::ERROR.primary_title("unused optional dependency")).element( Snippet::source(source) .line_start(4) .annotation( @@ -928,7 +934,7 @@ bar = { version = "0.1.0", optional = true } this is another line "#; let input = &[ - Group::with_title(Level::ERROR.title("unused optional dependency")).element( + Group::with_title(Level::ERROR.primary_title("unused optional dependency")).element( Snippet::source(source) .line_start(4) .annotation( @@ -978,12 +984,14 @@ error: unused optional dependency #[test] fn origin_correct_start_line() { let source = "aaa\nbbb\nccc\nddd\n"; - let input = &[Group::with_title(Level::ERROR.title("title")).element( - Snippet::source(source) - .path("origin.txt") - .fold(false) - .annotation(AnnotationKind::Primary.span(8..8 + 3).label("annotation")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("title")).element( + Snippet::source(source) + .path("origin.txt") + .fold(false) + .annotation(AnnotationKind::Primary.span(8..8 + 3).label("annotation")), + ), + ]; let expected = str![[r#" error: title @@ -1002,16 +1010,18 @@ error: title #[test] fn origin_correct_mid_line() { let source = "aaa\nbbb\nccc\nddd\n"; - let input = &[Group::with_title(Level::ERROR.title("title")).element( - Snippet::source(source) - .path("origin.txt") - .fold(false) - .annotation( - AnnotationKind::Primary - .span(8 + 1..8 + 3) - .label("annotation"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("title")).element( + Snippet::source(source) + .path("origin.txt") + .fold(false) + .annotation( + AnnotationKind::Primary + .span(8 + 1..8 + 3) + .label("annotation"), + ), + ), + ]; let expected = str![[r#" error: title @@ -1033,12 +1043,13 @@ fn two_suggestions_same_span() { let input_new = &[ Group::with_title( Level::ERROR - .title("expected value, found enum `A`") + .primary_title("expected value, found enum `A`") .id("E0423"), ) .element(Snippet::source(source).annotation(AnnotationKind::Primary.span(4..5))), Group::with_title( - Level::HELP.title("you might have meant to use one of the following enum variants"), + Level::HELP + .primary_title("you might have meant to use one of the following enum variants"), ) .element(Snippet::source(source).patch(Patch::new(4..5, "(A::Tuple())"))) .element(Snippet::source(source).patch(Patch::new(4..5, "A::Unit"))), @@ -1085,7 +1096,7 @@ fn main() { }"#; let input_new = &[Group::with_title(Level::ERROR - .title("no method named `pick` found for struct `Chaenomeles` in the current scope") + .primary_title("no method named `pick` found for struct `Chaenomeles` in the current scope") .id("E0599")).element( Snippet::source(source) .line_start(1) @@ -1101,7 +1112,7 @@ fn main() { .label("method not found in `Chaenomeles`"), ), ), - Group::with_title(Level::HELP.title( + Group::with_title(Level::HELP.primary_title( "the following traits which provide `pick` are implemented but not in scope; perhaps you want to import one of them", )) .element( @@ -1141,7 +1152,7 @@ fn single_line_non_overlapping_suggestions() { let input_new = &[ Group::with_title( Level::ERROR - .title("expected value, found enum `A`") + .primary_title("expected value, found enum `A`") .id("E0423"), ) .element( @@ -1149,11 +1160,12 @@ fn single_line_non_overlapping_suggestions() { .line_start(1) .annotation(AnnotationKind::Primary.span(4..5)), ), - Group::with_title(Level::HELP.title("make these changes and things will work")).element( - Snippet::source(source) - .patch(Patch::new(4..5, "(A::Tuple())")) - .patch(Patch::new(6..9, "bar")), - ), + Group::with_title(Level::HELP.primary_title("make these changes and things will work")) + .element( + Snippet::source(source) + .patch(Patch::new(4..5, "(A::Tuple())")) + .patch(Patch::new(6..9, "bar")), + ), ]; let expected = str![[r#" @@ -1176,16 +1188,22 @@ LL + (A::Tuple()).bar(); fn single_line_non_overlapping_suggestions2() { let source = r#" ThisIsVeryLong.foo();"#; let input_new = &[ - Group::with_title(Level::ERROR.title("Found `ThisIsVeryLong`").id("E0423")).element( + Group::with_title( + Level::ERROR + .primary_title("Found `ThisIsVeryLong`") + .id("E0423"), + ) + .element( Snippet::source(source) .line_start(1) .annotation(AnnotationKind::Primary.span(4..18)), ), - Group::with_title(Level::HELP.title("make these changes and things will work")).element( - Snippet::source(source) - .patch(Patch::new(4..18, "(A::Tuple())")) - .patch(Patch::new(19..22, "bar")), - ), + Group::with_title(Level::HELP.primary_title("make these changes and things will work")) + .element( + Snippet::source(source) + .patch(Patch::new(4..18, "(A::Tuple())")) + .patch(Patch::new(19..22, "bar")), + ), ]; let expected = str![[r#" @@ -1217,7 +1235,9 @@ fn multiple_replacements() { let input_new = &[ Group::with_title( Level::ERROR - .title("cannot borrow `*self` as mutable because it is also borrowed as immutable") + .primary_title( + "cannot borrow `*self` as mutable because it is also borrowed as immutable", + ) .id("E0502"), ) .element( @@ -1245,7 +1265,8 @@ fn multiple_replacements() { ), ), Group::with_title( - Level::HELP.title("try explicitly pass `&Self` into the Closure as an argument"), + Level::HELP + .primary_title("try explicitly pass `&Self` into the Closure as an argument"), ) .element( Snippet::source(source) @@ -1297,7 +1318,7 @@ fn main() { let input_new = &[ Group::with_title( Level::ERROR - .title("cannot borrow `chars` as mutable more than once at a time") + .primary_title("cannot borrow `chars` as mutable more than once at a time") .id("E0499"), ) .element( @@ -1319,7 +1340,7 @@ fn main() { .label("first borrow later used here"), ), ), - Group::with_title(Level::HELP.title( + Group::with_title(Level::HELP.primary_title( "if you want to call `next` on a iterator within the loop, consider using `while let`", )) .element( @@ -1377,7 +1398,7 @@ fn main() {}"#; let input_new = &[ Group::with_title( Level::ERROR - .title("failed to resolve: use of undeclared crate or module `st`") + .primary_title("failed to resolve: use of undeclared crate or module `st`") .id("E0433"), ) .element( @@ -1387,11 +1408,13 @@ fn main() {}"#; .label("use of undeclared crate or module `st`"), ), ), - Group::with_title(Level::HELP.title("there is a crate or module with a similar name")) - .element(Snippet::source(source).patch(Patch::new(122..124, "std"))), - Group::with_title(Level::HELP.title("consider importing this module")) + Group::with_title( + Level::HELP.primary_title("there is a crate or module with a similar name"), + ) + .element(Snippet::source(source).patch(Patch::new(122..124, "std"))), + Group::with_title(Level::HELP.primary_title("consider importing this module")) .element(Snippet::source(source).patch(Patch::new(1..1, "use std::cell;\n"))), - Group::with_title(Level::HELP.title("if you import `cell`, refer to it directly")) + Group::with_title(Level::HELP.primary_title("if you import `cell`, refer to it directly")) .element(Snippet::source(source).patch(Patch::new(122..126, ""))), ]; let expected = str![[r#" @@ -1440,7 +1463,9 @@ fn main() {}"#; let input_new = &[ Group::with_title( Level::ERROR - .title("the size for values of type `T` cannot be known at compilation time") + .primary_title( + "the size for values of type `T` cannot be known at compilation time", + ) .id("E0277"), ) .element( @@ -1457,10 +1482,9 @@ fn main() {}"#; .label("this type parameter needs to be `Sized`"), ), ), - Group::with_title( - Level::HELP - .title("consider removing the `?Sized` bound to make the type parameter `Sized`"), - ) + Group::with_title(Level::HELP.primary_title( + "consider removing the `?Sized` bound to make the type parameter `Sized`", + )) .element(Snippet::source(source).patch(Patch::new(52..85, ""))), ]; let expected = str![[r#" @@ -1502,7 +1526,7 @@ and where fn main() {}"#; let input_new = &[Group::with_title(Level::ERROR - .title("the size for values of type `T` cannot be known at compilation time") + .primary_title("the size for values of type `T` cannot be known at compilation time") .id("E0277")).element(Snippet::source(source) .line_start(1) .path("$DIR/removal-of-multiline-trait-bound-in-where-clause.rs") @@ -1519,7 +1543,7 @@ fn main() {}"#; )) ,Group::with_title( Level::NOTE - .title("required by an implicit `Sized` bound in `Wrapper`") + .primary_title("required by an implicit `Sized` bound in `Wrapper`") ).element( Snippet::source(source) .line_start(1) @@ -1532,7 +1556,7 @@ fn main() {}"#; ) ), Group::with_title( Level::HELP - .title("you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box`") + .primary_title("you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box`") ) .element( Snippet::source(source) @@ -1552,7 +1576,7 @@ fn main() {}"#; ),Group::with_title( Level::HELP - .title("consider removing the `?Sized` bound to make the type parameter `Sized`") + .primary_title("consider removing the `?Sized` bound to make the type parameter `Sized`") ).element( Snippet::source(source) @@ -1610,14 +1634,15 @@ zappy let input_new = &[ Group::with_title( Level::ERROR - .title("the size for values of type `T` cannot be known at compilation time") + .primary_title( + "the size for values of type `T` cannot be known at compilation time", + ) .id("E0277"), ), // We need an empty group here to ensure the HELP line is rendered correctly - Group::with_title( - Level::HELP - .title("consider removing the `?Sized` bound to make the type parameter `Sized`"), - ) + Group::with_title(Level::HELP.primary_title( + "consider removing the `?Sized` bound to make the type parameter `Sized`", + )) .element( Snippet::source(source) .line_start(7) @@ -1678,7 +1703,7 @@ fn main() { "#; let input_new = &[Group::with_title(Level::ERROR - .title("type mismatch resolving `>, ...>>, ...>>, ...> as Future>::Error == Foo`") + .primary_title("type mismatch resolving `>, ...>>, ...>>, ...> as Future>::Error == Foo`") .id("E0271")).element(Snippet::source(source) .line_start(4) .path("$DIR/E0271.rs") @@ -1688,7 +1713,7 @@ fn main() { .span(208..510) .label("type mismatch resolving `, ...>>, ...> as Future>::Error == Foo`"), )),Group::with_title( - Level::NOTE.title("expected this to be `Foo`") + Level::NOTE.primary_title("expected this to be `Foo`") ).element( Snippet::source(source) .line_start(4) @@ -1764,7 +1789,7 @@ fn main() { "#; let input_new = &[Group::with_title(Level::ERROR - .title("type mismatch resolving `>, ...>>, ...>>, ...> as Future>::Error == Foo`") + .primary_title("type mismatch resolving `>, ...>>, ...>>, ...> as Future>::Error == Foo`") .id("E0271")).element(Snippet::source(source) .line_start(4) .path("$DIR/E0271.rs") @@ -1774,7 +1799,7 @@ fn main() { .span(208..510) .label("type mismatch resolving `, ...>>, ...> as Future>::Error == Foo`"), )),Group::with_title( - Level::NOTE.title("expected this to be `Foo`") + Level::NOTE.primary_title("expected this to be `Foo`") ).element( Snippet::source(source) .line_start(4) @@ -1915,7 +1940,7 @@ fn main() { "#; let input_new = &[Group::with_title(Level::ERROR - .title("mismatched types") + .primary_title("mismatched types") .id("E0308")).element( Snippet::source(source) .line_start(7) @@ -1999,7 +2024,7 @@ fn main() { "#; let input_new = &[Group::with_title(Level::ERROR - .title("mismatched types") + .primary_title("mismatched types") .id("E0308")).element( Snippet::source(source) .line_start(7) @@ -2020,7 +2045,7 @@ fn main() { .message("expected fn pointer `for<'a> fn(Box<(dyn Any + Send + 'a)>) -> Pin<_>`\n found fn item `fn(Box<(dyn Any + Send + 'static)>) -> Pin<_> {wrapped_fn}`") , ),Group::with_title( - Level::NOTE.title("function defined here"), + Level::NOTE.primary_title("function defined here"), ).element( Snippet::source(source) .line_start(7) @@ -2065,11 +2090,13 @@ LL │ ┃ )>>) {} #[test] fn unicode_cut_handling() { let source = "version = \"0.1.0\"\n# Ensure that the spans from toml handle utf-8 correctly\nauthors = [\n { name = \"Z\u{351}\u{36b}\u{343}\u{36a}\u{302}\u{36b}\u{33d}\u{34f}\u{334}\u{319}\u{324}\u{31e}\u{349}\u{35a}\u{32f}\u{31e}\u{320}\u{34d}A\u{36b}\u{357}\u{334}\u{362}\u{335}\u{31c}\u{330}\u{354}L\u{368}\u{367}\u{369}\u{358}\u{320}G\u{311}\u{357}\u{30e}\u{305}\u{35b}\u{341}\u{334}\u{33b}\u{348}\u{34d}\u{354}\u{339}O\u{342}\u{30c}\u{30c}\u{358}\u{328}\u{335}\u{339}\u{33b}\u{31d}\u{333}\", email = 1 }\n]\n"; - let input = &[Group::with_title(Level::ERROR.title("title")).element( - Snippet::source(source) - .fold(false) - .annotation(AnnotationKind::Primary.span(85..228).label("annotation")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("title")).element( + Snippet::source(source) + .fold(false) + .annotation(AnnotationKind::Primary.span(85..228).label("annotation")), + ), + ]; let expected_ascii = str![[r#" error: title | @@ -2103,7 +2130,7 @@ error: title fn unicode_cut_handling2() { let source = "/*这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。*/?"; let input = &[Group::with_title(Level::ERROR - .title("expected item, found `?`")).element( + .primary_title("expected item, found `?`")).element( Snippet::source(source) .fold(false) .annotation(AnnotationKind::Primary.span(499..500).label("expected item")) @@ -2140,7 +2167,7 @@ error: expected item, found `?` fn unicode_cut_handling3() { let source = "/*这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。这是宽的。*/?"; let input = &[Group::with_title(Level::ERROR - .title("expected item, found `?`")).element( + .primary_title("expected item, found `?`")).element( Snippet::source(source) .fold(false) .annotation(AnnotationKind::Primary.span(251..254).label("expected item")) @@ -2177,7 +2204,7 @@ error: expected item, found `?` fn unicode_cut_handling4() { let source = "/*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*/?"; let input = &[Group::with_title(Level::ERROR - .title("expected item, found `?`")).element( + .primary_title("expected item, found `?`")).element( Snippet::source(source) .fold(false) .annotation(AnnotationKind::Primary.span(334..335).label("expected item")) @@ -2220,7 +2247,7 @@ fn main() { } "##; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element( Snippet::source(source) .path("$DIR/non-whitespace-trimming-unicode.rs") .annotation( @@ -2277,7 +2304,7 @@ fn main() { let input = &[ Group::with_title( Level::ERROR - .title("cannot add `&str` to `&str`") + .primary_title("cannot add `&str` to `&str`") .id("E0369"), ) .element( @@ -2294,12 +2321,14 @@ fn main() { .element( Level::NOTE.message("string concatenation requires an owned `String` on the left"), ), - Group::with_title(Level::HELP.title("create an owned `String` from a string reference")) - .element( - Snippet::source(source) - .path("$DIR/non-1-width-unicode-multiline-label.rs") - .patch(Patch::new(984..984, ".to_owned()")), - ), + Group::with_title( + Level::HELP.primary_title("create an owned `String` from a string reference"), + ) + .element( + Snippet::source(source) + .path("$DIR/non-1-width-unicode-multiline-label.rs") + .patch(Patch::new(984..984, ".to_owned()")), + ), ]; let expected_ascii = str![[r#" @@ -2355,13 +2384,13 @@ fn foo() { "##; let bin_source = "�|�\u{0002}!5�cc\u{0015}\u{0002}�Ӻi��WWj�ȥ�'�}�\u{0012}�J�ȉ��W�\u{001e}O�@����\u{001c}w�V���LO����\u{0014}[ \u{0003}_�'���SQ�~ذ��ų&��-\t��lN~��!@␌ _#���kQ��h�\u{001d}�:�\u{001c}\u{0007}�"; let input = &[Group::with_title(Level::ERROR - .title("couldn't read `$DIR/not-utf8.bin`: stream did not contain valid UTF-8")).element( + .primary_title("couldn't read `$DIR/not-utf8.bin`: stream did not contain valid UTF-8")).element( Snippet::source(source) .path("$DIR/not-utf8.rs") .annotation(AnnotationKind::Primary.span(136..160)), ), - Group::with_title(Level::NOTE.title("byte `193` is not valid utf-8")) + Group::with_title(Level::NOTE.primary_title("byte `193` is not valid utf-8")) .element( Snippet::source(bin_source) .path("$DIR/not-utf8.bin") @@ -2415,7 +2444,7 @@ fn secondary_title_no_level_text() { }"#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) .element( Snippet::source(source) .path("$DIR/mismatched-types.rs") @@ -2461,7 +2490,7 @@ fn secondary_title_custom_level_text() { }"#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) .element( Snippet::source(source) .path("$DIR/mismatched-types.rs") @@ -2531,7 +2560,7 @@ fn main() { let input = &[ Group::with_title( Level::ERROR - .title("`break` with value from a `while` loop") + .primary_title("`break` with value from a `while` loop") .id("E0571"), ) .element( @@ -2552,7 +2581,7 @@ fn main() { Group::with_title( Level::HELP .with_name(Some("suggestion")) - .title("use `break` on its own without a value inside this `while` loop") + .primary_title("use `break` on its own without a value inside this `while` loop") .id("S0123"), ) .element( @@ -2622,7 +2651,7 @@ zappy let input_new = &[Group::with_title( Level::ERROR - .title("the size for values of type `T` cannot be known at compilation time") + .primary_title("the size for values of type `T` cannot be known at compilation time") .id("E0277"), ) .element( @@ -2686,7 +2715,7 @@ fn main() { let long_title3 = "or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value"; let input = &[ - Group::with_title(Level::WARNING.title(long_title1)) + Group::with_title(Level::WARNING.primary_title(long_title1)) .element( Snippet::source(snippet_source) .path("lint_example.rs") @@ -2696,7 +2725,7 @@ fn main() { .element(Level::NOTE.message(long_title2)) .element(Level::NOTE.message("`#[warn(array_into_iter)]` on by default")), Group::with_title( - Level::HELP.title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"), + Level::HELP.primary_title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"), ) .element( Snippet::source(suggestion_source) @@ -2704,7 +2733,7 @@ fn main() { .line_start(3) .patch(Patch::new(10..19, "iter")), ), - Group::with_title(Level::HELP.title(long_title3)).element( + Group::with_title(Level::HELP.primary_title(long_title3)).element( Snippet::source(suggestion_source) .path("lint_example.rs") .line_start(3) @@ -2755,7 +2784,7 @@ fn main() { let long_title3 = "or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value"; let input = &[ - Group::with_title(Level::WARNING.title(long_title1)) + Group::with_title(Level::WARNING.primary_title(long_title1)) .element( Snippet::source(snippet_source) .path("lint_example.rs") @@ -2765,7 +2794,7 @@ fn main() { .element(Level::NOTE.message(long_title2)) .element(Level::NOTE.message("`#[warn(array_into_iter)]` on by default")), Group::with_title( - Level::HELP.title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"), + Level::HELP.primary_title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"), ) .element( Snippet::source(suggestion_source) @@ -2773,7 +2802,7 @@ fn main() { .line_start(3) .patch(Patch::new(10..19, "iter")), ), - Group::with_title(Level::HELP.title(long_title3)).element( + Group::with_title(Level::HELP.primary_title(long_title3)).element( Snippet::source(suggestion_source) .path("lint_example.rs") .line_start(3) @@ -2793,7 +2822,7 @@ fn snippet_no_path() { // Taken from: https://docs.python.org/3/library/typing.html#annotating-callable-objects let source = "def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ..."; - let input = &[Group::with_title(Level::ERROR.title("")).element( + let input = &[Group::with_title(Level::ERROR.primary_title("")).element( Snippet::source(source).annotation(AnnotationKind::Primary.span(4..12).label("annotation")), )]; @@ -2821,7 +2850,7 @@ fn multiple_snippet_no_path() { // Taken from: https://docs.python.org/3/library/typing.html#annotating-callable-objects let source = "def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ..."; - let input = &[Group::with_title(Level::ERROR.title("")) + let input = &[Group::with_title(Level::ERROR.primary_title("")) .element( Snippet::source(source) .annotation(AnnotationKind::Primary.span(4..12).label("annotation")), @@ -2878,17 +2907,20 @@ fn courier_to_des_moines_and_points_west(data: &[u32]) -> String { fn main() {} "#; - let input = &[ - Group::with_title(Level::ERROR.title("type annotations needed").id("E0282")) - .element( - Snippet::source(source) - .path("$DIR/issue-42234-unknown-receiver-type.rs") - .annotation(AnnotationKind::Primary.span(449..452).label( - "cannot infer type of the type parameter `S` declared on the method `sum`", - )), - ) - .element(Padding), - ]; + let input = + &[Group::with_title( + Level::ERROR + .primary_title("type annotations needed") + .id("E0282"), + ) + .element( + Snippet::source(source) + .path("$DIR/issue-42234-unknown-receiver-type.rs") + .annotation(AnnotationKind::Primary.span(449..452).label( + "cannot infer type of the type parameter `S` declared on the method `sum`", + )), + ) + .element(Padding)]; let expected_ascii = str![[r#" error[E0282]: type annotations needed @@ -2934,22 +2966,27 @@ fn main() {} "#; let input = &[ - Group::with_title(Level::ERROR.title("type annotations needed").id("E0282")) + Group::with_title( + Level::ERROR + .primary_title("type annotations needed") + .id("E0282"), + ) + .element( + Snippet::source(source) + .path("$DIR/issue-42234-unknown-receiver-type.rs") + .annotation(AnnotationKind::Primary.span(449..452).label( + "cannot infer type of the type parameter `S` declared on the method `sum`", + )), + ) + .element(Padding), + Group::with_title(Level::HELP.primary_title("consider specifying the generic argument")) .element( Snippet::source(source) .path("$DIR/issue-42234-unknown-receiver-type.rs") - .annotation(AnnotationKind::Primary.span(449..452).label( - "cannot infer type of the type parameter `S` declared on the method `sum`", - )), - ) - .element(Padding), - Group::with_title(Level::HELP.title("consider specifying the generic argument")).element( - Snippet::source(source) - .path("$DIR/issue-42234-unknown-receiver-type.rs") - .line_start(12) - .fold(true) - .patch(Patch::new(452..457, "::")), - ), + .line_start(12) + .fold(true) + .patch(Patch::new(452..457, "::")), + ), ]; let expected_ascii = str![[r#" @@ -3006,20 +3043,26 @@ fn main() {} "#; let input = &[ - Group::with_title(Level::ERROR.title("type annotations needed").id("E0282")).element( + Group::with_title( + Level::ERROR + .primary_title("type annotations needed") + .id("E0282"), + ) + .element( Snippet::source(source) .path("$DIR/issue-42234-unknown-receiver-type.rs") .annotation(AnnotationKind::Primary.span(449..452).label( "cannot infer type of the type parameter `S` declared on the method `sum`", )), ), - Group::with_title(Level::HELP.title("consider specifying the generic argument")).element( - Snippet::source(source) - .path("$DIR/issue-42234-unknown-receiver-type.rs") - .line_start(12) - .fold(true) - .patch(Patch::new(452..457, "::<_>")), - ), + Group::with_title(Level::HELP.primary_title("consider specifying the generic argument")) + .element( + Snippet::source(source) + .path("$DIR/issue-42234-unknown-receiver-type.rs") + .line_start(12) + .fold(true) + .patch(Patch::new(452..457, "::<_>")), + ), ]; let expected = str![[r#" error[E0282]: type annotations needed @@ -3051,7 +3094,7 @@ zappy let input_new = &[Group::with_title( Level::ERROR - .title("the size for values of type `T` cannot be known at compilation time") + .primary_title("the size for values of type `T` cannot be known at compilation time") .id("E0277"), ) .element( @@ -3086,7 +3129,7 @@ zappy let input_new = &[Group::with_title( Level::ERROR - .title("the size for values of type `T` cannot be known at compilation time") + .primary_title("the size for values of type `T` cannot be known at compilation time") .id("E0277"), ) .element( @@ -3142,7 +3185,7 @@ fn main() {} let input = &[Group::with_title( Level::ERROR - .title("no field `field` on type `Thing`") + .primary_title("no field `field` on type `Thing`") .id("E0609"), ) .element(Level::NOTE.message("a `Title` then a `Message`!?!?")) diff --git a/tests/rustc_tests.rs b/tests/rustc_tests.rs index 9a8682b1..04ef62bf 100644 --- a/tests/rustc_tests.rs +++ b/tests/rustc_tests.rs @@ -13,12 +13,14 @@ fn ends_on_col0() { fn foo() { } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation(AnnotationKind::Primary.span(10..13).label("test")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation(AnnotationKind::Primary.span(10..13).label("test")), + ), + ]; let expected = str![[r#" error: foo @@ -40,12 +42,14 @@ fn foo() { } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation(AnnotationKind::Primary.span(10..17).label("test")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation(AnnotationKind::Primary.span(10..17).label("test")), + ), + ]; let expected = str![[r#" error: foo --> test.rs:2:10 @@ -68,21 +72,23 @@ fn foo() { X2 Y2 } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(14..32) - .label("`X` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(17..35) - .label("`Y` is a good letter too"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(14..32) + .label("`X` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(17..35) + .label("`Y` is a good letter too"), + ), + ), + ]; let expected = str![[r#" error: foo @@ -108,21 +114,23 @@ fn foo() { Y1 X1 } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(14..27) - .label("`X` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(17..24) - .label("`Y` is a good letter too"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(14..27) + .label("`X` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(17..24) + .label("`Y` is a good letter too"), + ), + ), + ]; let expected = str![[r#" error: foo @@ -149,21 +157,23 @@ fn foo() { X3 Y3 Z3 } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(17..38) - .label("`X` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(31..49) - .label("`Y` is a good letter too"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(17..38) + .label("`X` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(31..49) + .label("`Y` is a good letter too"), + ), + ), + ]; let expected = str![[r#" error: foo @@ -190,22 +200,24 @@ fn foo() { X2 Y2 Z2 } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(14..38) - .label("`X` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(17..41) - .label("`Y` is a good letter too"), - ) - .annotation(AnnotationKind::Context.span(20..44).label("`Z` label")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(14..38) + .label("`X` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(17..41) + .label("`Y` is a good letter too"), + ) + .annotation(AnnotationKind::Context.span(20..44).label("`Z` label")), + ), + ]; let expected = str![[r#" error: foo @@ -234,22 +246,24 @@ fn foo() { X2 Y2 Z2 } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(14..38) - .label("`X` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(14..38) - .label("`Y` is a good letter too"), - ) - .annotation(AnnotationKind::Context.span(14..38).label("`Z` label")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(14..38) + .label("`X` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(14..38) + .label("`Y` is a good letter too"), + ) + .annotation(AnnotationKind::Context.span(14..38).label("`Z` label")), + ), + ]; // This should have a `^` but we currently don't support the idea of a // "primary" annotation, which would solve this @@ -279,22 +293,24 @@ fn foo() { X3 Y3 Z3 } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(17..27) - .label("`X` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(28..44) - .label("`Y` is a good letter too"), - ) - .annotation(AnnotationKind::Context.span(36..52).label("`Z`")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(17..27) + .label("`X` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(28..44) + .label("`Y` is a good letter too"), + ) + .annotation(AnnotationKind::Context.span(36..52).label("`Z`")), + ), + ]; let expected = str![[r#" error: foo @@ -326,21 +342,23 @@ fn foo() { X3 Y3 Z3 } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(14..27) - .label("`X` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(39..55) - .label("`Y` is a good letter too"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(14..27) + .label("`X` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(39..55) + .label("`Y` is a good letter too"), + ), + ), + ]; let expected = str![[r#" error: foo @@ -367,21 +385,23 @@ fn foo() { X3 Y3 Z3 } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(17..27) - .label("`X` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(31..55) - .label("`Y` is a good letter too"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(17..27) + .label("`X` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(31..55) + .label("`Y` is a good letter too"), + ), + ), + ]; let expected = str![[r#" error: foo @@ -407,18 +427,20 @@ fn foo() { a { b { c } d } } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation(AnnotationKind::Primary.span(18..25).label("")) - .annotation( - AnnotationKind::Context - .span(14..27) - .label("`a` is a good letter"), - ) - .annotation(AnnotationKind::Context.span(22..23).label("")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation(AnnotationKind::Primary.span(18..25).label("")) + .annotation( + AnnotationKind::Context + .span(14..27) + .label("`a` is a good letter"), + ) + .annotation(AnnotationKind::Context.span(22..23).label("")), + ), + ]; let expected = str![[r#" error: foo @@ -437,17 +459,19 @@ fn foo() { a { b { c } d } } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(14..27) - .label("`a` is a good letter"), - ) - .annotation(AnnotationKind::Context.span(18..25).label("")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(14..27) + .label("`a` is a good letter"), + ) + .annotation(AnnotationKind::Context.span(18..25).label("")), + ), + ]; let expected = str![[r#" error: foo @@ -466,18 +490,20 @@ fn foo() { a { b { c } d } } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(18..25) - .label("`b` is a good letter"), - ) - .annotation(AnnotationKind::Context.span(14..27).label("")) - .annotation(AnnotationKind::Context.span(22..23).label("")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(18..25) + .label("`b` is a good letter"), + ) + .annotation(AnnotationKind::Context.span(14..27).label("")) + .annotation(AnnotationKind::Context.span(22..23).label("")), + ), + ]; let expected = str![[r#" error: foo @@ -498,17 +524,19 @@ fn foo() { a { b { c } d } } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation(AnnotationKind::Primary.span(14..27).label("")) - .annotation( - AnnotationKind::Context - .span(18..25) - .label("`b` is a good letter"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation(AnnotationKind::Primary.span(14..27).label("")) + .annotation( + AnnotationKind::Context + .span(18..25) + .label("`b` is a good letter"), + ), + ), + ]; let expected = str![[r#" error: foo @@ -529,17 +557,19 @@ fn foo() { a bc d } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(14..18) - .label("`a` is a good letter"), - ) - .annotation(AnnotationKind::Context.span(18..22).label("")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(14..18) + .label("`a` is a good letter"), + ) + .annotation(AnnotationKind::Context.span(18..22).label("")), + ), + ]; let expected = str![[r#" error: foo @@ -560,13 +590,15 @@ fn foo() { a { b { c } d } } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation(AnnotationKind::Primary.span(14..27).label("")) - .annotation(AnnotationKind::Context.span(18..25).label("")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation(AnnotationKind::Primary.span(14..27).label("")) + .annotation(AnnotationKind::Context.span(18..25).label("")), + ), + ]; let expected = str![[r#" error: foo @@ -585,14 +617,16 @@ fn foo() { a { b { c } d } } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation(AnnotationKind::Primary.span(18..25).label("")) - .annotation(AnnotationKind::Context.span(14..27).label("")) - .annotation(AnnotationKind::Context.span(22..23).label("")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation(AnnotationKind::Primary.span(18..25).label("")) + .annotation(AnnotationKind::Context.span(14..27).label("")) + .annotation(AnnotationKind::Context.span(22..23).label("")), + ), + ]; let expected = str![[r#" error: foo @@ -611,21 +645,23 @@ fn foo() { a { b { c } d } } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(14..27) - .label("`a` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(18..25) - .label("`b` is a good letter"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(14..27) + .label("`a` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(18..25) + .label("`b` is a good letter"), + ), + ), + ]; let expected = str![[r#" error: foo @@ -647,16 +683,18 @@ fn foo() { a { b { c } d } } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(14..27) - .label("`a` is a good letter"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(14..27) + .label("`a` is a good letter"), + ), + ), + ]; let expected = str![[r#" error: foo @@ -675,12 +713,14 @@ fn foo() { a { b { c } d } } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation(AnnotationKind::Primary.span(14..27).label("")), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation(AnnotationKind::Primary.span(14..27).label("")), + ), + ]; let expected = str![[r#" error: foo @@ -712,21 +752,23 @@ fn foo() { X3 Y3 Z3 } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(17..27) - .label("`X` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(31..76) - .label("`Y` is a good letter too"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(17..27) + .label("`X` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(31..76) + .label("`Y` is a good letter too"), + ), + ), + ]; let expected = str![[r#" error: foo @@ -769,21 +811,23 @@ fn foo() { X3 Y3 Z3 } "#; - let input = &[Group::with_title(Level::ERROR.title("foo")).element( - Snippet::source(source) - .line_start(1) - .path("test.rs") - .annotation( - AnnotationKind::Primary - .span(17..73) - .label("`Y` is a good letter"), - ) - .annotation( - AnnotationKind::Context - .span(37..56) - .label("`Z` is a good letter too"), - ), - )]; + let input = &[ + Group::with_title(Level::ERROR.primary_title("foo")).element( + Snippet::source(source) + .line_start(1) + .path("test.rs") + .annotation( + AnnotationKind::Primary + .span(17..73) + .label("`Y` is a good letter"), + ) + .annotation( + AnnotationKind::Context + .span(37..56) + .label("`Z` is a good letter too"), + ), + ), + ]; let expected = str![[r#" error: foo @@ -820,31 +864,30 @@ fn issue_91334() { fn f(){||yield(((){), "#; - let input = - &[ - Group::with_title(Level::ERROR.title("this file contains an unclosed delimiter")) - .element( - Snippet::source(source) - .line_start(1) - .path("$DIR/issue-91334.rs") - .annotation( - AnnotationKind::Context - .span(151..152) - .label("unclosed delimiter"), - ) - .annotation( - AnnotationKind::Context - .span(159..160) - .label("unclosed delimiter"), - ) - .annotation( - AnnotationKind::Context - .span(164..164) - .label("missing open `(` for this delimiter"), - ) - .annotation(AnnotationKind::Primary.span(167..167)), - ), - ]; + let input = &[Group::with_title( + Level::ERROR.primary_title("this file contains an unclosed delimiter"), + ) + .element( + Snippet::source(source) + .line_start(1) + .path("$DIR/issue-91334.rs") + .annotation( + AnnotationKind::Context + .span(151..152) + .label("unclosed delimiter"), + ) + .annotation( + AnnotationKind::Context + .span(159..160) + .label("unclosed delimiter"), + ) + .annotation( + AnnotationKind::Context + .span(164..164) + .label("missing open `(` for this delimiter"), + ) + .annotation(AnnotationKind::Primary.span(167..167)), + )]; let expected = str![[r#" error: this file contains an unclosed delimiter --> $DIR/issue-91334.rs:7:23 @@ -893,7 +936,7 @@ fn main() { let input = &[ Group::with_title( Level::ERROR - .title("`break` with value from a `while` loop") + .primary_title("`break` with value from a `while` loop") .id("E0571"), ) .element( @@ -912,7 +955,8 @@ fn main() { ), ), Group::with_title( - Level::HELP.title("use `break` on its own without a value inside this `while` loop"), + Level::HELP + .primary_title("use `break` on its own without a value inside this `while` loop"), ) .element( Snippet::source(source) @@ -1098,7 +1142,7 @@ fn nsize() { let input = &[ Group::with_title( Level::ERROR - .title("`V0usize` cannot be safely transmuted into `[usize; 2]`") + .primary_title("`V0usize` cannot be safely transmuted into `[usize; 2]`") .id("E0277"), ) .element( @@ -1111,21 +1155,22 @@ fn nsize() { .label("the size of `V0usize` is smaller than the size of `[usize; 2]`"), ), ), - Group::with_title(Level::NOTE.title("required by a bound in `is_transmutable`")).element( - Snippet::source(source) - .line_start(1) - .path("$DIR/primitive_reprs_should_have_correct_length.rs") - .annotation( - AnnotationKind::Context - .span(225..240) - .label("required by a bound in this function"), - ) - .annotation( - AnnotationKind::Primary - .span(276..470) - .label("required by this bound in `is_transmutable`"), - ), - ), + Group::with_title(Level::NOTE.primary_title("required by a bound in `is_transmutable`")) + .element( + Snippet::source(source) + .line_start(1) + .path("$DIR/primitive_reprs_should_have_correct_length.rs") + .annotation( + AnnotationKind::Context + .span(225..240) + .label("required by a bound in this function"), + ) + .annotation( + AnnotationKind::Primary + .span(276..470) + .label("required by this bound in `is_transmutable`"), + ), + ), ]; let expected = str![[r#" error[E0277]: `V0usize` cannot be safely transmuted into `[usize; 2]` @@ -1180,7 +1225,7 @@ fn main() { } "#; let input = &[Group::with_title(Level::ERROR - .title("`&[u8; 0]` cannot be safely transmuted into `&[u16; 0]`") + .primary_title("`&[u8; 0]` cannot be safely transmuted into `&[u16; 0]`") .id("E027s7")).element( Snippet::source(source) .line_start(1) @@ -1247,7 +1292,7 @@ fn main() {} "#; let input = &[Group::with_title( Level::ERROR - .title("expected function, found `{integer}`") + .primary_title("expected function, found `{integer}`") .id("E0618"), ) .element( @@ -1339,7 +1384,7 @@ outer_macro!(FirstStruct, FirstAttrStruct); "#; let input = &[ Group::with_title(Level::WARNING - .title("non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module")) + .primary_title("non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module")) .element( Snippet::source(aux_source) .line_start(1) @@ -1371,7 +1416,7 @@ outer_macro!(FirstStruct, FirstAttrStruct); Level::NOTE .message("a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute") ), - Group::with_title(Level::NOTE.title("the lint level is defined here")) + Group::with_title(Level::NOTE.primary_title("the lint level is defined here")) .element( Snippet::source(source) .line_start(1) @@ -1468,7 +1513,7 @@ macro_rules! inline { let input = &[ Group::with_title( Level::ERROR - .title("can't call method `pow` on ambiguous numeric type `{integer}`") + .primary_title("can't call method `pow` on ambiguous numeric type `{integer}`") .id("E0689"), ) .element( @@ -1478,7 +1523,7 @@ macro_rules! inline { .annotation(AnnotationKind::Primary.span(916..919)), ), Group::with_title( - Level::HELP.title("you must specify a type for this binding, like `i32`"), + Level::HELP.primary_title("you must specify a type for this binding, like `i32`"), ) .element( Snippet::source(aux_source) @@ -1528,16 +1573,20 @@ fn courier_to_des_moines_and_points_west(data: &[u32]) -> String { fn main() {} "#; - let input = &[ - Group::with_title(Level::ERROR.title("type annotations needed").id("E0282")).element( + let input = + &[Group::with_title( + Level::ERROR + .primary_title("type annotations needed") + .id("E0282"), + ) + .element( Snippet::source(source) .line_start(1) .path("$DIR/issue-42234-unknown-receiver-type.rs") .annotation(AnnotationKind::Primary.span(536..539).label( "cannot infer type of the type parameter `S` declared on the method `sum`", )), - ), - ]; + )]; let expected = str![[r#" error[E0282]: type annotations needed --> $DIR/issue-42234-unknown-receiver-type.rs:15:10 @@ -1632,7 +1681,7 @@ fn main() {} let input = &[ Group::with_title( Level::ERROR - .title( + .primary_title( "non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered" ) .id("E0004")).element( @@ -1646,7 +1695,7 @@ fn main() {} .label("patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered") ), ), - Group::with_title(Level::NOTE.title("`NonEmptyEnum5` defined here")) + Group::with_title(Level::NOTE.primary_title("`NonEmptyEnum5` defined here")) .element( Snippet::source(source) .line_start(1) @@ -1664,7 +1713,7 @@ fn main() {} ), Group::with_title( Level::HELP - .title("ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown, or multiple match arms") + .primary_title("ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown, or multiple match arms") ) .element( Snippet::source(source) @@ -1727,7 +1776,7 @@ fn main() { } "#; let input = &[Group::with_title(Level::ERROR - .title("the trait alias `EqAlias` is not dyn compatible") + .primary_title("the trait alias `EqAlias` is not dyn compatible") .id("E0038")).element( Snippet::source(source) .line_start(1) @@ -1741,7 +1790,7 @@ fn main() { ), Group::with_title( Level::NOTE - .title("for a trait to be dyn compatible it needs to allow building a vtable\nfor more information, visit ")) + .primary_title("for a trait to be dyn compatible it needs to allow building a vtable\nfor more information, visit ")) .element( Origin::path("$SRC_DIR/core/src/cmp.rs") .line(334) @@ -1792,7 +1841,7 @@ const C: u8 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, fn main() {} "#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0038")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0038")).element( Snippet::source(source) .path("$DIR/long-span.rs") .annotation( @@ -1825,7 +1874,7 @@ const C: u8 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, fn main() {} "#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0038")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0038")).element( Snippet::source(source) .path("$DIR/long-span.rs") .annotation( @@ -1859,7 +1908,7 @@ const C: u8 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, fn main() {} "#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0038")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0038")).element( Snippet::source(source) .path("$DIR/long-span.rs") .annotation( @@ -1893,7 +1942,7 @@ const C: u8 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, fn main() {} "#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0038")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0038")).element( Snippet::source(source) .path("$DIR/long-span.rs") .annotation( @@ -1943,7 +1992,7 @@ fn main() { "#; let input = &[Group::with_title(Level::ERROR - .title("`Iterator::map` call that discard the iterator's values")) + .primary_title("`Iterator::map` call that discard the iterator's values")) .element( Snippet::source(source) .path("$DIR/lint_map_unit_fn.rs") @@ -1965,7 +2014,7 @@ fn main() { ) .element( Level::NOTE.message("`Iterator::map`, like many of the methods on `Iterator`, gets executed lazily, meaning that its effects won't be visible until it is iterated")), - Group::with_title(Level::HELP.title("you might have meant to use `Iterator::for_each`")) + Group::with_title(Level::HELP.primary_title("you might have meant to use `Iterator::for_each`")) .element( Snippet::source(source) .path("$DIR/lint_map_unit_fn.rs") @@ -2032,12 +2081,13 @@ fn main() { "#; let input = &[ - Group::with_title(Level::ERROR.title("character constant must be escaped: `\\n`")).element( - Snippet::source(source) - .path("$DIR/bad-char-literals.rs") - .annotation(AnnotationKind::Primary.span(204..205)), - ), - Group::with_title(Level::HELP.title("escape the character")).element( + Group::with_title(Level::ERROR.primary_title("character constant must be escaped: `\\n`")) + .element( + Snippet::source(source) + .path("$DIR/bad-char-literals.rs") + .annotation(AnnotationKind::Primary.span(204..205)), + ), + Group::with_title(Level::HELP.primary_title("escape the character")).element( Snippet::source(source) .path("$DIR/bad-char-literals.rs") .line_start(1) @@ -2079,16 +2129,17 @@ fn main() {} "#; let input = &[ - Group::with_title(Level::ERROR.title("unclosed frontmatter")).element( + Group::with_title(Level::ERROR.primary_title("unclosed frontmatter")).element( Snippet::source(source) .path("$DIR/unclosed-1.rs") .annotation(AnnotationKind::Primary.span(0..221)), ), - Group::with_title(Level::NOTE.title("frontmatter opening here was not closed")).element( - Snippet::source(source) - .path("$DIR/unclosed-1.rs") - .annotation(AnnotationKind::Primary.span(0..4)), - ), + Group::with_title(Level::NOTE.primary_title("frontmatter opening here was not closed")) + .element( + Snippet::source(source) + .path("$DIR/unclosed-1.rs") + .annotation(AnnotationKind::Primary.span(0..4)), + ), ]; let expected = str![[r#" error: unclosed frontmatter @@ -2131,16 +2182,17 @@ fn foo() -> &str { "#; let input = &[ - Group::with_title(Level::ERROR.title("unclosed frontmatter")).element( + Group::with_title(Level::ERROR.primary_title("unclosed frontmatter")).element( Snippet::source(source) .path("$DIR/unclosed-2.rs") .annotation(AnnotationKind::Primary.span(0..377)), ), - Group::with_title(Level::NOTE.title("frontmatter opening here was not closed")).element( - Snippet::source(source) - .path("$DIR/unclosed-2.rs") - .annotation(AnnotationKind::Primary.span(0..4)), - ), + Group::with_title(Level::NOTE.primary_title("frontmatter opening here was not closed")) + .element( + Snippet::source(source) + .path("$DIR/unclosed-2.rs") + .annotation(AnnotationKind::Primary.span(0..4)), + ), ]; let expected = str![[r#" error: unclosed frontmatter @@ -2185,14 +2237,16 @@ fn foo(x: i32) -> i32 { "#; let input = &[ - Group::with_title(Level::ERROR.title("invalid preceding whitespace for frontmatter close")) - .element( - Snippet::source(source) - .path("$DIR/unclosed-3.rs") - .annotation(AnnotationKind::Primary.span(302..310)), - ), Group::with_title( - Level::NOTE.title("frontmatter close should not be preceded by whitespace"), + Level::ERROR.primary_title("invalid preceding whitespace for frontmatter close"), + ) + .element( + Snippet::source(source) + .path("$DIR/unclosed-3.rs") + .annotation(AnnotationKind::Primary.span(302..310)), + ), + Group::with_title( + Level::NOTE.primary_title("frontmatter close should not be preceded by whitespace"), ) .element( Snippet::source(source) @@ -2233,16 +2287,17 @@ fn main() {} "#; let input = &[ - Group::with_title(Level::ERROR.title("unclosed frontmatter")).element( + Group::with_title(Level::ERROR.primary_title("unclosed frontmatter")).element( Snippet::source(source) .path("$DIR/unclosed-4.rs") .annotation(AnnotationKind::Primary.span(0..43)), ), - Group::with_title(Level::NOTE.title("frontmatter opening here was not closed")).element( - Snippet::source(source) - .path("$DIR/unclosed-4.rs") - .annotation(AnnotationKind::Primary.span(0..4)), - ), + Group::with_title(Level::NOTE.primary_title("frontmatter opening here was not closed")) + .element( + Snippet::source(source) + .path("$DIR/unclosed-4.rs") + .annotation(AnnotationKind::Primary.span(0..4)), + ), ]; let expected = str![[r#" error: unclosed frontmatter @@ -2280,16 +2335,17 @@ fn main() {} "#; let input = &[ - Group::with_title(Level::ERROR.title("unclosed frontmatter")).element( + Group::with_title(Level::ERROR.primary_title("unclosed frontmatter")).element( Snippet::source(source) .path("$DIR/unclosed-5.rs") .annotation(AnnotationKind::Primary.span(0..176)), ), - Group::with_title(Level::NOTE.title("frontmatter opening here was not closed")).element( - Snippet::source(source) - .path("$DIR/unclosed-5.rs") - .annotation(AnnotationKind::Primary.span(0..4)), - ), + Group::with_title(Level::NOTE.primary_title("frontmatter opening here was not closed")) + .element( + Snippet::source(source) + .path("$DIR/unclosed-5.rs") + .annotation(AnnotationKind::Primary.span(0..4)), + ), ]; let expected = str![[r#" @@ -2398,7 +2454,7 @@ pub enum E2 { let input = &[ Group::with_title( Level::ERROR - .title( + .primary_title( "expected unit struct, unit variant or constant, found tuple variant `E1::Z1`", ) .id(r#"E0532"#), @@ -2422,17 +2478,20 @@ pub enum E2 { .label("similarly named unit variant `Z0` defined here"), ), ), - Group::with_title(Level::HELP.title("use the tuple variant pattern syntax instead")) + Group::with_title( + Level::HELP.primary_title("use the tuple variant pattern syntax instead"), + ) + .element( + Snippet::source(source) + .path("$DIR/pat-tuple-field-count-cross.rs") + .patch(Patch::new(1760..1766, r#"E1::Z1()"#)), + ), + Group::with_title(Level::HELP.primary_title("a unit variant with a similar name exists")) .element( Snippet::source(source) .path("$DIR/pat-tuple-field-count-cross.rs") - .patch(Patch::new(1760..1766, r#"E1::Z1()"#)), + .patch(Patch::new(1764..1766, r#"Z0"#)), ), - Group::with_title(Level::HELP.title("a unit variant with a similar name exists")).element( - Snippet::source(source) - .path("$DIR/pat-tuple-field-count-cross.rs") - .patch(Patch::new(1764..1766, r#"Z0"#)), - ), ]; let expected = str![[r#" error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1` @@ -2472,26 +2531,29 @@ fn unterminated_nested_comment() { */ "#; - let input = &[ - Group::with_title(Level::ERROR.title("unterminated block comment").id("E0758")).element( - Snippet::source(source) - .path("$DIR/unterminated-nested-comment.rs") - .annotation( - AnnotationKind::Context - .span(0..2) - .label("unterminated block comment"), - ) - .annotation(AnnotationKind::Context.span(25..27).label( - "...as last nested comment starts here, maybe you want to close this instead?", - )) - .annotation( - AnnotationKind::Context - .span(28..30) - .label("...and last nested comment terminates here."), - ) - .annotation(AnnotationKind::Primary.span(0..31)), - ), - ]; + let input = &[Group::with_title( + Level::ERROR + .primary_title("unterminated block comment") + .id("E0758"), + ) + .element( + Snippet::source(source) + .path("$DIR/unterminated-nested-comment.rs") + .annotation( + AnnotationKind::Context + .span(0..2) + .label("unterminated block comment"), + ) + .annotation(AnnotationKind::Context.span(25..27).label( + "...as last nested comment starts here, maybe you want to close this instead?", + )) + .annotation( + AnnotationKind::Context + .span(28..30) + .label("...and last nested comment terminates here."), + ) + .annotation(AnnotationKind::Primary.span(0..31)), + )]; let expected = str![[r#" error[E0758]: unterminated block comment @@ -2528,7 +2590,7 @@ fn mismatched_types1() { }"#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) .element( Snippet::source(file_txt_source) .line_start(3) @@ -2590,7 +2652,7 @@ fn mismatched_types2() { }"#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) .element( Snippet::source(source) .path("$DIR/mismatched-types.rs") @@ -2643,7 +2705,7 @@ fn main() { "#; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element( + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element( Snippet::source(source) .path("$DIR/short-error-format.rs") .annotation( @@ -2657,7 +2719,7 @@ fn main() { .label("arguments to this function are incorrect"), ), ), - Group::with_title(Level::NOTE.title("function defined here")).element( + Group::with_title(Level::NOTE.primary_title("function defined here")).element( Snippet::source(source) .path("$DIR/short-error-format.rs") .annotation(AnnotationKind::Context.span(48..54).label("")) @@ -2691,7 +2753,7 @@ fn main() { let input = &[Group::with_title( Level::ERROR - .title("no method named `salut` found for type `u32` in the current scope") + .primary_title("no method named `salut` found for type `u32` in the current scope") .id("E0599"), ) .element( @@ -2727,7 +2789,7 @@ pub struct Foo; //~^ ERROR "#; let input = &[ - Group::with_title(Level::ERROR.title("this URL is not a hyperlink")) + Group::with_title(Level::ERROR.primary_title("this URL is not a hyperlink")) .element( Snippet::source(source_0) .path("$DIR/diagnostic-width.rs") @@ -2736,12 +2798,12 @@ pub struct Foo; //~^ ERROR .element( Level::NOTE.message("bare URLs are not automatically turned into clickable links"), ), - Group::with_title(Level::NOTE.title("the lint level is defined here")).element( + Group::with_title(Level::NOTE.primary_title("the lint level is defined here")).element( Snippet::source(source_0) .path("$DIR/diagnostic-width.rs") .annotation(AnnotationKind::Primary.span(49..67)), ), - Group::with_title(Level::HELP.title("use an automatic link instead")).element( + Group::with_title(Level::HELP.primary_title("use an automatic link instead")).element( Snippet::source(source_1) .path("$DIR/diagnostic-width.rs") .line_start(4) @@ -2789,7 +2851,7 @@ fn main() { let long_title3 = "or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value"; let input = &[ - Group::with_title(Level::WARNING.title(long_title1)) + Group::with_title(Level::WARNING.primary_title(long_title1)) .element( Snippet::source(source1) .path("lint_example.rs") @@ -2799,7 +2861,7 @@ fn main() { .element(Level::NOTE.message(long_title2)) .element(Level::NOTE.message("`#[warn(array_into_iter)]` on by default")), Group::with_title( - Level::HELP.title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"), + Level::HELP.primary_title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"), ) .element( Snippet::source(source2) @@ -2807,7 +2869,7 @@ fn main() { .line_start(3) .patch(Patch::new(10..19, "iter")), ), - Group::with_title(Level::HELP.title(long_title3)).element( + Group::with_title(Level::HELP.primary_title(long_title3)).element( Snippet::source(source2) .path("lint_example.rs") .line_start(3) @@ -2884,7 +2946,7 @@ fn main() { let input = &[ Group::with_title( Level::ERROR - .title("cannot add `Box` to `Box`") + .primary_title("cannot add `Box` to `Box`") .id("E0369"), ) .element( @@ -2895,7 +2957,7 @@ fn main() { .annotation(AnnotationKind::Primary.span(587..588)), ), Group::with_title( - Level::NOTE.title("the foreign item type `Box` doesn't implement `Add`"), + Level::NOTE.primary_title("the foreign item type `Box` doesn't implement `Add`"), ) .element( Origin::path("$SRC_DIR/alloc/src/boxed.rs") @@ -3011,7 +3073,7 @@ fn main() { let title_1 = "trait `Future` which provides `poll` is implemented but not in scope; perhaps you want to import it"; let input = &[ - Group::with_title(Level::ERROR.title(title_0).id("E0599")).element( + Group::with_title(Level::ERROR.primary_title(title_0).id("E0599")).element( Snippet::source(source) .path("$DIR/dont-project-to-specializable-projection.rs") .annotation( @@ -3036,7 +3098,7 @@ fn main() { .element( Level::HELP.message("items from traits can only be used if the trait is in scope"), ), - Group::with_title(Level::HELP.title(title_1)).element( + Group::with_title(Level::HELP.primary_title(title_1)).element( Snippet::source("struct MyStruct;\n") .path("$DIR/dont-project-to-specializable-projection.rs") .line_start(6) @@ -3114,7 +3176,7 @@ fn main() { "the foreign item types don't implement required traits for this operation to be valid"; let input = &[ - Group::with_title(Level::ERROR.title(title_0).id("E0369")).element( + Group::with_title(Level::ERROR.primary_title(title_0).id("E0369")).element( Snippet::source(source) .path("$DIR/binary-op-not-allowed-issue-125631.rs") .annotation( @@ -3129,7 +3191,7 @@ fn main() { ) .annotation(AnnotationKind::Primary.span(309..311)), ), - Group::with_title(Level::NOTE.title(title_1)) + Group::with_title(Level::NOTE.primary_title(title_1)) .element( Origin::path("$SRC_DIR/std/src/io/error.rs") .line(65) @@ -3201,16 +3263,18 @@ pub fn main() {} "#; let input = &[ - Group::with_title(Level::ERROR.title("cannot find derive macro `Eqr` in this scope")) - .element( - Snippet::source(source) - .path("$DIR/deriving-meta-unknown-trait.rs") - .annotation( - AnnotationKind::Primary - .span(9..12) - .label("help: a derive macro with a similar name exists: `Eq`"), - ), - ), + Group::with_title( + Level::ERROR.primary_title("cannot find derive macro `Eqr` in this scope"), + ) + .element( + Snippet::source(source) + .path("$DIR/deriving-meta-unknown-trait.rs") + .annotation( + AnnotationKind::Primary + .span(9..12) + .label("help: a derive macro with a similar name exists: `Eq`"), + ), + ), Group::with_level(Level::ERROR) .element( Origin::path("$SRC_DIR/core/src/cmp.rs") @@ -3289,7 +3353,7 @@ which is required by `Ipv4Addr: proc_macro::ext::RepToTokensExt` which is required by `&mut Ipv4Addr: proc_macro::ext::RepIteratorExt`"#; let input = &[ - Group::with_title(Level::ERROR.title(title_0).id("E0599")) + Group::with_title(Level::ERROR.primary_title(title_0).id("E0599")) .element( Snippet::source(source) .path("$DIR/not-repeatable.rs") @@ -3300,7 +3364,7 @@ which is required by `&mut Ipv4Addr: proc_macro::ext::RepIteratorExt`"#; ) .element(Level::NOTE.message(title_1)), Group::with_title( - Level::NOTE.title("the traits `Iterator` and `ToTokens` must be implemented"), + Level::NOTE.primary_title("the traits `Iterator` and `ToTokens` must be implemented"), ) .element( Origin::path("$SRC_DIR/proc_macro/src/to_tokens.rs") @@ -3405,7 +3469,7 @@ fn main() { let input = &[Group::with_title( Level::ERROR - .title("associated type `Pr` not found for `S` in the current scope") + .primary_title("associated type `Pr` not found for `S` in the current scope") .id("E0220"), ) .element( @@ -3470,7 +3534,7 @@ fn main() {} let title_1 = "for more information, see "; let input = &[ - Group::with_title(Level::ERROR.title("extern blocks should be unsafe")) + Group::with_title(Level::ERROR.primary_title("extern blocks should be unsafe")) .element( Snippet::source(source) .path("$DIR/unsafe-extern-suggestion.rs") @@ -3483,7 +3547,7 @@ fn main() {} ) .element(Level::WARNING.message(title_0)) .element(Level::NOTE.message(title_1)), - Group::with_title(Level::NOTE.title("the lint level is defined here")).element( + Group::with_title(Level::NOTE.primary_title("the lint level is defined here")).element( Snippet::source(source) .path("$DIR/unsafe-extern-suggestion.rs") .annotation(AnnotationKind::Primary.span(25..49)), @@ -3544,7 +3608,7 @@ fn panic(_: &core::panic::PanicInfo) -> ! { loop {} } "`core::alloc::Layout` and `Layout` have similar names, but are actually distinct types"; let input = &[ - Group::with_title(Level::ERROR.title("mismatched types").id("E0308")) + Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")) .element( Snippet::source(source) .path("$DIR/alloc-error-handler-bad-signature-2.rs") @@ -3565,18 +3629,21 @@ fn panic(_: &core::panic::PanicInfo) -> ! { loop {} } ), ) .element(Level::NOTE.message(title_0)), - Group::with_title(Level::NOTE.title("`core::alloc::Layout` is defined in crate `core`")) + Group::with_title( + Level::NOTE.primary_title("`core::alloc::Layout` is defined in crate `core`"), + ) + .element( + Origin::path("$SRC_DIR/core/src/alloc/layout.rs") + .line(40) + .char_column(0), + ), + Group::with_title(Level::NOTE.primary_title("`Layout` is defined in the current crate")) .element( - Origin::path("$SRC_DIR/core/src/alloc/layout.rs") - .line(40) - .char_column(0), + Snippet::source(source) + .path("$DIR/alloc-error-handler-bad-signature-2.rs") + .annotation(AnnotationKind::Primary.span(91..104)), ), - Group::with_title(Level::NOTE.title("`Layout` is defined in the current crate")).element( - Snippet::source(source) - .path("$DIR/alloc-error-handler-bad-signature-2.rs") - .annotation(AnnotationKind::Primary.span(91..104)), - ), - Group::with_title(Level::NOTE.title("function defined here")).element( + Group::with_title(Level::NOTE.primary_title("function defined here")).element( Snippet::source(source) .path("$DIR/alloc-error-handler-bad-signature-2.rs") .annotation(AnnotationKind::Context.span(142..154).label("")) @@ -3656,20 +3723,19 @@ fn main() { } "#; - let input = - &[ - Group::with_title(Level::WARNING.title(r#"whitespace symbol '\u{a0}' is not skipped"#)) - .element( - Snippet::source(source) - .path("$DIR/str-escape.rs") - .annotation( - AnnotationKind::Context - .span(203..205) - .label(r#"whitespace symbol '\u{a0}' is not skipped"#), - ) - .annotation(AnnotationKind::Primary.span(199..205)), - ), - ]; + let input = &[Group::with_title( + Level::WARNING.primary_title(r#"whitespace symbol '\u{a0}' is not skipped"#), + ) + .element( + Snippet::source(source) + .path("$DIR/str-escape.rs") + .annotation( + AnnotationKind::Context + .span(203..205) + .label(r#"whitespace symbol '\u{a0}' is not skipped"#), + ) + .annotation(AnnotationKind::Primary.span(199..205)), + )]; let expected = str![[r#" warning: whitespace symbol '\u{a0}' is not skipped --> $DIR/str-escape.rs:12:18 @@ -3713,7 +3779,7 @@ fn main() { let title_2 = "ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown"; let input = &[ - Group::with_title(Level::ERROR.title(title_0).id("E0004")).element( + Group::with_title(Level::ERROR.primary_title(title_0).id("E0004")).element( Snippet::source(source) .path("$DIR/match-privately-empty.rs") .annotation( @@ -3722,7 +3788,7 @@ fn main() { .label("pattern `Some(Private { misc: true, .. })` not covered"), ), ), - Group::with_title(Level::NOTE.title(title_1)) + Group::with_title(Level::NOTE.primary_title(title_1)) .element( Origin::path("$SRC_DIR/core/src/option.rs") .line(593) @@ -3736,7 +3802,7 @@ fn main() { .element(Padding) .element(Level::NOTE.message("not covered")) .element(Level::NOTE.message("the matched value is of type `Option`")), - Group::with_title(Level::HELP.title(title_2)).element( + Group::with_title(Level::HELP.primary_title(title_2)).element( Snippet::source(source) .path("$DIR/match-privately-empty.rs") .line_start(17) @@ -3798,7 +3864,7 @@ for more information, visit for more details", - )), - ]; + let input = &[Group::with_title( + Level::ERROR.primary_title("invalid `--check-cfg` argument: `cfg(`"), + ) + .element( + Level::NOTE.message(r#"expected `cfg(name, values("value1", "value2", ... "valueN"))`"#), + ) + .element( + Level::NOTE.message( + "visit for more details", + ), + )]; let expected = str![[r#" error: invalid `--check-cfg` argument: `cfg(` | @@ -4595,14 +4666,14 @@ If your compilation actually takes a long time, you can safely allow the lint."; let title_1 = "this error originates in the macro `uint_impl` (in Nightly builds, run with -Z macro-backtrace for more info)"; let input = &[ - Group::with_title(Level::ERROR.title("constant evaluation is taking a long time")) + Group::with_title(Level::ERROR.primary_title("constant evaluation is taking a long time")) .element( Origin::path("$SRC_DIR/core/src/num/mod.rs") .line(1151) .char_column(4), ) .element(Level::NOTE.message(title_0)), - Group::with_title(Level::HELP.title("the constant being evaluated")) + Group::with_title(Level::HELP.primary_title("the constant being evaluated")) .element( Snippet::source(source) .path("$DIR/timeout.rs")