Skip to content

Commit b9dc9e5

Browse files
authored
Merge pull request rust-lang#282 from Muscraft/fix-bad-primary-title-usage
fix: Use secondary_title for Groups after the first
2 parents 6adb579 + 248f697 commit b9dc9e5

File tree

6 files changed

+129
-122
lines changed

6 files changed

+129
-122
lines changed

examples/custom_level.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,38 @@ fn main() {
2929
}
3030
}
3131
"#;
32-
let report = &[
33-
Group::with_title(
34-
Level::ERROR
35-
.primary_title("`break` with value from a `while` loop")
36-
.id("E0571"),
37-
)
38-
.element(
39-
Snippet::source(source)
40-
.line_start(1)
41-
.path("$DIR/issue-114529-illegal-break-with-value.rs")
42-
.annotation(
43-
AnnotationKind::Primary
44-
.span(483..581)
45-
.label("can only break with a value inside `loop` or breakable block"),
46-
)
47-
.annotation(
48-
AnnotationKind::Context
49-
.span(462..472)
50-
.label("you can't `break` with a value in a `while` loop"),
51-
),
52-
),
53-
Group::with_title(
54-
Level::HELP
55-
.with_name(Some("suggestion"))
56-
.primary_title("use `break` on its own without a value inside this `while` loop"),
57-
)
58-
.element(
59-
Snippet::source(source)
60-
.line_start(1)
61-
.path("$DIR/issue-114529-illegal-break-with-value.rs")
62-
.patch(Patch::new(483..581, "break")),
63-
),
64-
];
32+
let report =
33+
&[
34+
Group::with_title(
35+
Level::ERROR
36+
.primary_title("`break` with value from a `while` loop")
37+
.id("E0571"),
38+
)
39+
.element(
40+
Snippet::source(source)
41+
.line_start(1)
42+
.path("$DIR/issue-114529-illegal-break-with-value.rs")
43+
.annotation(
44+
AnnotationKind::Primary
45+
.span(483..581)
46+
.label("can only break with a value inside `loop` or breakable block"),
47+
)
48+
.annotation(
49+
AnnotationKind::Context
50+
.span(462..472)
51+
.label("you can't `break` with a value in a `while` loop"),
52+
),
53+
),
54+
Group::with_title(Level::HELP.with_name(Some("suggestion")).secondary_title(
55+
"use `break` on its own without a value inside this `while` loop",
56+
))
57+
.element(
58+
Snippet::source(source)
59+
.line_start(1)
60+
.path("$DIR/issue-114529-illegal-break-with-value.rs")
61+
.patch(Patch::new(483..581, "break")),
62+
),
63+
];
6564

6665
let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
6766
anstream::println!("{}", renderer.render(report));

examples/footer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
"expected struct `annotate_snippets::snippet::Slice`, found reference",
1212
)),
1313
),
14-
Group::with_title(Level::NOTE.primary_title(
14+
Group::with_title(Level::NOTE.secondary_title(
1515
"expected type: `snippet::Annotation`\n found type: `__&__snippet::Annotation`",
1616
)),
1717
];

examples/highlight_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn main() {
5050
),
5151
)
5252
.element(Level::NOTE.message(&message)),
53-
Group::with_title(Level::NOTE.primary_title("function defined here")).element(
53+
Group::with_title(Level::NOTE.secondary_title("function defined here")).element(
5454
Snippet::source(source)
5555
.path("$DIR/highlighting.rs")
5656
.annotation(AnnotationKind::Context.span(200..333).label(""))

tests/color/multiline_removal_suggestion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ fn main() {}
8686
.element(
8787
Level::NOTE.message("required for `(bool, HashSet<u8>)` to implement `IntoIterator`"),
8888
),
89-
Group::with_title(Level::NOTE.primary_title("required by a bound in `flatten`"))
89+
Group::with_title(Level::NOTE.secondary_title("required by a bound in `flatten`"))
9090
.element(
9191
Origin::path("/rustc/FAKE_PREFIX/library/core/src/iter/traits/iterator.rs")
9292
.line(1556)
9393
.char_column(4),
9494
),
95-
Group::with_title(Level::HELP.primary_title("consider removing this method call, as the receiver has type `std::vec::IntoIter<HashSet<u8>>` and `std::vec::IntoIter<HashSet<u8>>: Iterator` trivially holds")).element(
95+
Group::with_title(Level::HELP.secondary_title("consider removing this method call, as the receiver has type `std::vec::IntoIter<HashSet<u8>>` and `std::vec::IntoIter<HashSet<u8>>: Iterator` trivially holds")).element(
9696
Snippet::source(source)
9797
.path("$DIR/multiline-removal-suggestion.rs")
9898

tests/formatter.rs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ fn two_suggestions_same_span() {
10491049
.element(Snippet::source(source).annotation(AnnotationKind::Primary.span(4..5))),
10501050
Group::with_title(
10511051
Level::HELP
1052-
.primary_title("you might have meant to use one of the following enum variants"),
1052+
.secondary_title("you might have meant to use one of the following enum variants"),
10531053
)
10541054
.element(Snippet::source(source).patch(Patch::new(4..5, "(A::Tuple())")))
10551055
.element(Snippet::source(source).patch(Patch::new(4..5, "A::Unit"))),
@@ -1112,7 +1112,7 @@ fn main() {
11121112
.label("method not found in `Chaenomeles`"),
11131113
),
11141114
),
1115-
Group::with_title(Level::HELP.primary_title(
1115+
Group::with_title(Level::HELP.secondary_title(
11161116
"the following traits which provide `pick` are implemented but not in scope; perhaps you want to import one of them",
11171117
))
11181118
.element(
@@ -1160,7 +1160,7 @@ fn single_line_non_overlapping_suggestions() {
11601160
.line_start(1)
11611161
.annotation(AnnotationKind::Primary.span(4..5)),
11621162
),
1163-
Group::with_title(Level::HELP.primary_title("make these changes and things will work"))
1163+
Group::with_title(Level::HELP.secondary_title("make these changes and things will work"))
11641164
.element(
11651165
Snippet::source(source)
11661166
.patch(Patch::new(4..5, "(A::Tuple())"))
@@ -1198,7 +1198,7 @@ fn single_line_non_overlapping_suggestions2() {
11981198
.line_start(1)
11991199
.annotation(AnnotationKind::Primary.span(4..18)),
12001200
),
1201-
Group::with_title(Level::HELP.primary_title("make these changes and things will work"))
1201+
Group::with_title(Level::HELP.secondary_title("make these changes and things will work"))
12021202
.element(
12031203
Snippet::source(source)
12041204
.patch(Patch::new(4..18, "(A::Tuple())"))
@@ -1266,7 +1266,7 @@ fn multiple_replacements() {
12661266
),
12671267
Group::with_title(
12681268
Level::HELP
1269-
.primary_title("try explicitly pass `&Self` into the Closure as an argument"),
1269+
.secondary_title("try explicitly pass `&Self` into the Closure as an argument"),
12701270
)
12711271
.element(
12721272
Snippet::source(source)
@@ -1340,7 +1340,7 @@ fn main() {
13401340
.label("first borrow later used here"),
13411341
),
13421342
),
1343-
Group::with_title(Level::HELP.primary_title(
1343+
Group::with_title(Level::HELP.secondary_title(
13441344
"if you want to call `next` on a iterator within the loop, consider using `while let`",
13451345
))
13461346
.element(
@@ -1409,13 +1409,15 @@ fn main() {}"#;
14091409
),
14101410
),
14111411
Group::with_title(
1412-
Level::HELP.primary_title("there is a crate or module with a similar name"),
1412+
Level::HELP.secondary_title("there is a crate or module with a similar name"),
14131413
)
14141414
.element(Snippet::source(source).patch(Patch::new(122..124, "std"))),
1415-
Group::with_title(Level::HELP.primary_title("consider importing this module"))
1415+
Group::with_title(Level::HELP.secondary_title("consider importing this module"))
14161416
.element(Snippet::source(source).patch(Patch::new(1..1, "use std::cell;\n"))),
1417-
Group::with_title(Level::HELP.primary_title("if you import `cell`, refer to it directly"))
1418-
.element(Snippet::source(source).patch(Patch::new(122..126, ""))),
1417+
Group::with_title(
1418+
Level::HELP.secondary_title("if you import `cell`, refer to it directly"),
1419+
)
1420+
.element(Snippet::source(source).patch(Patch::new(122..126, ""))),
14191421
];
14201422
let expected = str![[r#"
14211423
error[E0433]: failed to resolve: use of undeclared crate or module `st`
@@ -1482,7 +1484,7 @@ fn main() {}"#;
14821484
.label("this type parameter needs to be `Sized`"),
14831485
),
14841486
),
1485-
Group::with_title(Level::HELP.primary_title(
1487+
Group::with_title(Level::HELP.secondary_title(
14861488
"consider removing the `?Sized` bound to make the type parameter `Sized`",
14871489
))
14881490
.element(Snippet::source(source).patch(Patch::new(52..85, ""))),
@@ -1543,7 +1545,7 @@ fn main() {}"#;
15431545
))
15441546
,Group::with_title(
15451547
Level::NOTE
1546-
.primary_title("required by an implicit `Sized` bound in `Wrapper`")
1548+
.secondary_title("required by an implicit `Sized` bound in `Wrapper`")
15471549
).element(
15481550
Snippet::source(source)
15491551
.line_start(1)
@@ -1556,7 +1558,7 @@ fn main() {}"#;
15561558
)
15571559
), Group::with_title(
15581560
Level::HELP
1559-
.primary_title("you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`")
1561+
.secondary_title("you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`")
15601562
)
15611563
.element(
15621564
Snippet::source(source)
@@ -1576,7 +1578,7 @@ fn main() {}"#;
15761578

15771579
),Group::with_title(
15781580
Level::HELP
1579-
.primary_title("consider removing the `?Sized` bound to make the type parameter `Sized`")
1581+
.secondary_title("consider removing the `?Sized` bound to make the type parameter `Sized`")
15801582
).element(
15811583
Snippet::source(source)
15821584

@@ -1640,7 +1642,7 @@ zappy
16401642
.id("E0277"),
16411643
),
16421644
// We need an empty group here to ensure the HELP line is rendered correctly
1643-
Group::with_title(Level::HELP.primary_title(
1645+
Group::with_title(Level::HELP.secondary_title(
16441646
"consider removing the `?Sized` bound to make the type parameter `Sized`",
16451647
))
16461648
.element(
@@ -1713,7 +1715,7 @@ fn main() {
17131715
.span(208..510)
17141716
.label("type mismatch resolving `<Result<Result<(), Result<Result<(), ...>, ...>>, ...> as Future>::Error == Foo`"),
17151717
)),Group::with_title(
1716-
Level::NOTE.primary_title("expected this to be `Foo`")
1718+
Level::NOTE.secondary_title("expected this to be `Foo`")
17171719
).element(
17181720
Snippet::source(source)
17191721
.line_start(4)
@@ -1799,7 +1801,7 @@ fn main() {
17991801
.span(208..510)
18001802
.label("type mismatch resolving `<Result<Result<(), Result<Result<(), ...>, ...>>, ...> as Future>::Error == Foo`"),
18011803
)),Group::with_title(
1802-
Level::NOTE.primary_title("expected this to be `Foo`")
1804+
Level::NOTE.secondary_title("expected this to be `Foo`")
18031805
).element(
18041806
Snippet::source(source)
18051807
.line_start(4)
@@ -2045,7 +2047,7 @@ fn main() {
20452047
.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}`")
20462048
,
20472049
),Group::with_title(
2048-
Level::NOTE.primary_title("function defined here"),
2050+
Level::NOTE.secondary_title("function defined here"),
20492051
).element(
20502052
Snippet::source(source)
20512053
.line_start(7)
@@ -2322,7 +2324,7 @@ fn main() {
23222324
Level::NOTE.message("string concatenation requires an owned `String` on the left"),
23232325
),
23242326
Group::with_title(
2325-
Level::HELP.primary_title("create an owned `String` from a string reference"),
2327+
Level::HELP.secondary_title("create an owned `String` from a string reference"),
23262328
)
23272329
.element(
23282330
Snippet::source(source)
@@ -2390,7 +2392,7 @@ fn foo() {
23902392

23912393
.annotation(AnnotationKind::Primary.span(136..160)),
23922394
),
2393-
Group::with_title(Level::NOTE.primary_title("byte `193` is not valid utf-8"))
2395+
Group::with_title(Level::NOTE.secondary_title("byte `193` is not valid utf-8"))
23942396
.element(
23952397
Snippet::source(bin_source)
23962398
.path("$DIR/not-utf8.bin")
@@ -2581,7 +2583,7 @@ fn main() {
25812583
Group::with_title(
25822584
Level::HELP
25832585
.with_name(Some("suggestion"))
2584-
.primary_title("use `break` on its own without a value inside this `while` loop")
2586+
.secondary_title("use `break` on its own without a value inside this `while` loop")
25852587
.id("S0123"),
25862588
)
25872589
.element(
@@ -2725,15 +2727,16 @@ fn main() {
27252727
.element(Level::NOTE.message(long_title2))
27262728
.element(Level::NOTE.message("`#[warn(array_into_iter)]` on by default")),
27272729
Group::with_title(
2728-
Level::HELP.primary_title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"),
2730+
Level::HELP
2731+
.secondary_title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"),
27292732
)
27302733
.element(
27312734
Snippet::source(suggestion_source)
27322735
.path("lint_example.rs")
27332736
.line_start(3)
27342737
.patch(Patch::new(10..19, "iter")),
27352738
),
2736-
Group::with_title(Level::HELP.primary_title(long_title3)).element(
2739+
Group::with_title(Level::HELP.secondary_title(long_title3)).element(
27372740
Snippet::source(suggestion_source)
27382741
.path("lint_example.rs")
27392742
.line_start(3)
@@ -2794,15 +2797,16 @@ fn main() {
27942797
.element(Level::NOTE.message(long_title2))
27952798
.element(Level::NOTE.message("`#[warn(array_into_iter)]` on by default")),
27962799
Group::with_title(
2797-
Level::HELP.primary_title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"),
2800+
Level::HELP
2801+
.secondary_title("use `.iter()` instead of `.into_iter()` to avoid ambiguity"),
27982802
)
27992803
.element(
28002804
Snippet::source(suggestion_source)
28012805
.path("lint_example.rs")
28022806
.line_start(3)
28032807
.patch(Patch::new(10..19, "iter")),
28042808
),
2805-
Group::with_title(Level::HELP.primary_title(long_title3)).element(
2809+
Group::with_title(Level::HELP.secondary_title(long_title3)).element(
28062810
Snippet::source(suggestion_source)
28072811
.path("lint_example.rs")
28082812
.line_start(3)
@@ -2979,7 +2983,7 @@ fn main() {}
29792983
)),
29802984
)
29812985
.element(Padding),
2982-
Group::with_title(Level::HELP.primary_title("consider specifying the generic argument"))
2986+
Group::with_title(Level::HELP.secondary_title("consider specifying the generic argument"))
29832987
.element(
29842988
Snippet::source(source)
29852989
.path("$DIR/issue-42234-unknown-receiver-type.rs")
@@ -3055,7 +3059,7 @@ fn main() {}
30553059
"cannot infer type of the type parameter `S` declared on the method `sum`",
30563060
)),
30573061
),
3058-
Group::with_title(Level::HELP.primary_title("consider specifying the generic argument"))
3062+
Group::with_title(Level::HELP.secondary_title("consider specifying the generic argument"))
30593063
.element(
30603064
Snippet::source(source)
30613065
.path("$DIR/issue-42234-unknown-receiver-type.rs")

0 commit comments

Comments
 (0)