Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2919,26 +2919,34 @@ fn max_line_number(groups: &[Group<'_>]) -> usize {
| Element::Origin(_)
| Element::Padding(_) => 0,
Element::Cause(cause) => {
let end = cause
.markers
.iter()
.map(|a| a.span.end)
.max()
.unwrap_or(cause.source.len())
.min(cause.source.len());

cause.line_start + newline_count(&cause.source[..end])
if cause.fold {
let end = cause
.markers
.iter()
.map(|a| a.span.end)
.max()
.unwrap_or(cause.source.len())
.min(cause.source.len());

cause.line_start + newline_count(&cause.source[..end])
} else {
cause.line_start + newline_count(&cause.source)
}
}
Element::Suggestion(suggestion) => {
let end = suggestion
.markers
.iter()
.map(|a| a.span.end)
.max()
.unwrap_or(suggestion.source.len())
.min(suggestion.source.len());

suggestion.line_start + newline_count(&suggestion.source[..end])
if suggestion.fold {
let end = suggestion
.markers
.iter()
.map(|a| a.span.end)
.max()
.unwrap_or(suggestion.source.len())
.min(suggestion.source.len());

suggestion.line_start + newline_count(&suggestion.source[..end])
} else {
suggestion.line_start + newline_count(&suggestion.source)
}
}
})
.max()
Expand Down
38 changes: 38 additions & 0 deletions tests/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,3 +2574,41 @@ LL + break;
let renderer_unicode = renderer_ascii.theme(OutputTheme::Unicode);
assert_data_eq!(renderer_unicode.render(input), expected_unicode);
}

#[test]
fn max_line_num_no_fold() {
let source = r#"cargo
fuzzy
pizza
jumps
crazy
quack
zappy
"#;

let input_new = &[Group::with_title(
Level::ERROR
.title("the size for values of type `T` cannot be known at compilation time")
.id("E0277"),
)
.element(
Snippet::source(source)
.line_start(8)
.fold(false)
.annotation(AnnotationKind::Primary.span(6..11)),
)];
let expected = str![[r#"
error[E0277]: the size for values of type `T` cannot be known at compilation time
|
8 | cargo
9 | fuzzy
| ^^^^^
10 | pizza
11 | jumps
12 | crazy
13 | quack
14 | zappy
"#]];
let renderer = Renderer::plain();
assert_data_eq!(renderer.render(input_new), expected);
}