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`.
This commit is contained in:
parent
a416a19153
commit
f2919a31c8
5 changed files with 53 additions and 53 deletions
|
|
@ -13,7 +13,7 @@ pub fn want_cyclic_generator_return<T>(_: T)
|
|||
|
||||
fn supply_cyclic_generator_return() {
|
||||
want_cyclic_generator_return(|| {
|
||||
//~^ ERROR type mismatch
|
||||
//~^ ERROR closure/generator type that references itself
|
||||
if false { yield None.unwrap(); }
|
||||
None.unwrap()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
error[E0271]: type mismatch resolving `<[generator@$DIR/generator-yielding-or-returning-itself.rs:15:34: 19:6 _] as std::ops::Generator>::Return == [generator@$DIR/generator-yielding-or-returning-itself.rs:15:34: 19:6 _]`
|
||||
--> $DIR/generator-yielding-or-returning-itself.rs:15:5
|
||||
error[E0644]: closure/generator type that references itself
|
||||
--> $DIR/generator-yielding-or-returning-itself.rs:15:34
|
||||
|
|
||||
LL | want_cyclic_generator_return(|| {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size
|
||||
LL | want_cyclic_generator_return(|| {
|
||||
| __________________________________^
|
||||
LL | |
|
||||
LL | | if false { yield None.unwrap(); }
|
||||
LL | | None.unwrap()
|
||||
LL | | })
|
||||
| |_____^ cyclic type of infinite size
|
||||
|
|
||||
= note: closures cannot capture themselves or take themselves as argument;
|
||||
this error may be the result of a recent compiler bug-fix,
|
||||
see https://github.com/rust-lang/rust/issues/46062 for more details
|
||||
note: required by `want_cyclic_generator_return`
|
||||
--> $DIR/generator-yielding-or-returning-itself.rs:9:1
|
||||
|
|
||||
LL | / pub fn want_cyclic_generator_return<T>(_: T)
|
||||
LL | | where T: Generator<Yield = (), Return = T>
|
||||
LL | | {
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error[E0271]: type mismatch resolving `<[generator@$DIR/generator-yielding-or-returning-itself.rs:28:33: 32:6 _] as std::ops::Generator>::Yield == [generator@$DIR/generator-yielding-or-returning-itself.rs:28:33: 32:6 _]`
|
||||
--> $DIR/generator-yielding-or-returning-itself.rs:28:5
|
||||
|
|
@ -36,4 +33,5 @@ LL | | }
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
Some errors have detailed explanations: E0271, E0644.
|
||||
For more information about an error, try `rustc --explain E0271`.
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
use std::ops::Generator;
|
||||
|
||||
fn foo() -> impl Generator<Return = i32> { //~ ERROR type mismatch
|
||||
fn foo() -> impl Generator<Return = i32> {
|
||||
|| {
|
||||
if false {
|
||||
return Ok(6);
|
||||
return Ok(6); //~ ERROR mismatched types [E0308]
|
||||
}
|
||||
|
||||
yield ();
|
||||
|
||||
5 //~ ERROR mismatched types [E0308]
|
||||
5
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 previous error
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
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`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue