-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #98784 - compiler-errors:forgot-to-return-binding, r=…
…estebank Suggest returning local on "expected `ty`, found `()`" due to expr-less block Putting this up for _initial_ review. Notably, this doesn't consider if the value has possibly been moved, or whether the type is `Copy`. It also provides a structured suggestion if there's one "preferred" binding that matches the type (i.e. one binding in the block or its parent), otherwise it just points them out if there's fewer than 4 of them. Fixes #98177 r? `@estebank`
- Loading branch information
Showing
10 changed files
with
314 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn a(i: i32) -> i32 { | ||
//~^ ERROR mismatched types | ||
let j = 2i32; | ||
} | ||
|
||
fn b(i: i32, j: i32) -> i32 {} | ||
//~^ ERROR mismatched types | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/return-bindings-multi.rs:1:17 | ||
| | ||
LL | fn a(i: i32) -> i32 { | ||
| - ^^^ expected `i32`, found `()` | ||
| | | ||
| implicitly returns `()` as its body has no tail or `return` expression | ||
| | ||
note: consider returning one of these bindings | ||
--> $DIR/return-bindings-multi.rs:1:6 | ||
| | ||
LL | fn a(i: i32) -> i32 { | ||
| ^ | ||
LL | | ||
LL | let j = 2i32; | ||
| ^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/return-bindings-multi.rs:6:25 | ||
| | ||
LL | fn b(i: i32, j: i32) -> i32 {} | ||
| - ^^^ expected `i32`, found `()` | ||
| | | ||
| implicitly returns `()` as its body has no tail or `return` expression | ||
| | ||
note: consider returning one of these bindings | ||
--> $DIR/return-bindings-multi.rs:6:6 | ||
| | ||
LL | fn b(i: i32, j: i32) -> i32 {} | ||
| ^ ^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// run-rustfix | ||
|
||
#![allow(unused)] | ||
|
||
fn a(i: i32) -> i32 { i } | ||
//~^ ERROR mismatched types | ||
|
||
fn b(opt_str: Option<String>) { | ||
let s: String = if let Some(s) = opt_str { | ||
s | ||
//~^ ERROR mismatched types | ||
} else { | ||
String::new() | ||
}; | ||
} | ||
|
||
fn c() -> Option<i32> { | ||
//~^ ERROR mismatched types | ||
let x = Some(1); | ||
x | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// run-rustfix | ||
|
||
#![allow(unused)] | ||
|
||
fn a(i: i32) -> i32 {} | ||
//~^ ERROR mismatched types | ||
|
||
fn b(opt_str: Option<String>) { | ||
let s: String = if let Some(s) = opt_str { | ||
//~^ ERROR mismatched types | ||
} else { | ||
String::new() | ||
}; | ||
} | ||
|
||
fn c() -> Option<i32> { | ||
//~^ ERROR mismatched types | ||
let x = Some(1); | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.