Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Trust signature over return expr for generators.
This commit extends the logic used to determine what the expected signature of a closure is so that it can also determine the expected signature of a generator. This improves a diagnostic where the fn signature was blamed instead of the generator body. It doesn't fix fix the diagnostic for `async fn`.
- Loading branch information
Showing
5 changed files
with
53 additions
and
53 deletions.
There are no files selected for viewing
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
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
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
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
25 changes: 7 additions & 18 deletions
25
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 |
---|---|---|
@@ -1,23 +1,12 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/type-mismatch-signature-deduction.rs:13:9 | ||
--> $DIR/type-mismatch-signature-deduction.rs:8:20 | ||
| | ||
LL | 5 | ||
| ^ expected enum `std::result::Result`, found integer | ||
LL | return Ok(6); | ||
| ^^^^^ expected i32, found enum `std::result::Result` | ||
| | ||
= note: expected type `std::result::Result<{integer}, _>` | ||
found type `{integer}` | ||
= note: expected type `i32` | ||
found type `std::result::Result<{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 | ||
error: aborting due to previous error | ||
|
||
Some errors have detailed explanations: E0271, E0308. | ||
For more information about an error, try `rustc --explain E0271`. | ||
For more information about this error, try `rustc --explain E0308`. |