Skip to content

Commit 2f7e07b

Browse files
authored
Rollup merge of #148001 - Muscraft:fix-diff-symbol-unchanged-lines, r=fmease
fix: Don't add diff symbol to unchanged lines When rendering a "multi-line" suggestion with the [`Diff`](https://github.com/rust-lang/rust/blob/dc1feabef242259d61bd930713de3250577c1c71/compiler/rustc_errors/src/emitter.rs#L3078) format, `rustc` uses a [diff symbol](https://github.com/rust-lang/rust/blob/dc1feabef242259d61bd930713de3250577c1c71/compiler/rustc_errors/src/emitter.rs#L3017-L3022) for [any line that has a highlight part](https://github.com/rust-lang/rust/blob/dc1feabef242259d61bd930713de3250577c1c71/compiler/rustc_errors/src/emitter.rs#L2705-L2713). This includes highlight parts that are highlighting nothing, i.e., a span of `0..0`. This leads `rustc` to add a diff symbol unnecessarily to lines that have no changes and are not highlighted. This PR makes it so that `rustc` will not add a diff symbol to lines that contain no changes/highlights. Note: This PR is part of my ongoing effort to have `rustc` use `annotate-snippets` for rendering. This change will make it so that `rustc` and `annotate-snippets` will match in this case.
2 parents b397b6b + c7f014d commit 2f7e07b

File tree

8 files changed

+53
-54
lines changed

8 files changed

+53
-54
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,8 +2698,7 @@ impl HumanEmitter {
26982698
[SubstitutionHighlight { start: 0, end }] if *end == line_to_add.len() => {
26992699
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
27002700
}
2701-
[] => {
2702-
// FIXME: needed? Doesn't get exercised in any test.
2701+
[] | [SubstitutionHighlight { start: 0, end: 0 }] => {
27032702
self.draw_col_separator_no_space(buffer, *row_num, max_line_num_len + 1);
27042703
}
27052704
_ => {

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | | }
1414
help: replace the manual implementation with a derive attribute
1515
|
1616
LL + #[derive(Default)]
17-
LL ~ struct FooDefault<'a> {
17+
LL | struct FooDefault<'a> {
1818
|
1919

2020
error: this `impl` can be derived
@@ -31,7 +31,7 @@ LL | | }
3131
help: replace the manual implementation with a derive attribute
3232
|
3333
LL + #[derive(Default)]
34-
LL ~ struct TupleDefault(bool, i32, u64);
34+
LL | struct TupleDefault(bool, i32, u64);
3535
|
3636

3737
error: this `impl` can be derived
@@ -48,7 +48,7 @@ LL | | }
4848
help: replace the manual implementation with a derive attribute
4949
|
5050
LL + #[derive(Default)]
51-
LL ~ struct StrDefault<'a>(&'a str);
51+
LL | struct StrDefault<'a>(&'a str);
5252
|
5353

5454
error: this `impl` can be derived
@@ -65,7 +65,7 @@ LL | | }
6565
help: replace the manual implementation with a derive attribute
6666
|
6767
LL + #[derive(Default)]
68-
LL ~ struct Y(u32);
68+
LL | struct Y(u32);
6969
|
7070

7171
error: this `impl` can be derived
@@ -82,7 +82,7 @@ LL | | }
8282
help: replace the manual implementation with a derive attribute
8383
|
8484
LL + #[derive(Default)]
85-
LL ~ struct WithoutSelfCurly {
85+
LL | struct WithoutSelfCurly {
8686
|
8787

8888
error: this `impl` can be derived
@@ -99,7 +99,7 @@ LL | | }
9999
help: replace the manual implementation with a derive attribute
100100
|
101101
LL + #[derive(Default)]
102-
LL ~ struct WithoutSelfParan(bool);
102+
LL | struct WithoutSelfParan(bool);
103103
|
104104

105105
error: this `impl` can be derived
@@ -115,7 +115,7 @@ LL | | }
115115
help: replace the manual implementation with a derive attribute
116116
|
117117
LL + #[derive(Default)]
118-
LL ~ pub struct DirectDefaultDefaultCall {
118+
LL | pub struct DirectDefaultDefaultCall {
119119
|
120120

121121
error: this `impl` can be derived
@@ -131,7 +131,7 @@ LL | | }
131131
help: replace the manual implementation with a derive attribute
132132
|
133133
LL + #[derive(Default)]
134-
LL ~ pub struct EquivalentToDefaultDefaultCallVec {
134+
LL | pub struct EquivalentToDefaultDefaultCallVec {
135135
|
136136

137137
error: this `impl` can be derived
@@ -147,7 +147,7 @@ LL | | }
147147
help: replace the manual implementation with a derive attribute
148148
|
149149
LL + #[derive(Default)]
150-
LL ~ pub struct EquivalentToDefaultDefaultCallLocal {
150+
LL | pub struct EquivalentToDefaultDefaultCallLocal {
151151
|
152152

153153
error: this `impl` can be derived
@@ -164,7 +164,7 @@ LL | | }
164164
help: replace the manual implementation with a derive attribute
165165
|
166166
LL + #[derive(Default)]
167-
LL ~ pub struct RepeatDefault1 {
167+
LL | pub struct RepeatDefault1 {
168168
|
169169

170170
error: this `impl` can be derived
@@ -181,7 +181,7 @@ LL | | }
181181
help: replace the manual implementation with a derive attribute and mark the default variant
182182
|
183183
LL + #[derive(Default)]
184-
LL ~ pub enum SimpleEnum {
184+
LL | pub enum SimpleEnum {
185185
LL | Foo,
186186
LL ~ #[default]
187187
LL ~ Bar,

tests/ui/half-open-range-patterns/range_pat_interactions1.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | 0..5+1 => errors_only.push(x),
88
help: consider extracting the expression into a `const`
99
|
1010
LL + const VAL: /* Type */ = 5+1;
11-
LL ~ match x as i32 {
11+
LL | match x as i32 {
1212
LL ~ 0..VAL => errors_only.push(x),
1313
|
1414

tests/ui/parser/issues/issue-24375.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL + val if val == tmp[0] => {}
1313
help: consider extracting the expression into a `const`
1414
|
1515
LL + const VAL: /* Type */ = tmp[0];
16-
LL ~ match z {
16+
LL | match z {
1717
LL ~ VAL => {}
1818
|
1919

tests/ui/parser/recover/recover-pat-exprs.stderr

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL + val if val == x.y => (),
1313
help: consider extracting the expression into a `const`
1414
|
1515
LL + const VAL: /* Type */ = x.y;
16-
LL ~ match 0 {
16+
LL | match 0 {
1717
LL | x => (),
1818
LL ~ VAL => (),
1919
|
@@ -33,7 +33,7 @@ LL + val if val == x.0 => (),
3333
help: consider extracting the expression into a `const`
3434
|
3535
LL + const VAL: /* Type */ = x.0;
36-
LL ~ match 0 {
36+
LL | match 0 {
3737
LL | x => (),
3838
LL | x.y => (),
3939
LL ~ VAL => (),
@@ -54,7 +54,7 @@ LL + val if val == x._0 => (),
5454
help: consider extracting the expression into a `const`
5555
|
5656
LL + const VAL: /* Type */ = x._0;
57-
LL ~ match 0 {
57+
LL | match 0 {
5858
LL | x => (),
5959
LL | x.y => (),
6060
LL | x.0 => (),
@@ -76,7 +76,7 @@ LL + val if val == x.0.1 => (),
7676
help: consider extracting the expression into a `const`
7777
|
7878
LL + const VAL: /* Type */ = x.0.1;
79-
LL ~ match 0 {
79+
LL | match 0 {
8080
LL | x => (),
8181
...
8282
LL | x._0 => (),
@@ -98,7 +98,7 @@ LL + val if val == x.4.y.17.__z => (),
9898
help: consider extracting the expression into a `const`
9999
|
100100
LL + const VAL: /* Type */ = x.4.y.17.__z;
101-
LL ~ match 0 {
101+
LL | match 0 {
102102
LL | x => (),
103103
...
104104
LL | x.0.1 => (),
@@ -150,7 +150,7 @@ LL + val if val == x[0] => (),
150150
help: consider extracting the expression into a `const`
151151
|
152152
LL + const VAL: /* Type */ = x[0];
153-
LL ~ match 0 {
153+
LL | match 0 {
154154
LL ~ VAL => (),
155155
|
156156

@@ -169,7 +169,7 @@ LL + val if val == x[..] => (),
169169
help: consider extracting the expression into a `const`
170170
|
171171
LL + const VAL: /* Type */ = x[..];
172-
LL ~ match 0 {
172+
LL | match 0 {
173173
LL | x[0] => (),
174174
LL ~ VAL => (),
175175
|
@@ -216,7 +216,7 @@ LL + val if val == x.f() => (),
216216
help: consider extracting the expression into a `const`
217217
|
218218
LL + const VAL: /* Type */ = x.f();
219-
LL ~ match 0 {
219+
LL | match 0 {
220220
LL ~ VAL => (),
221221
|
222222

@@ -235,7 +235,7 @@ LL + val if val == x._f() => (),
235235
help: consider extracting the expression into a `const`
236236
|
237237
LL + const VAL: /* Type */ = x._f();
238-
LL ~ match 0 {
238+
LL | match 0 {
239239
LL | x.f() => (),
240240
LL ~ VAL => (),
241241
|
@@ -255,7 +255,7 @@ LL + val if val == x? => (),
255255
help: consider extracting the expression into a `const`
256256
|
257257
LL + const VAL: /* Type */ = x?;
258-
LL ~ match 0 {
258+
LL | match 0 {
259259
LL | x.f() => (),
260260
LL | x._f() => (),
261261
LL ~ VAL => (),
@@ -276,7 +276,7 @@ LL + val if val == ().f() => (),
276276
help: consider extracting the expression into a `const`
277277
|
278278
LL + const VAL: /* Type */ = ().f();
279-
LL ~ match 0 {
279+
LL | match 0 {
280280
LL | x.f() => (),
281281
LL | x._f() => (),
282282
LL | x? => (),
@@ -298,7 +298,7 @@ LL + val if val == (0, x)?.f() => (),
298298
help: consider extracting the expression into a `const`
299299
|
300300
LL + const VAL: /* Type */ = (0, x)?.f();
301-
LL ~ match 0 {
301+
LL | match 0 {
302302
LL | x.f() => (),
303303
...
304304
LL | ().f() => (),
@@ -320,7 +320,7 @@ LL + val if val == x.f().g() => (),
320320
help: consider extracting the expression into a `const`
321321
|
322322
LL + const VAL: /* Type */ = x.f().g();
323-
LL ~ match 0 {
323+
LL | match 0 {
324324
LL | x.f() => (),
325325
...
326326
LL | (0, x)?.f() => (),
@@ -342,7 +342,7 @@ LL + val if val == 0.f()?.g()?? => (),
342342
help: consider extracting the expression into a `const`
343343
|
344344
LL + const VAL: /* Type */ = 0.f()?.g()??;
345-
LL ~ match 0 {
345+
LL | match 0 {
346346
LL | x.f() => (),
347347
...
348348
LL | x.f().g() => (),
@@ -364,7 +364,7 @@ LL + val if val == x as usize => (),
364364
help: consider extracting the expression into a `const`
365365
|
366366
LL + const VAL: /* Type */ = x as usize;
367-
LL ~ match 0 {
367+
LL | match 0 {
368368
LL ~ VAL => (),
369369
|
370370

@@ -383,7 +383,7 @@ LL + val if val == 0 as usize => (),
383383
help: consider extracting the expression into a `const`
384384
|
385385
LL + const VAL: /* Type */ = 0 as usize;
386-
LL ~ match 0 {
386+
LL | match 0 {
387387
LL | x as usize => (),
388388
LL ~ VAL => (),
389389
|
@@ -403,7 +403,7 @@ LL + val if val == x.f().0.4 as f32 => (),
403403
help: consider extracting the expression into a `const`
404404
|
405405
LL + const VAL: /* Type */ = x.f().0.4 as f32;
406-
LL ~ match 0 {
406+
LL | match 0 {
407407
LL | x as usize => (),
408408
LL | 0 as usize => (),
409409
LL ~ VAL => (),
@@ -424,7 +424,7 @@ LL + val if val == 1 + 1 => (),
424424
help: consider extracting the expression into a `const`
425425
|
426426
LL + const VAL: /* Type */ = 1 + 1;
427-
LL ~ match 0 {
427+
LL | match 0 {
428428
LL ~ VAL => (),
429429
|
430430

@@ -443,7 +443,7 @@ LL + val if val == (1 + 2) * 3 => (),
443443
help: consider extracting the expression into a `const`
444444
|
445445
LL + const VAL: /* Type */ = (1 + 2) * 3;
446-
LL ~ match 0 {
446+
LL | match 0 {
447447
LL | 1 + 1 => (),
448448
LL ~ VAL => (),
449449
|
@@ -463,7 +463,7 @@ LL + val if val == (x.0 > 2) => (),
463463
help: consider extracting the expression into a `const`
464464
|
465465
LL + const VAL: /* Type */ = x.0 > 2;
466-
LL ~ match 0 {
466+
LL | match 0 {
467467
LL | 1 + 1 => (),
468468
...
469469
LL |
@@ -485,7 +485,7 @@ LL + val if val == (x.0 == 2) => (),
485485
help: consider extracting the expression into a `const`
486486
|
487487
LL + const VAL: /* Type */ = x.0 == 2;
488-
LL ~ match 0 {
488+
LL | match 0 {
489489
LL | 1 + 1 => (),
490490
...
491491
LL | x.0 > 2 => (),
@@ -507,7 +507,7 @@ LL + (x, val) if x != 0 && val == (y.0 > 2) => (),
507507
help: consider extracting the expression into a `const`
508508
|
509509
LL + const VAL: /* Type */ = y.0 > 2;
510-
LL ~ match (0, 0) {
510+
LL | match (0, 0) {
511511
LL ~ (x, VAL) if x != 0 => (),
512512
|
513513

@@ -526,7 +526,7 @@ LL + (x, val) if (x != 0 || x != 1) && val == (y.0 > 2) => (),
526526
help: consider extracting the expression into a `const`
527527
|
528528
LL + const VAL: /* Type */ = y.0 > 2;
529-
LL ~ match (0, 0) {
529+
LL | match (0, 0) {
530530
LL | (x, y.0 > 2) if x != 0 => (),
531531
LL ~ (x, VAL) if x != 0 || x != 1 => (),
532532
|
@@ -563,7 +563,7 @@ LL + val if val == u8::MAX.abs() => (),
563563
help: consider extracting the expression into a `const`
564564
|
565565
LL + const VAL: /* Type */ = u8::MAX.abs();
566-
LL ~ match u8::MAX {
566+
LL | match u8::MAX {
567567
LL ~ VAL => (),
568568
|
569569

@@ -582,7 +582,7 @@ LL + z @ w @ val if val == v.u() => (),
582582
help: consider extracting the expression into a `const`
583583
|
584584
LL + const VAL: /* Type */ = v.u();
585-
LL ~ match u8::MAX {
585+
LL | match u8::MAX {
586586
LL | u8::MAX.abs() => (),
587587
...
588588
LL |
@@ -604,7 +604,7 @@ LL + val if val == y.ilog(3) => (),
604604
help: consider extracting the expression into a `const`
605605
|
606606
LL + const VAL: /* Type */ = y.ilog(3);
607-
LL ~ match u8::MAX {
607+
LL | match u8::MAX {
608608
LL | u8::MAX.abs() => (),
609609
...
610610
LL |
@@ -626,7 +626,7 @@ LL + val if val == n + 1 => (),
626626
help: consider extracting the expression into a `const`
627627
|
628628
LL + const VAL: /* Type */ = n + 1;
629-
LL ~ match u8::MAX {
629+
LL | match u8::MAX {
630630
LL | u8::MAX.abs() => (),
631631
...
632632
LL |
@@ -648,7 +648,7 @@ LL + (val) if val == "".f() + 14 * 8 => (),
648648
help: consider extracting the expression into a `const`
649649
|
650650
LL + const VAL: /* Type */ = "".f() + 14 * 8;
651-
LL ~ match u8::MAX {
651+
LL | match u8::MAX {
652652
LL | u8::MAX.abs() => (),
653653
...
654654
LL |
@@ -670,7 +670,7 @@ LL + val if val == f?() => (),
670670
help: consider extracting the expression into a `const`
671671
|
672672
LL + const VAL: /* Type */ = f?();
673-
LL ~ match u8::MAX {
673+
LL | match u8::MAX {
674674
LL | u8::MAX.abs() => (),
675675
...
676676
LL | 0 | ((1) | 2) | 3 => (),

0 commit comments

Comments
 (0)