-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/test/ui/generator/type-mismatch-signature-deduction.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![feature(generators, generator_trait)] | ||
|
||
use std::ops::Generator; | ||
|
||
fn foo() -> impl Generator<Return = i32> { //~ ERROR type mismatch | ||
|| { | ||
if false { | ||
return Ok(6); | ||
} | ||
|
||
yield (); | ||
|
||
5 //~ ERROR mismatched types [E0308] | ||
} | ||
} | ||
|
||
fn main() {} |
23 changes: 23 additions & 0 deletions
23
src/test/ui/generator/type-mismatch-signature-deduction.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/type-mismatch-signature-deduction.rs:13:9 | ||
| | ||
LL | 5 | ||
| ^ expected enum `std::result::Result`, found integer | ||
| | ||
= note: expected type `std::result::Result<{integer}, _>` | ||
found type `{integer}` | ||
|
||
error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature-deduction.rs:6:5: 14:6 _] as std::ops::Generator>::Return == i32` | ||
--> $DIR/type-mismatch-signature-deduction.rs:5:13 | ||
| | ||
LL | fn foo() -> impl Generator<Return = i32> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found i32 | ||
| | ||
= note: expected type `std::result::Result<{integer}, _>` | ||
found type `i32` | ||
= note: the return type of a function must have a statically known size | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0271, E0308. | ||
For more information about an error, try `rustc --explain E0271`. |