Rollup merge of #78235 - Aaron1011:closure-ret-infer, r=varkor
Explain where the closure return type was inferred Fixes #78193
This commit is contained in:
commit
3f462c22b5
4 changed files with 65 additions and 0 deletions
17
src/test/ui/closures/closure-return-type-mismatch.rs
Normal file
17
src/test/ui/closures/closure-return-type-mismatch.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
fn main() {
|
||||
|| {
|
||||
if false {
|
||||
return "test";
|
||||
}
|
||||
let a = true;
|
||||
a //~ ERROR mismatched types
|
||||
};
|
||||
|
||||
|| -> bool {
|
||||
if false {
|
||||
return "hello" //~ ERROR mismatched types
|
||||
};
|
||||
let b = true;
|
||||
b
|
||||
};
|
||||
}
|
||||
21
src/test/ui/closures/closure-return-type-mismatch.stderr
Normal file
21
src/test/ui/closures/closure-return-type-mismatch.stderr
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/closure-return-type-mismatch.rs:7:9
|
||||
|
|
||||
LL | a
|
||||
| ^ expected `&str`, found `bool`
|
||||
|
|
||||
note: return type inferred to be `&str` here
|
||||
--> $DIR/closure-return-type-mismatch.rs:4:20
|
||||
|
|
||||
LL | return "test";
|
||||
| ^^^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/closure-return-type-mismatch.rs:12:20
|
||||
|
|
||||
LL | return "hello"
|
||||
| ^^^^^^^ expected `bool`, found `&str`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
|
@ -6,6 +6,11 @@ LL | 5
|
|||
|
|
||||
= note: expected type `std::result::Result<{integer}, _>`
|
||||
found type `{integer}`
|
||||
note: return type inferred to be `std::result::Result<{integer}, _>` here
|
||||
--> $DIR/type-mismatch-signature-deduction.rs:8:20
|
||||
|
|
||||
LL | return Ok(6);
|
||||
| ^^^^^
|
||||
|
||||
error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature-deduction.rs:6:5: 14:6] as Generator>::Return == i32`
|
||||
--> $DIR/type-mismatch-signature-deduction.rs:5:13
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue