Skip to content

Commit ecde91a

Browse files
committed
Suggest removal of semicolon (instead of being help)
1 parent c023856 commit ecde91a

File tree

6 files changed

+14
-37
lines changed

6 files changed

+14
-37
lines changed

src/librustc_errors/emitter.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ impl Emitter for EmitterWriter {
4747
// don't display multiline suggestions as labels
4848
sugg.substitution_parts[0].substitutions[0].find('\n').is_none() {
4949
let substitution = &sugg.substitution_parts[0].substitutions[0];
50-
let msg = format!("help: {} `{}`", sugg.msg, substitution);
50+
let msg = if substitution.len() == 0 {
51+
// This substitution is only removal, don't show it
52+
format!("help: {}", sugg.msg)
53+
} else {
54+
format!("help: {} `{}`", sugg.msg, substitution)
55+
};
5156
primary_span.push_span_label(sugg.substitution_spans().next().unwrap(), msg);
5257
} else {
5358
// if there are multiple suggestions, print them all in full

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4391,7 +4391,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
43914391
hi: original_span.hi,
43924392
ctxt: original_span.ctxt,
43934393
};
4394-
err.span_help(span_semi, "consider removing this semicolon:");
4394+
err.span_suggestion(span_semi, "consider removing this semicolon", "".to_string());
43954395
}
43964396

43974397
// Instantiates the given path, which must refer to an item with the given

src/test/ui/block-result/consider-removing-last-semi.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ error[E0308]: mismatched types
55
| __________________^
66
12 | | 0u8;
77
13 | | "bla".to_string(); //~ HELP consider removing this semicolon
8+
| | - help: consider removing this semicolon
89
14 | | }
910
| |_^ expected struct `std::string::String`, found ()
1011
|
1112
= note: expected type `std::string::String`
1213
found type `()`
13-
help: consider removing this semicolon:
14-
--> $DIR/consider-removing-last-semi.rs:13:22
15-
|
16-
13 | "bla".to_string(); //~ HELP consider removing this semicolon
17-
| ^
1814

1915
error[E0308]: mismatched types
2016
--> $DIR/consider-removing-last-semi.rs:16:18
@@ -23,16 +19,12 @@ error[E0308]: mismatched types
2319
| __________________^
2420
17 | | "this won't work".to_string();
2521
18 | | "removeme".to_string(); //~ HELP consider removing this semicolon
22+
| | - help: consider removing this semicolon
2623
19 | | }
2724
| |_^ expected struct `std::string::String`, found ()
2825
|
2926
= note: expected type `std::string::String`
3027
found type `()`
31-
help: consider removing this semicolon:
32-
--> $DIR/consider-removing-last-semi.rs:18:27
33-
|
34-
18 | "removeme".to_string(); //~ HELP consider removing this semicolon
35-
| ^
3628

3729
error: aborting due to previous error(s)
3830

src/test/ui/block-result/issue-11714.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ error[E0308]: mismatched types
66
12 | | 1
77
13 | |
88
14 | | ; //~ HELP consider removing this semicolon:
9+
| | - help: consider removing this semicolon
910
15 | | }
1011
| |_^ expected i32, found ()
1112
|
1213
= note: expected type `i32`
1314
found type `()`
14-
help: consider removing this semicolon:
15-
--> $DIR/issue-11714.rs:14:5
16-
|
17-
14 | ; //~ HELP consider removing this semicolon:
18-
| ^
1915

2016
error: aborting due to previous error(s)
2117

src/test/ui/block-result/issue-13428.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ error[E0308]: mismatched types
88
16 | | // Put the trailing semicolon on its own line to test that the
99
17 | | // note message gets the offending semicolon exactly
1010
18 | | ; //~ HELP consider removing this semicolon
11+
| | - help: consider removing this semicolon
1112
19 | | }
1213
| |_^ expected struct `std::string::String`, found ()
1314
|
1415
= note: expected type `std::string::String`
1516
found type `()`
16-
help: consider removing this semicolon:
17-
--> $DIR/issue-13428.rs:18:5
18-
|
19-
18 | ; //~ HELP consider removing this semicolon
20-
| ^
2117

2218
error[E0308]: mismatched types
2319
--> $DIR/issue-13428.rs:21:20
@@ -26,16 +22,12 @@ error[E0308]: mismatched types
2622
| ____________________^
2723
22 | | "foobar".to_string()
2824
23 | | ; //~ HELP consider removing this semicolon
25+
| | - help: consider removing this semicolon
2926
24 | | }
3027
| |_^ expected struct `std::string::String`, found ()
3128
|
3229
= note: expected type `std::string::String`
3330
found type `()`
34-
help: consider removing this semicolon:
35-
--> $DIR/issue-13428.rs:23:5
36-
|
37-
23 | ; //~ HELP consider removing this semicolon
38-
| ^
3931

4032
error: aborting due to previous error(s)
4133

src/test/ui/coercion-missing-tail-expected-type.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,25 @@ error[E0308]: mismatched types
44
13 | fn plus_one(x: i32) -> i32 {
55
| ____________________________^
66
14 | | x + 1;
7+
| | - help: consider removing this semicolon
78
15 | | }
89
| |_^ expected i32, found ()
910
|
1011
= note: expected type `i32`
1112
found type `()`
12-
help: consider removing this semicolon:
13-
--> $DIR/coercion-missing-tail-expected-type.rs:14:10
14-
|
15-
14 | x + 1;
16-
| ^
1713

1814
error[E0308]: mismatched types
1915
--> $DIR/coercion-missing-tail-expected-type.rs:17:29
2016
|
2117
17 | fn foo() -> Result<u8, u64> {
2218
| _____________________________^
2319
18 | | Ok(1);
20+
| | - help: consider removing this semicolon
2421
19 | | }
2522
| |_^ expected enum `std::result::Result`, found ()
2623
|
2724
= note: expected type `std::result::Result<u8, u64>`
2825
found type `()`
29-
help: consider removing this semicolon:
30-
--> $DIR/coercion-missing-tail-expected-type.rs:18:10
31-
|
32-
18 | Ok(1);
33-
| ^
3426

3527
error: aborting due to previous error(s)
3628

0 commit comments

Comments
 (0)