diff options
| author | bors <bors@rust-lang.org> | 2023-12-03 18:57:49 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-03 18:57:49 +0000 |
| commit | d12dc74a2c2543619fc38c98b2efe6f76d552196 (patch) | |
| tree | a8581af97bcad2aad446feca60c1a38af75cf7e9 /compiler/rustc_codegen_llvm/src/errors.rs | |
| parent | db07cccb1e6b448eb1fec576096b587680e4ff69 (diff) | |
| parent | 45efb8e6a68081462a70fa8cb40510d50ab848a4 (diff) | |
| download | rust-d12dc74a2c2543619fc38c98b2efe6f76d552196.tar.gz rust-d12dc74a2c2543619fc38c98b2efe6f76d552196.zip | |
Auto merge of #118072 - estebank:issue-98982, r=cjgillot
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/errors.rs')
0 files changed, 0 insertions, 0 deletions
