Skip to content

Commit 96a2d7c

Browse files
committed
fix: Add pipe to first snippet when not alone
1 parent 9371771 commit 96a2d7c

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

examples/multislice.svg

Lines changed: 7 additions & 5 deletions
Loading

src/renderer/display_list.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,11 +1006,13 @@ fn format_message(
10061006
format_footer(level, id, title)
10071007
};
10081008

1009+
let num_snippets = snippets.len();
10091010
for (idx, snippet) in snippets.into_iter().enumerate() {
10101011
let snippet = fold_prefix_suffix(snippet);
10111012
sets.push(format_snippet(
10121013
snippet,
10131014
idx == 0,
1015+
idx == 0 && num_snippets > 1,
10141016
term_width,
10151017
anonymized_line_numbers,
10161018
));
@@ -1089,6 +1091,7 @@ fn format_label(
10891091
fn format_snippet(
10901092
snippet: snippet::Snippet<'_>,
10911093
is_first: bool,
1094+
needs_trailing_pipe: bool,
10921095
term_width: usize,
10931096
anonymized_line_numbers: bool,
10941097
) -> DisplaySet<'_> {
@@ -1098,6 +1101,7 @@ fn format_snippet(
10981101
let mut body = format_body(
10991102
snippet,
11001103
need_empty_header,
1104+
needs_trailing_pipe,
11011105
term_width,
11021106
anonymized_line_numbers,
11031107
);
@@ -1285,6 +1289,7 @@ fn fold_body(body: Vec<DisplayLine<'_>>) -> Vec<DisplayLine<'_>> {
12851289
fn format_body(
12861290
snippet: snippet::Snippet<'_>,
12871291
need_empty_header: bool,
1292+
needs_trailing_pipe: bool,
12881293
term_width: usize,
12891294
anonymized_line_numbers: bool,
12901295
) -> DisplaySet<'_> {
@@ -1599,6 +1604,15 @@ fn format_body(
15991604
);
16001605
}
16011606

1607+
if needs_trailing_pipe {
1608+
body.push(DisplayLine::Source {
1609+
lineno: None,
1610+
inline_marks: vec![],
1611+
line: DisplaySourceLine::Empty,
1612+
annotations: vec![],
1613+
});
1614+
}
1615+
16021616
let max_line_num_len = if anonymized_line_numbers {
16031617
ANONYMIZED_LINE_NUM.len()
16041618
} else {

tests/fixtures/color/issue_9.svg

Lines changed: 7 additions & 5 deletions
Loading

tests/formatter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ error
146146
--> file1.rs
147147
|
148148
5402 | This is slice 1
149+
|
149150
::: file2.rs
150151
|
151152
2 | This is slice 2

tests/rustc_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,7 @@ LL | | ($bang_macro:ident, $attr_macro:ident) => {
13231323
LL | | }
13241324
LL | | }
13251325
| |_________^
1326+
|
13261327
::: $DIR/nested-macro-rules.rs:23:5
13271328
|
13281329
LL | nested_macro_rules::outer_macro!(SecondStruct, SecondAttrStruct);
@@ -1697,6 +1698,7 @@ note: for a trait to be dyn compatible it needs to allow building a vtable
16971698
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
16981699
--> $SRC_DIR/core/src/cmp.rs
16991700
|
1701+
|
17001702
::: $DIR/object-fail.rs:3:7
17011703
|
17021704
LL | trait EqAlias = Eq;

0 commit comments

Comments
 (0)