Skip to content

Commit a416a19

Browse files
committed
Add test for current behaviour.
This commit adds a test for the current behaviour of signature deduction of generators when there is a type mismatch between the return type of the function body and the signature.
1 parent 40bd145 commit a416a19

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(generators, generator_trait)]
2+
3+
use std::ops::Generator;
4+
5+
fn foo() -> impl Generator<Return = i32> { //~ ERROR type mismatch
6+
|| {
7+
if false {
8+
return Ok(6);
9+
}
10+
11+
yield ();
12+
13+
5 //~ ERROR mismatched types [E0308]
14+
}
15+
}
16+
17+
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/type-mismatch-signature-deduction.rs:13:9
3+
|
4+
LL | 5
5+
| ^ expected enum `std::result::Result`, found integer
6+
|
7+
= note: expected type `std::result::Result<{integer}, _>`
8+
found type `{integer}`
9+
10+
error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature-deduction.rs:6:5: 14:6 _] as std::ops::Generator>::Return == i32`
11+
--> $DIR/type-mismatch-signature-deduction.rs:5:13
12+
|
13+
LL | fn foo() -> impl Generator<Return = i32> {
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found i32
15+
|
16+
= note: expected type `std::result::Result<{integer}, _>`
17+
found type `i32`
18+
= note: the return type of a function must have a statically known size
19+
20+
error: aborting due to 2 previous errors
21+
22+
Some errors have detailed explanations: E0271, E0308.
23+
For more information about an error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)