diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 2d25d12d3a96..4b71aa6b85f1 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -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 diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 684e5a66fc51..0467f24948e7 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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 diff --git a/src/test/ui/block-result/consider-removing-last-semi.stderr b/src/test/ui/block-result/consider-removing-last-semi.stderr index 944c9d6c4279..282583d32a66 100644 --- a/src/test/ui/block-result/consider-removing-last-semi.stderr +++ b/src/test/ui/block-result/consider-removing-last-semi.stderr @@ -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 @@ -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) diff --git a/src/test/ui/block-result/issue-11714.stderr b/src/test/ui/block-result/issue-11714.stderr index cba9c3f51d7e..ed61ec6ca291 100644 --- a/src/test/ui/block-result/issue-11714.stderr +++ b/src/test/ui/block-result/issue-11714.stderr @@ -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) diff --git a/src/test/ui/block-result/issue-13428.stderr b/src/test/ui/block-result/issue-13428.stderr index d0ed8935cd77..5e8d92f64e29 100644 --- a/src/test/ui/block-result/issue-13428.stderr +++ b/src/test/ui/block-result/issue-13428.stderr @@ -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 @@ -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) diff --git a/src/test/ui/coercion-missing-tail-expected-type.stderr b/src/test/ui/coercion-missing-tail-expected-type.stderr index e96bc425e0b4..49e8b9febc2b 100644 --- a/src/test/ui/coercion-missing-tail-expected-type.stderr +++ b/src/test/ui/coercion-missing-tail-expected-type.stderr @@ -4,16 +4,12 @@ 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 @@ -21,16 +17,12 @@ error[E0308]: mismatched types 17 | fn foo() -> Result { | _____________________________^ 18 | | Ok(1); + | | - help: consider removing this semicolon 19 | | } | |_^ expected enum `std::result::Result`, found () | = note: expected type `std::result::Result` 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)