Skip to content

Commit 294c358

Browse files
authored
Rollup merge of rust-lang#147165 - Muscraft:subtract-code-offset, r=davidtwco
test: Subtract code_offset from width for ui_testing `annotate-snippets` does not have a "UI test" mode like `rustc`, [where the code offset is not subtracted from the column width](https://github.com/rust-lang/rust/blob/f34ba774c78ea32b7c40598b8ad23e75cdac42a6/compiler/rustc_errors/src/emitter.rs#L1985-L1987). This makes it so `annotate-snippets` will shift the output for some very long tests 5 - 7 columns to the left. As part of my work to have `rustc` use `annotate-snippets`, and to reduce the test differences between the two, I figured it would be best if `rustc` started subtracting the code offset from the width as well. The first commit exists to keep the test output changes of adding a new line to a test separate from adding the `--diagnostic-width` flag in the second commit. This makes it easier to verify that adding the flag does not affect the test's output. [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/147480-t-compiler.2Fdiagnostics/topic/annotate-snippets.20hurdles)
2 parents bccc02c + 9c6897b commit 294c358

33 files changed

+98
-94
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ impl HumanEmitter {
20212021
if let Some(width) = self.diagnostic_width {
20222022
width.saturating_sub(code_offset)
20232023
} else if self.ui_testing || cfg!(miri) {
2024-
DEFAULT_COLUMN_WIDTH
2024+
DEFAULT_COLUMN_WIDTH.saturating_sub(code_offset)
20252025
} else {
20262026
termize::dimensions()
20272027
.map(|(w, _)| w.saturating_sub(code_offset))

src/tools/clippy/tests/ui/option_env_unwrap.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set
1919
error: this will panic at run-time if the environment variable doesn't exist at compile-time
2020
--> tests/ui/option_env_unwrap.rs:14:13
2121
|
22-
LL | let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your env...
22+
LL | let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in you...
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424
|
2525
= help: consider using the `env!` macro instead

src/tools/clippy/tests/ui/too_long_first_doc_paragraph.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ LL | | /// gravida non lacinia at, rhoncus eu lacus.
4242
error: first doc comment paragraph is too long
4343
--> tests/ui/too_long_first_doc_paragraph.rs:65:1
4444
|
45-
LL | / /// Some function. This doc-string paragraph is too long. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lore...
45+
LL | / /// Some function. This doc-string paragraph is too long. Lorem Ipsum is simply dummy text of the printing and typesetting industr...
4646
LL | |
4747
LL | | ///
4848
LL | | /// Here's a second paragraph. It would be preferable to put the details here.

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_join_joined.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: trying to join an already joined thread
22
--> tests/fail-dep/concurrency/libc_pthread_join_joined.rs:LL:CC
33
|
4-
LL | assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
4+
LL | ... assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_join_main.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: trying to join a detached thread
22
--> tests/fail-dep/concurrency/libc_pthread_join_main.rs:LL:CC
33
|
4-
LL | assert_eq!(libc::pthread_join(thread_id, ptr::null_mut()), 0);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
4+
LL | ... assert_eq!(libc::pthread_join(thread_id, ptr::null_mut()), 0);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `unnamed-ID` and (2) deallocation on thread `unnamed-ID` at ALLOC
22
--> tests/fail/data_race/dealloc_read_race1.rs:LL:CC
33
|
4-
LL | / __rust_dealloc(
5-
LL | |
6-
LL | | ptr.0 as *mut _,
7-
LL | | std::mem::size_of::<usize>(),
8-
LL | | std::mem::align_of::<usize>(),
9-
LL | | );
10-
| |_____________^ (2) just happened here
4+
LL | / ... __rust_dealloc(
5+
LL | | ...
6+
LL | | ... ptr.0 as *mut _,
7+
LL | | ... std::mem::size_of::<usize>(),
8+
LL | | ... std::mem::align_of::<usize>(),
9+
LL | | ... );
10+
| |_______^ (2) just happened here
1111
|
1212
help: and (1) occurred earlier here
1313
--> tests/fail/data_race/dealloc_read_race1.rs:LL:CC

src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `unnamed-ID` and (2) deallocation on thread `unnamed-ID` at ALLOC
22
--> tests/fail/data_race/dealloc_read_race_stack.rs:LL:CC
33
|
4-
LL | }
5-
| ^ (2) just happened here
4+
LL | ... }
5+
| ^ (2) just happened here
66
|
77
help: and (1) occurred earlier here
88
--> tests/fail/data_race/dealloc_read_race_stack.rs:LL:CC

src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `unnamed-ID` and (2) deallocation on thread `unnamed-ID` at ALLOC
22
--> tests/fail/data_race/dealloc_write_race1.rs:LL:CC
33
|
4-
LL | / __rust_dealloc(
5-
LL | |
6-
LL | | ptr.0 as *mut _,
7-
LL | | std::mem::size_of::<usize>(),
8-
LL | | std::mem::align_of::<usize>(),
9-
LL | | );
10-
| |_____________^ (2) just happened here
4+
LL | / ... __rust_dealloc(
5+
LL | | ...
6+
LL | | ... ptr.0 as *mut _,
7+
LL | | ... std::mem::size_of::<usize>(),
8+
LL | | ... std::mem::align_of::<usize>(),
9+
LL | | ... );
10+
| |_______^ (2) just happened here
1111
|
1212
help: and (1) occurred earlier here
1313
--> tests/fail/data_race/dealloc_write_race1.rs:LL:CC

src/tools/miri/tests/fail/data_race/dealloc_write_race_stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `unnamed-ID` and (2) deallocation on thread `unnamed-ID` at ALLOC
22
--> tests/fail/data_race/dealloc_write_race_stack.rs:LL:CC
33
|
4-
LL | }
5-
| ^ (2) just happened here
4+
LL | ... }
5+
| ^ (2) just happened here
66
|
77
help: and (1) occurred earlier here
88
--> tests/fail/data_race/dealloc_write_race_stack.rs:LL:CC

src/tools/miri/tests/fail/intrinsics/copy_unaligned.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
22
--> tests/fail/intrinsics/copy_unaligned.rs:LL:CC
33
|
4-
LL | std::intrinsics::copy_nonoverlapping(&data[5], ptr, 0);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
4+
LL | ... std::intrinsics::copy_nonoverlapping(&data[5], ptr, 0);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

0 commit comments

Comments
 (0)