Skip to content

Commit

Permalink
Tweak multispan rendering
Browse files Browse the repository at this point in the history
Consider comments and bare delimiters the same as an "empty line" for purposes of hiding rendered code output of long multispans. This results in more aggressive shortening of rendered output without losing too much context, specially in `*.stderr` tests that have "hidden" comments.
  • Loading branch information
estebank committed Dec 11, 2024
1 parent 33c245b commit 84ae532
Show file tree
Hide file tree
Showing 111 changed files with 206 additions and 653 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3048,11 +3048,15 @@ impl FileWithAnnotatedLines {
// working correctly.
let middle = min(ann.line_start + 4, ann.line_end);
// We'll show up to 4 lines past the beginning of the multispan start.
// We will *not* include the tail of lines that are only whitespace.
// We will *not* include the tail of lines that are only whitespace, a comment or
// a bare delimiter.
let until = (ann.line_start..middle)
.rev()
.filter_map(|line| file.get_line(line - 1).map(|s| (line + 1, s)))
.find(|(_, s)| !s.trim().is_empty())
.find(|(_, s)| {
let s = s.trim();
!["", "{", "}", "(", ")", "[", "]"].contains(&s) && !s.starts_with("//")
})
.map(|(line, _)| line)
.unwrap_or(ann.line_start);
for line in ann.line_start + 1..until {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ error: this block is too nested
LL | if true {
| _________________________^
LL | | if true {
LL | |
LL | | }
... |
LL | | }
| |_________________^
|
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/async_yields_async.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ error: an async construct yields a type which is itself awaitable
LL | let _m = async || {
| _______________________-
LL | | println!("I'm bored");
LL | | // Some more stuff
... |
LL | | CustomFutureType
| | ^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ error: all if blocks contain the same code at the end
--> tests/ui/branches_sharing_code/shared_at_bottom.rs:183:5
|
LL | / x << 2
LL | |
LL | |
... |
LL | | };
| |_____^
|
Expand All @@ -131,8 +130,7 @@ error: all if blocks contain the same code at the end
--> tests/ui/branches_sharing_code/shared_at_bottom.rs:192:5
|
LL | / x * 4
LL | |
LL | |
... |
LL | | }
| |_____^
|
Expand Down
5 changes: 0 additions & 5 deletions src/tools/clippy/tests/ui/collapsible_else_if.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ LL | } else {
| ____________^
LL | | if y == "world" {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
Expand All @@ -66,7 +65,6 @@ LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
Expand All @@ -89,7 +87,6 @@ LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
Expand All @@ -112,7 +109,6 @@ LL | } else {
| ____________^
LL | | if x == "hello" {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
Expand All @@ -135,7 +131,6 @@ LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
Expand Down
6 changes: 0 additions & 6 deletions src/tools/clippy/tests/ui/crashes/ice-360.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ error: this loop never actually loops
--> tests/ui/crashes/ice-360.rs:5:5
|
LL | / loop {
LL | |
LL | |
LL | |
... |
LL | |
LL | | }
Expand All @@ -16,9 +13,6 @@ error: this loop could be written as a `while let` loop
--> tests/ui/crashes/ice-360.rs:5:5
|
LL | / loop {
LL | |
LL | |
LL | |
... |
LL | |
LL | | }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ error: this looks like you are trying to swap `a` and `b`
--> tests/ui/crate_level_checks/no_std_swap.rs:12:5
|
LL | / a = b;
LL | |
LL | |
... |
LL | | b = a;
| |_________^ help: try: `core::mem::swap(&mut a, &mut b)`
|
Expand Down
4 changes: 1 addition & 3 deletions src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ error: backticks are unbalanced
|
LL | /// This is a doc comment with `unbalanced_tick marks and several words that
| _____^
LL | |
LL | | /// should be `encompassed_by` tick marks because they `contain_underscores`.
LL | | /// Because of the initial `unbalanced_tick` pair, the error message is
... |
LL | | /// very `confusing_and_misleading`.
| |____________________________________^
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ error: empty lines after doc comment
--> tests/ui/empty_line_after/doc_comments.rs:63:5
|
LL | / /// for OldA
LL | | // struct OldA;
LL | |
LL | | /// Docs
LL | | /// for OldB
... |
LL | | // struct OldB;
LL | |
| |_^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ error: empty lines after outer attribute
--> tests/ui/empty_line_after/outer_attribute.rs:64:1
|
LL | / #[allow(unused)]
LL | |
LL | | // This comment is isolated
... |
LL | |
| |_^
LL | pub fn isolated_comment() {}
Expand Down
2 changes: 0 additions & 2 deletions src/tools/clippy/tests/ui/enum_variants.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ error: all variants have the same prefix: `c`
LL | / enum Foo {
LL | |
LL | | cFoo,
LL | |
... |
LL | | cBaz,
LL | | }
Expand Down Expand Up @@ -45,7 +44,6 @@ error: all variants have the same prefix: `Food`
LL | / enum Food {
LL | |
LL | | FoodGood,
LL | |
... |
LL | |
LL | | }
Expand Down
7 changes: 2 additions & 5 deletions src/tools/clippy/tests/ui/infinite_loops.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ error: infinite loop detected
LL | / loop {
LL | |
LL | | loop {
LL | |
... |
LL | | do_something();
LL | | }
Expand All @@ -37,8 +36,7 @@ error: infinite loop detected
LL | / loop {
LL | |
LL | | loop {
LL | |
LL | | do_something();
... |
LL | | }
LL | | }
| |_________^
Expand Down Expand Up @@ -79,8 +77,7 @@ error: infinite loop detected
LL | / loop {
LL | | fn inner_fn() -> ! {
LL | | std::process::exit(0);
LL | | }
LL | | do_something();
... |
LL | | }
| |_____^
|
Expand Down
36 changes: 12 additions & 24 deletions src/tools/clippy/tests/ui/manual_find_fixable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ error: manual implementation of `Iterator::find`
LL | / for &v in ARRAY {
LL | | if v == n {
LL | | return Some(v);
LL | | }
LL | | }
... |
LL | | None
| |________^ help: replace with an iterator: `ARRAY.iter().find(|&&v| v == n).copied()`
|
Expand All @@ -18,8 +17,7 @@ error: manual implementation of `Iterator::find`
LL | / for (a, _) in arr {
LL | | if a % 2 == 0 {
LL | | return Some(a);
LL | | }
LL | | }
... |
LL | | None
| |________^ help: replace with an iterator: `arr.into_iter().map(|(a, _)| a).find(|&a| a % 2 == 0)`

Expand All @@ -29,8 +27,7 @@ error: manual implementation of `Iterator::find`
LL | / for el in arr {
LL | | if el.name.len() == 10 {
LL | | return Some(el);
LL | | }
LL | | }
... |
LL | | None
| |________^ help: replace with an iterator: `arr.into_iter().find(|el| el.name.len() == 10)`
|
Expand All @@ -42,8 +39,7 @@ error: manual implementation of `Iterator::find`
LL | / for Tuple(a, _) in arr {
LL | | if a >= 3 {
LL | | return Some(a);
LL | | }
LL | | }
... |
LL | | None
| |________^ help: replace with an iterator: `arr.into_iter().map(|Tuple(a, _)| a).find(|&a| a >= 3)`

Expand All @@ -53,8 +49,7 @@ error: manual implementation of `Iterator::find`
LL | / for el in arr {
LL | | if el.should_keep() {
LL | | return Some(el);
LL | | }
LL | | }
... |
LL | | None
| |________^ help: replace with an iterator: `arr.into_iter().find(|el| el.should_keep())`
|
Expand All @@ -66,8 +61,7 @@ error: manual implementation of `Iterator::find`
LL | / for el in arr {
LL | | if f(el) == 20 {
LL | | return Some(el);
LL | | }
LL | | }
... |
LL | | None
| |________^ help: replace with an iterator: `arr.into_iter().find(|&el| f(el) == 20)`

Expand All @@ -77,8 +71,7 @@ error: manual implementation of `Iterator::find`
LL | / for &el in arr.values() {
LL | | if f(el) {
LL | | return Some(el);
LL | | }
LL | | }
... |
LL | | None
| |________^ help: replace with an iterator: `arr.values().find(|&&el| f(el)).copied()`

Expand All @@ -88,8 +81,7 @@ error: manual implementation of `Iterator::find`
LL | / for el in arr {
LL | | if el.is_true {
LL | | return Some(el);
LL | | }
LL | | }
... |
LL | | None
| |________^ help: replace with an iterator: `arr.into_iter().find(|el| el.is_true)`
|
Expand All @@ -101,8 +93,7 @@ error: manual implementation of `Iterator::find`
LL | / for (_, &x) in v {
LL | | if x > 10 {
LL | | return Some(x);
LL | | }
LL | | }
... |
LL | | None
| |________^ help: replace with an iterator: `v.into_iter().map(|(_, &x)| x).find(|&x| x > 10)`

Expand All @@ -112,8 +103,7 @@ error: manual implementation of `Iterator::find`
LL | / for &(_, &x) in v {
LL | | if x > 10 {
LL | | return Some(x);
LL | | }
LL | | }
... |
LL | | None
| |________^ help: replace with an iterator: `v.iter().map(|&(_, &x)| x).find(|&x| x > 10)`

Expand All @@ -123,8 +113,7 @@ error: manual implementation of `Iterator::find`
LL | / for x in arr {
LL | | if x >= 5 {
LL | | return Some(x);
LL | | }
LL | | }
... |
LL | | return None;
| |________________^ help: replace with an iterator: `arr.into_iter().find(|&x| x >= 5)`

Expand All @@ -134,8 +123,7 @@ error: manual implementation of `Iterator::find`
LL | / for x in arr {
LL | | if x < 1 {
LL | | return Some(x);
LL | | }
LL | | }
... |
LL | | None
| |____________^ help: replace with an iterator: `arr.into_iter().find(|&x| x < 1)`

Expand Down
3 changes: 0 additions & 3 deletions src/tools/clippy/tests/ui/map_flatten_fixable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ error: called `map(..).flatten()` on `Option`
|
LL | .map(|_| {
| __________^
LL | | // we need some newlines
LL | | // so that the span is big enough
LL | | // for a split output of the diagnostic
... |
LL | | })
LL | | .flatten();
Expand Down
3 changes: 0 additions & 3 deletions src/tools/clippy/tests/ui/match_bool.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ error: you seem to be trying to match on a boolean expression
--> tests/ui/match_bool.rs:36:5
|
LL | / match test && test {
LL | |
LL | |
LL | |
... |
LL | | _ => (),
LL | | };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ LL | let _ans = match x {
| ____________________^
LL | | E::A(_) => {
LL | | true
LL | | }
LL | | E::B(_) => true,
... |
LL | | _ => false,
LL | | };
| |_________^ help: try: `matches!(x, E::A(_) | E::B(_))`
Expand Down
4 changes: 1 addition & 3 deletions src/tools/clippy/tests/ui/missing_doc_crate_missing.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ error: missing documentation for the crate
--> tests/ui/missing_doc_crate_missing.rs:1:1
|
LL | / #![warn(clippy::missing_docs_in_private_items)]
LL | |
LL | |
LL | |
... |
LL | | fn main() {}
| |____________^
|
Expand Down
Loading

0 comments on commit 84ae532

Please sign in to comment.