Skip to content

Commit

Permalink
Suggest removal of semicolon (instead of being help)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jun 24, 2017
1 parent c023856 commit ecde91a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 37 deletions.
7 changes: 6 additions & 1 deletion src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ impl Emitter for EmitterWriter {
// don't display multiline suggestions as labels
sugg.substitution_parts[0].substitutions[0].find('\n').is_none() {
let substitution = &sugg.substitution_parts[0].substitutions[0];
let msg = format!("help: {} `{}`", sugg.msg, substitution);
let msg = if substitution.len() == 0 {
// This substitution is only removal, don't show it
format!("help: {}", sugg.msg)
} else {
format!("help: {} `{}`", sugg.msg, substitution)
};
primary_span.push_span_label(sugg.substitution_spans().next().unwrap(), msg);
} else {
// if there are multiple suggestions, print them all in full
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4391,7 +4391,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
hi: original_span.hi,
ctxt: original_span.ctxt,
};
err.span_help(span_semi, "consider removing this semicolon:");
err.span_suggestion(span_semi, "consider removing this semicolon", "".to_string());
}

// Instantiates the given path, which must refer to an item with the given
Expand Down
12 changes: 2 additions & 10 deletions src/test/ui/block-result/consider-removing-last-semi.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ error[E0308]: mismatched types
| __________________^
12 | | 0u8;
13 | | "bla".to_string(); //~ HELP consider removing this semicolon
| | - help: consider removing this semicolon
14 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
found type `()`
help: consider removing this semicolon:
--> $DIR/consider-removing-last-semi.rs:13:22
|
13 | "bla".to_string(); //~ HELP consider removing this semicolon
| ^

error[E0308]: mismatched types
--> $DIR/consider-removing-last-semi.rs:16:18
Expand All @@ -23,16 +19,12 @@ error[E0308]: mismatched types
| __________________^
17 | | "this won't work".to_string();
18 | | "removeme".to_string(); //~ HELP consider removing this semicolon
| | - help: consider removing this semicolon
19 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
found type `()`
help: consider removing this semicolon:
--> $DIR/consider-removing-last-semi.rs:18:27
|
18 | "removeme".to_string(); //~ HELP consider removing this semicolon
| ^

error: aborting due to previous error(s)

6 changes: 1 addition & 5 deletions src/test/ui/block-result/issue-11714.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ error[E0308]: mismatched types
12 | | 1
13 | |
14 | | ; //~ HELP consider removing this semicolon:
| | - help: consider removing this semicolon
15 | | }
| |_^ expected i32, found ()
|
= note: expected type `i32`
found type `()`
help: consider removing this semicolon:
--> $DIR/issue-11714.rs:14:5
|
14 | ; //~ HELP consider removing this semicolon:
| ^

error: aborting due to previous error(s)

12 changes: 2 additions & 10 deletions src/test/ui/block-result/issue-13428.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ error[E0308]: mismatched types
16 | | // Put the trailing semicolon on its own line to test that the
17 | | // note message gets the offending semicolon exactly
18 | | ; //~ HELP consider removing this semicolon
| | - help: consider removing this semicolon
19 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
found type `()`
help: consider removing this semicolon:
--> $DIR/issue-13428.rs:18:5
|
18 | ; //~ HELP consider removing this semicolon
| ^

error[E0308]: mismatched types
--> $DIR/issue-13428.rs:21:20
Expand All @@ -26,16 +22,12 @@ error[E0308]: mismatched types
| ____________________^
22 | | "foobar".to_string()
23 | | ; //~ HELP consider removing this semicolon
| | - help: consider removing this semicolon
24 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
found type `()`
help: consider removing this semicolon:
--> $DIR/issue-13428.rs:23:5
|
23 | ; //~ HELP consider removing this semicolon
| ^

error: aborting due to previous error(s)

12 changes: 2 additions & 10 deletions src/test/ui/coercion-missing-tail-expected-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,25 @@ error[E0308]: mismatched types
13 | fn plus_one(x: i32) -> i32 {
| ____________________________^
14 | | x + 1;
| | - help: consider removing this semicolon
15 | | }
| |_^ expected i32, found ()
|
= note: expected type `i32`
found type `()`
help: consider removing this semicolon:
--> $DIR/coercion-missing-tail-expected-type.rs:14:10
|
14 | x + 1;
| ^

error[E0308]: mismatched types
--> $DIR/coercion-missing-tail-expected-type.rs:17:29
|
17 | fn foo() -> Result<u8, u64> {
| _____________________________^
18 | | Ok(1);
| | - help: consider removing this semicolon
19 | | }
| |_^ expected enum `std::result::Result`, found ()
|
= note: expected type `std::result::Result<u8, u64>`
found type `()`
help: consider removing this semicolon:
--> $DIR/coercion-missing-tail-expected-type.rs:18:10
|
18 | Ok(1);
| ^

error: aborting due to previous error(s)

0 comments on commit ecde91a

Please sign in to comment.