about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2017-06-24 01:09:57 -0700
committerEsteban Küber <esteban@kuber.com.ar>2017-06-24 10:08:51 -0700
commitecde91a69d8414113b71bf2f5c79e607861dba23 (patch)
tree922599d94a469c29aeda272d9529867e3b630947
parentc023856b38c847731720fa8e26f3e1b9062bc946 (diff)
downloadrust-ecde91a69d8414113b71bf2f5c79e607861dba23.tar.gz
rust-ecde91a69d8414113b71bf2f5c79e607861dba23.zip
Suggest removal of semicolon (instead of being help)
-rw-r--r--src/librustc_errors/emitter.rs7
-rw-r--r--src/librustc_typeck/check/mod.rs2
-rw-r--r--src/test/ui/block-result/consider-removing-last-semi.stderr12
-rw-r--r--src/test/ui/block-result/issue-11714.stderr6
-rw-r--r--src/test/ui/block-result/issue-13428.stderr12
-rw-r--r--src/test/ui/coercion-missing-tail-expected-type.stderr12
6 files changed, 14 insertions, 37 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 2d25d12d3a9..4b71aa6b85f 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 684e5a66fc5..0467f24948e 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 944c9d6c427..282583d32a6 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 cba9c3f51d7..ed61ec6ca29 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 d0ed8935cd7..5e8d92f64e2 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 e96bc425e0b..49e8b9febc2 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<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)