Skip to content

Commit 5ddaece

Browse files
committed
slightly improve no return for returning function error
1 parent d9f8b4b commit 5ddaece

12 files changed

+18
-19
lines changed

compiler/rustc_hir_analysis/src/check/fn_ctxt/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11221122
} else {
11231123
err.span_suggestion_short(
11241124
span_semi,
1125-
"remove this semicolon",
1125+
"remove this semicolon to return this value",
11261126
"",
11271127
Applicability::MachineApplicable,
11281128
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub fn f() -> String {
77
| implicitly returns `()` as its body has no tail or `return` expression
88
LL | 0u8;
99
LL | "bla".to_string();
10-
| - help: remove this semicolon
10+
| - help: remove this semicolon to return this value
1111

1212
error[E0308]: mismatched types
1313
--> $DIR/consider-removing-last-semi.rs:8:15
@@ -18,7 +18,7 @@ LL | pub fn g() -> String {
1818
| implicitly returns `()` as its body has no tail or `return` expression
1919
LL | "this won't work".to_string();
2020
LL | "removeme".to_string();
21-
| - help: remove this semicolon
21+
| - help: remove this semicolon to return this value
2222

2323
error[E0308]: mismatched types
2424
--> $DIR/consider-removing-last-semi.rs:13:25
@@ -29,7 +29,7 @@ LL | pub fn macro_tests() -> u32 {
2929
| implicitly returns `()` as its body has no tail or `return` expression
3030
...
3131
LL | mac!();
32-
| - help: remove this semicolon
32+
| - help: remove this semicolon to return this value
3333

3434
error: aborting due to 3 previous errors
3535

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | fn blah() -> i32 {
77
| implicitly returns `()` as its body has no tail or `return` expression
88
...
99
LL | ;
10-
| - help: remove this semicolon
10+
| - help: remove this semicolon to return this value
1111

1212
error: aborting due to previous error
1313

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | fn bar() -> String {
1515
| implicitly returns `()` as its body has no tail or `return` expression
1616
LL | "foobar".to_string()
1717
LL | ;
18-
| - help: remove this semicolon
18+
| - help: remove this semicolon to return this value
1919

2020
error: aborting due to 2 previous errors
2121

src/test/ui/closures/old-closure-expression-remove-semicolon.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ fn foo() -> i32 {
77
fn main() {
88
let _x: i32 = {
99
//~^ ERROR mismatched types
10-
foo() //~ HELP remove this semicolon
10+
foo() //~ HELP remove this semicolon to return this value
1111
};
1212
}

src/test/ui/closures/old-closure-expression-remove-semicolon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ fn foo() -> i32 {
77
fn main() {
88
let _x: i32 = {
99
//~^ ERROR mismatched types
10-
foo(); //~ HELP remove this semicolon
10+
foo(); //~ HELP remove this semicolon to return this value
1111
};
1212
}

src/test/ui/closures/old-closure-expression-remove-semicolon.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let _x: i32 = {
55
| ___________________^
66
LL | |
77
LL | | foo();
8-
| | - help: remove this semicolon
8+
| | - help: remove this semicolon to return this value
99
LL | | };
1010
| |_____^ expected `i32`, found `()`
1111

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | fn plus_one(x: i32) -> i32 {
66
| |
77
| implicitly returns `()` as its body has no tail or `return` expression
88
LL | x + 1;
9-
| - help: remove this semicolon
9+
| - help: remove this semicolon to return this value
1010

1111
error[E0308]: mismatched types
1212
--> $DIR/coercion-missing-tail-expected-type.rs:8:13
@@ -16,7 +16,7 @@ LL | fn foo() -> Result<u8, u64> {
1616
| |
1717
| implicitly returns `()` as its body has no tail or `return` expression
1818
LL | Ok(1);
19-
| - help: remove this semicolon
19+
| - help: remove this semicolon to return this value
2020
|
2121
= note: expected enum `Result<u8, u64>`
2222
found unit type `()`

src/test/ui/issues/issue-6458-4.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | fn foo(b: bool) -> Result<bool,String> {
66
| |
77
| implicitly returns `()` as its body has no tail or `return` expression
88
LL | Err("bar".to_string());
9-
| - help: remove this semicolon
9+
| - help: remove this semicolon to return this value
1010
|
1111
= note: expected enum `Result<bool, String>`
1212
found unit type `()`

src/test/ui/liveness/liveness-return-last-stmt-semi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//
21
// regression test for #8005
32

43
macro_rules! test { () => { fn foo() -> i32 { 1; } } }

0 commit comments

Comments
 (0)