Skip to content

Slightly improve no return for returning function error #102650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
err.span_suggestion_short(
span_semi,
"remove this semicolon",
"remove this semicolon to return this value",
"",
Applicability::MachineApplicable,
);
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/block-result/consider-removing-last-semi.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | pub fn f() -> String {
| implicitly returns `()` as its body has no tail or `return` expression
LL | 0u8;
LL | "bla".to_string();
| - help: remove this semicolon
| - help: remove this semicolon to return this value

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

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

error: aborting due to 3 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/block-result/issue-11714.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | fn blah() -> i32 {
| implicitly returns `()` as its body has no tail or `return` expression
...
LL | ;
| - help: remove this semicolon
| - help: remove this semicolon to return this value

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/block-result/issue-13428.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ LL | fn bar() -> String {
| implicitly returns `()` as its body has no tail or `return` expression
LL | "foobar".to_string()
LL | ;
| - help: remove this semicolon
| - help: remove this semicolon to return this value

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ fn foo() -> i32 {
fn main() {
let _x: i32 = {
//~^ ERROR mismatched types
foo() //~ HELP remove this semicolon
foo() //~ HELP remove this semicolon to return this value
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ fn foo() -> i32 {
fn main() {
let _x: i32 = {
//~^ ERROR mismatched types
foo(); //~ HELP remove this semicolon
foo(); //~ HELP remove this semicolon to return this value
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let _x: i32 = {
| ___________________^
LL | |
LL | | foo();
| | - help: remove this semicolon
| | - help: remove this semicolon to return this value
LL | | };
| |_____^ expected `i32`, found `()`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | fn plus_one(x: i32) -> i32 {
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | x + 1;
| - help: remove this semicolon
| - help: remove this semicolon to return this value

error[E0308]: mismatched types
--> $DIR/coercion-missing-tail-expected-type.rs:8:13
Expand All @@ -16,7 +16,7 @@ LL | fn foo() -> Result<u8, u64> {
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | Ok(1);
| - help: remove this semicolon
| - help: remove this semicolon to return this value
|
= note: expected enum `Result<u8, u64>`
found unit type `()`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-6458-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | fn foo(b: bool) -> Result<bool,String> {
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | Err("bar".to_string());
| - help: remove this semicolon
| - help: remove this semicolon to return this value
|
= note: expected enum `Result<bool, String>`
found unit type `()`
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/liveness/liveness-return-last-stmt-semi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//
// regression test for #8005

macro_rules! test { () => { fn foo() -> i32 { 1; } } }
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/liveness/liveness-return-last-stmt-semi.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
error[E0308]: mismatched types
--> $DIR/liveness-return-last-stmt-semi.rs:7:19
--> $DIR/liveness-return-last-stmt-semi.rs:6:19
|
LL | fn no_return() -> i32 {}
| --------- ^^^ expected `i32`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression

error[E0308]: mismatched types
--> $DIR/liveness-return-last-stmt-semi.rs:9:19
--> $DIR/liveness-return-last-stmt-semi.rs:8:19
|
LL | fn bar(x: u32) -> u32 {
| --- ^^^ expected `u32`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | x * 2;
| - help: remove this semicolon
| - help: remove this semicolon to return this value

error[E0308]: mismatched types
--> $DIR/liveness-return-last-stmt-semi.rs:13:19
--> $DIR/liveness-return-last-stmt-semi.rs:12:19
|
LL | fn baz(x: u64) -> u32 {
| --- ^^^ expected `u32`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression

error[E0308]: mismatched types
--> $DIR/liveness-return-last-stmt-semi.rs:4:41
--> $DIR/liveness-return-last-stmt-semi.rs:3:41
|
LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } }
| --- ^^^ expected `i32`, found `()`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | fn not_all_paths(a: &str) -> u32 {
| implicitly returns `()` as its body has no tail or `return` expression
...
LL | };
| - help: remove this semicolon
| - help: remove this semicolon to return this value

error[E0308]: `match` arms have incompatible types
--> $DIR/match-with-different-arm-types-as-stmt-instead-of-expr.rs:26:14
Expand Down