diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2023-11-19 21:01:57 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2023-11-22 19:56:53 +0000 |
| commit | 45efb8e6a68081462a70fa8cb40510d50ab848a4 (patch) | |
| tree | 7b31a678fb172e6f6ad6f2809abd364e568fc3c6 /compiler/rustc_codegen_llvm/src | |
| parent | 73bc12199ea8c7651ed98b069c0dd6b0bb5fabcf (diff) | |
| download | rust-45efb8e6a68081462a70fa8cb40510d50ab848a4.tar.gz rust-45efb8e6a68081462a70fa8cb40510d50ab848a4.zip | |
Provide structured suggestion for type mismatch in loop
We currently provide only a `help` message, this PR introduces the last
two structured suggestions instead:
```
error[E0308]: mismatched types
--> $DIR/issue-98982.rs:2:5
|
LL | fn foo() -> i32 {
| --- expected `i32` because of return type
LL | / for i in 0..0 {
LL | | return i;
LL | | }
| |_____^ expected `i32`, found `()`
|
note: the function expects a value to always be returned, but loops might run zero times
--> $DIR/issue-98982.rs:2:5
|
LL | for i in 0..0 {
| ^^^^^^^^^^^^^ this might have zero elements to iterate on
LL | return i;
| -------- if the loop doesn't execute, this value would never get returned
help: return a value for the case when the loop has zero elements to iterate on
|
LL ~ }
LL ~ /* `i32` value */
|
help: otherwise consider changing the return type to account for that possibility
|
LL ~ fn foo() -> Option<i32> {
LL | for i in 0..0 {
LL ~ return Some(i);
LL ~ }
LL ~ None
|
```
Fix #98982.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions
