about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/errors.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-03 18:57:49 +0000
committerbors <bors@rust-lang.org>2023-12-03 18:57:49 +0000
commitd12dc74a2c2543619fc38c98b2efe6f76d552196 (patch)
treea8581af97bcad2aad446feca60c1a38af75cf7e9 /compiler/rustc_codegen_llvm/src/errors.rs
parentdb07cccb1e6b448eb1fec576096b587680e4ff69 (diff)
parent45efb8e6a68081462a70fa8cb40510d50ab848a4 (diff)
downloadrust-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