Skip to content

Commit 5aa062e

Browse files
authored
Rollup merge of rust-lang#107659 - bvanjoi:issue-107649, r=estebank
test: snapshot for derive suggestion in diff files fixed rust-lang#107649
2 parents 188dd72 + 7615045 commit 5aa062e

File tree

3 files changed

+135
-11
lines changed

3 files changed

+135
-11
lines changed

compiler/rustc_errors/src/emitter.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1796,17 +1796,17 @@ impl EmitterWriter {
17961796
// telling users to make a change but not clarifying *where*.
17971797
let loc = sm.lookup_char_pos(parts[0].span.lo());
17981798
if loc.file.name != sm.span_to_filename(span) && loc.file.name.is_real() {
1799-
buffer.puts(row_num - 1, 0, "--> ", Style::LineNumber);
1800-
buffer.append(
1801-
row_num - 1,
1802-
&format!(
1803-
"{}:{}:{}",
1804-
sm.filename_for_diagnostics(&loc.file.name),
1805-
sm.doctest_offset_line(&loc.file.name, loc.line),
1806-
loc.col.0 + 1,
1807-
),
1808-
Style::LineAndColumn,
1809-
);
1799+
let arrow = "--> ";
1800+
buffer.puts(row_num - 1, 0, arrow, Style::LineNumber);
1801+
let filename = sm.filename_for_diagnostics(&loc.file.name);
1802+
let offset = sm.doctest_offset_line(&loc.file.name, loc.line);
1803+
let message = format!("{}:{}:{}", filename, offset, loc.col.0 + 1);
1804+
if row_num == 2 {
1805+
let col = usize::max(max_line_num_len + 1, arrow.len());
1806+
buffer.puts(1, col, &message, Style::LineAndColumn);
1807+
} else {
1808+
buffer.append(row_num - 1, &message, Style::LineAndColumn);
1809+
}
18101810
for _ in 0..max_line_num_len {
18111811
buffer.prepend(row_num - 1, " ", Style::NoStyle);
18121812
}

tests/ui/modules/issue-107649.rs

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// compile-flags: -Z ui-testing=no
2+
#[path = "auxiliary/dummy_lib.rs"]
3+
mod lib;
4+
5+
/// The function needs to be long enough to
6+
/// ensure `max_line_num_len` to be large enough
7+
/// for no-ui-testing
8+
fn main() {
9+
();
10+
();
11+
();
12+
();
13+
();
14+
();
15+
();
16+
();
17+
();
18+
();
19+
();
20+
();
21+
();
22+
();
23+
();
24+
();
25+
();
26+
();
27+
();
28+
();
29+
();
30+
();
31+
();
32+
();
33+
();
34+
();
35+
();
36+
();
37+
();
38+
();
39+
();
40+
();
41+
();
42+
();
43+
();
44+
();
45+
();
46+
();
47+
();
48+
();
49+
();
50+
();
51+
();
52+
();
53+
();
54+
();
55+
();
56+
();
57+
();
58+
();
59+
();
60+
();
61+
();
62+
();
63+
();
64+
();
65+
();
66+
();
67+
();
68+
();
69+
();
70+
();
71+
();
72+
();
73+
();
74+
();
75+
();
76+
();
77+
();
78+
();
79+
();
80+
();
81+
();
82+
();
83+
();
84+
();
85+
();
86+
();
87+
();
88+
();
89+
();
90+
();
91+
();
92+
();
93+
();
94+
();
95+
();
96+
();
97+
();
98+
();
99+
();
100+
();
101+
();
102+
();
103+
();
104+
();
105+
dbg!(lib::Dummy); //~ Error: `Dummy` doesn't implement `Debug`
106+
}

tests/ui/modules/issue-107649.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0277]: `Dummy` doesn't implement `Debug`
2+
--> $DIR/issue-107649.rs:105:5
3+
|
4+
105 | dbg!(lib::Dummy);
5+
| ^^^^^^^^^^^^^^^^ `Dummy` cannot be formatted using `{:?}`
6+
|
7+
= help: the trait `Debug` is not implemented for `Dummy`
8+
= note: add `#[derive(Debug)]` to `Dummy` or manually `impl Debug for Dummy`
9+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
10+
help: consider annotating `Dummy` with `#[derive(Debug)]`
11+
--> $DIR/auxiliary/dummy_lib.rs:2:1
12+
|
13+
2 | #[derive(Debug)]
14+
|
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)