Skip to content

Commit

Permalink
Rollup merge of rust-lang#134181 - estebank:trim-render, r=oli-obk
Browse files Browse the repository at this point in the history
Tweak multispan rendering to reduce output length

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. We do that check not only on the first 4 lines of the multispan, but now also on the previous to last line as well.
  • Loading branch information
matthiaskrgr authored Dec 14, 2024
2 parents 4a204be + 9f1044e commit d2c3dd3
Show file tree
Hide file tree
Showing 181 changed files with 216 additions and 859 deletions.
15 changes: 12 additions & 3 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3048,19 +3048,28 @@ 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 filter = |s: &str| {
let s = s.trim();
// Consider comments as empty, but don't consider docstrings to be empty.
!(s.starts_with("//") && !(s.starts_with("///") || s.starts_with("//!")))
// Consider lines with nothing but whitespace, a single delimiter as empty.
&& !["", "{", "}", "(", ")", "[", "]"].contains(&s)
};
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)| filter(s))
.map(|(line, _)| line)
.unwrap_or(ann.line_start);
for line in ann.line_start + 1..until {
// Every `|` that joins the beginning of the span (`___^`) to the end (`|__^`).
add_annotation_to_file(&mut output, Lrc::clone(&file), line, ann.as_line());
}
let line_end = ann.line_end - 1;
if middle < line_end {
let end_is_empty = file.get_line(line_end - 1).map_or(false, |s| !filter(&s));
if middle < line_end && !end_is_empty {
add_annotation_to_file(&mut output, Lrc::clone(&file), line_end, ann.as_line());
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ LL | | fn clone_self(&self) -> Self {
LL | | Self {
LL | | a: true,
... |
LL | | }
LL | | }
| |_^
|
Expand All @@ -32,7 +31,6 @@ LL | | fn default() -> Self {
LL | | Self {
LL | | a: true,
... |
LL | | }
LL | | }
| |_^

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
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ LL | | if unsafe { true } {
LL | | todo!();
LL | | } else {
... |
LL | | }
LL | | };
| |______^
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ LL | | if unsafe { true } {
LL | | todo!();
LL | | } else {
... |
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 @@ -44,7 +44,6 @@ LL | | if {
LL | | if s == "43" {
LL | | return Some(43);
... |
LL | | }
LL | | });
| |______^
|
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
10 changes: 0 additions & 10 deletions src/tools/clippy/tests/ui/collapsible_else_if.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ LL | } else {
| ____________^
LL | | if y == "world" {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
Expand All @@ -66,9 +64,7 @@ LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
Expand All @@ -89,9 +85,7 @@ LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
Expand All @@ -112,9 +106,7 @@ LL | } else {
| ____________^
LL | | if x == "hello" {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
Expand All @@ -135,9 +127,7 @@ LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/copy_iterator.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ LL | |
LL | |
LL | | type Item = u8;
... |
LL | | }
LL | | }
| |_^
|
Expand Down
8 changes: 0 additions & 8 deletions src/tools/clippy/tests/ui/crashes/ice-360.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ error: this loop never actually loops
--> tests/ui/crashes/ice-360.rs:5:5
|
LL | / loop {
LL | |
LL | |
LL | |
... |
LL | |
LL | | }
| |_____^
|
Expand All @@ -16,11 +12,7 @@ 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 | | }
| |_____^ help: try: `while let Some(ele) = iter.next() { .. }`
|
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
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/derivable_impls.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ LL | | fn default() -> Self {
LL | | Self {
LL | | a: false,
... |
LL | | }
LL | | }
| |_^
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ 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
5 changes: 1 addition & 4 deletions src/tools/clippy/tests/ui/entry.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ LL | / if !m.contains_key(&k) {
LL | | if true {
LL | | m.insert(k, v);
LL | | } else {
LL | | m.insert(k, v2);
LL | | }
... |
LL | | }
| |_____^
|
Expand Down Expand Up @@ -63,7 +62,6 @@ LL | | if true {
LL | | m.insert(k, v);
LL | | } else {
... |
LL | | }
LL | | }
| |_____^
|
Expand Down Expand Up @@ -154,7 +152,6 @@ LL | | foo();
LL | | match 0 {
LL | | 0 if false => {
... |
LL | | }
LL | | }
| |_____^
|
Expand Down
3 changes: 0 additions & 3 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,9 +44,7 @@ error: all variants have the same prefix: `Food`
LL | / enum Food {
LL | |
LL | | FoodGood,
LL | |
... |
LL | |
LL | | }
| |_^
|
Expand Down
3 changes: 0 additions & 3 deletions src/tools/clippy/tests/ui/fallible_impl_from.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ LL | |
LL | | fn from(i: usize) -> Invalid {
LL | | if i != 42 {
... |
LL | | }
LL | | }
| |_^
|
Expand All @@ -49,7 +48,6 @@ LL | |
LL | | fn from(s: Option<String>) -> Invalid {
LL | | let s = s.unwrap();
... |
LL | | }
LL | | }
| |_^
|
Expand All @@ -76,7 +74,6 @@ LL | |
LL | | fn from(s: &'a mut <Box<u32> as ProjStrTrait>::ProjString) -> Invalid {
LL | | if s.parse::<u32>().ok().unwrap() != 42 {
... |
LL | | }
LL | | }
| |_^
|
Expand Down
2 changes: 0 additions & 2 deletions src/tools/clippy/tests/ui/if_same_then_else2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ LL | | for _ in &[42] {
LL | | let foo: &Option<_> = &Some::<u8>(42);
LL | | if foo.is_some() {
... |
LL | | }
LL | | } else {
| |_____^
|
Expand All @@ -20,7 +19,6 @@ LL | | for _ in &[42] {
LL | | let bar: &Option<_> = &Some::<u8>(42);
LL | | if bar.is_some() {
... |
LL | | }
LL | | }
| |_____^
= note: `-D clippy::if-same-then-else` implied by `-D warnings`
Expand Down
13 changes: 2 additions & 11 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,9 +36,7 @@ error: infinite loop detected
LL | / loop {
LL | |
LL | | loop {
LL | |
LL | | do_something();
LL | | }
... |
LL | | }
| |_________^
|
Expand Down Expand Up @@ -79,8 +76,7 @@ error: infinite loop detected
LL | / loop {
LL | | fn inner_fn() -> ! {
LL | | std::process::exit(0);
LL | | }
LL | | do_something();
... |
LL | | }
| |_____^
|
Expand All @@ -97,7 +93,6 @@ LL | |
LL | | loop {
LL | | if cond {
... |
LL | | }
LL | | }
| |_____^
|
Expand All @@ -114,7 +109,6 @@ LL | |
LL | | 'inner: loop {
LL | | loop {
... |
LL | | }
LL | | }
| |_____^
|
Expand Down Expand Up @@ -145,7 +139,6 @@ LL | |
LL | | 'inner: loop {
LL | | loop {
... |
LL | | }
LL | | }
| |_________^
|
Expand All @@ -162,7 +155,6 @@ LL | |
LL | | match opt {
LL | | Some(v) => {
... |
LL | | }
LL | | }
| |_____^
|
Expand Down Expand Up @@ -279,7 +271,6 @@ LL | |
LL | | 'inner: loop {
LL | | loop {
... |
LL | | }
LL | | }
| |_____^
|
Expand Down
Loading

0 comments on commit d2c3dd3

Please sign in to comment.