Skip to content

Commit 6bbaca7

Browse files
authored
Rollup merge of #94788 - estebank:removal-suggestion, r=petrochenkov
Account for suggestions for complete removal of lines Fix #94192.
2 parents e7281d0 + ac2afa0 commit 6bbaca7

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

compiler/rustc_errors/src/emitter.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,31 @@ impl EmitterWriter {
16571657
let line_start = sm.lookup_char_pos(parts[0].span.lo()).line;
16581658
draw_col_separator_no_space(&mut buffer, 1, max_line_num_len + 1);
16591659
let mut lines = complete.lines();
1660+
if lines.clone().next().is_none() {
1661+
// Account for a suggestion to completely remove a line(s) with whitespace (#94192).
1662+
let line_end = sm.lookup_char_pos(parts[0].span.hi()).line;
1663+
for line in line_start..=line_end {
1664+
buffer.puts(
1665+
row_num - 1 + line - line_start,
1666+
0,
1667+
&self.maybe_anonymized(line),
1668+
Style::LineNumber,
1669+
);
1670+
buffer.puts(
1671+
row_num - 1 + line - line_start,
1672+
max_line_num_len + 1,
1673+
"- ",
1674+
Style::Removal,
1675+
);
1676+
buffer.puts(
1677+
row_num - 1 + line - line_start,
1678+
max_line_num_len + 3,
1679+
&normalize_whitespace(&*file_lines.file.get_line(line - 1).unwrap()),
1680+
Style::Removal,
1681+
);
1682+
}
1683+
row_num += line_end - line_start;
1684+
}
16601685
for (line_pos, (line, highlight_parts)) in
16611686
lines.by_ref().zip(highlights).take(MAX_SUGGESTION_HIGHLIGHT_LINES).enumerate()
16621687
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
struct Wrapper<T>(T);
2+
3+
fn foo<T>(foo: Wrapper<T>)
4+
//~^ ERROR the size for values of type `T` cannot be known at compilation time
5+
where
6+
T
7+
:
8+
?
9+
Sized
10+
{
11+
//
12+
}
13+
14+
fn bar<T>(foo: Wrapper<T>)
15+
//~^ ERROR the size for values of type `T` cannot be known at compilation time
16+
where T: ?Sized
17+
{
18+
//
19+
}
20+
21+
fn qux<T>(foo: Wrapper<T>)
22+
//~^ ERROR the size for values of type `T` cannot be known at compilation time
23+
where
24+
T: ?Sized
25+
{
26+
//
27+
}
28+
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
error[E0277]: the size for values of type `T` cannot be known at compilation time
2+
--> $DIR/removal-of-multiline-trait-bound-in-where-clause.rs:3:16
3+
|
4+
LL | fn foo<T>(foo: Wrapper<T>)
5+
| - ^^^^^^^^^^ doesn't have a size known at compile-time
6+
| |
7+
| this type parameter needs to be `std::marker::Sized`
8+
|
9+
note: required by a bound in `Wrapper`
10+
--> $DIR/removal-of-multiline-trait-bound-in-where-clause.rs:1:16
11+
|
12+
LL | struct Wrapper<T>(T);
13+
| ^ required by this bound in `Wrapper`
14+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
15+
--> $DIR/removal-of-multiline-trait-bound-in-where-clause.rs:1:16
16+
|
17+
LL | struct Wrapper<T>(T);
18+
| ^ - ...if indirection were used here: `Box<T>`
19+
| |
20+
| this could be changed to `T: ?Sized`...
21+
help: consider removing the `?Sized` bound to make the type parameter `Sized`
22+
|
23+
LL - where
24+
LL - T
25+
LL - :
26+
LL - ?
27+
LL - Sized
28+
|
29+
30+
error[E0277]: the size for values of type `T` cannot be known at compilation time
31+
--> $DIR/removal-of-multiline-trait-bound-in-where-clause.rs:14:16
32+
|
33+
LL | fn bar<T>(foo: Wrapper<T>)
34+
| - ^^^^^^^^^^ doesn't have a size known at compile-time
35+
| |
36+
| this type parameter needs to be `std::marker::Sized`
37+
|
38+
note: required by a bound in `Wrapper`
39+
--> $DIR/removal-of-multiline-trait-bound-in-where-clause.rs:1:16
40+
|
41+
LL | struct Wrapper<T>(T);
42+
| ^ required by this bound in `Wrapper`
43+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
44+
--> $DIR/removal-of-multiline-trait-bound-in-where-clause.rs:1:16
45+
|
46+
LL | struct Wrapper<T>(T);
47+
| ^ - ...if indirection were used here: `Box<T>`
48+
| |
49+
| this could be changed to `T: ?Sized`...
50+
help: consider removing the `?Sized` bound to make the type parameter `Sized`
51+
|
52+
LL - where T: ?Sized
53+
|
54+
55+
error[E0277]: the size for values of type `T` cannot be known at compilation time
56+
--> $DIR/removal-of-multiline-trait-bound-in-where-clause.rs:21:16
57+
|
58+
LL | fn qux<T>(foo: Wrapper<T>)
59+
| - ^^^^^^^^^^ doesn't have a size known at compile-time
60+
| |
61+
| this type parameter needs to be `std::marker::Sized`
62+
|
63+
note: required by a bound in `Wrapper`
64+
--> $DIR/removal-of-multiline-trait-bound-in-where-clause.rs:1:16
65+
|
66+
LL | struct Wrapper<T>(T);
67+
| ^ required by this bound in `Wrapper`
68+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
69+
--> $DIR/removal-of-multiline-trait-bound-in-where-clause.rs:1:16
70+
|
71+
LL | struct Wrapper<T>(T);
72+
| ^ - ...if indirection were used here: `Box<T>`
73+
| |
74+
| this could be changed to `T: ?Sized`...
75+
help: consider removing the `?Sized` bound to make the type parameter `Sized`
76+
|
77+
LL - where
78+
LL - T: ?Sized
79+
|
80+
81+
error: aborting due to 3 previous errors
82+
83+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)