Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug. Get doubled error message with impl_trait_in_bindings when no error must be #70997

Closed
DustinByfuglien opened this issue Apr 10, 2020 · 6 comments
Labels
A-coroutines Area: Coroutines A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. F-coroutines `#![feature(coroutines)]` F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` P-low Low priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DustinByfuglien
Copy link

DustinByfuglien commented Apr 10, 2020

This example compiling with error message. And it's not obvious:

  1. what cycle is this message about?
  2. why this error is doubled in output?
  3. why error is at all? It seems no error must be.
#![feature(generator_trait)]
#![feature(generators)]
#![allow(incomplete_features)]
#![feature(impl_trait_in_bindings)]

use std::ops::Generator;

fn main() {
    let mut gen: impl Generator =
        || {
            yield;
        };
    std::pin::Pin::new(&mut gen).resume(());
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0391]: cycle detected when processing `main::{{opaque}}#0`
  --> src/main.rs:9:18
   |
9  |     let mut gen: impl Generator =
   |                  ^^^^^^^^^^^^^^
   |
note: ...which requires type-checking `main`...
  --> src/main.rs:8:1
   |
8  | fn main() {
   | ^^^^^^^^^
   = note: ...which requires evaluating trait selection obligation `impl std::ops::Generator: std::marker::Unpin`...
   = note: ...which again requires processing `main::{{opaque}}#0`, completing the cycle
note: cycle used when checking item types in top-level module
  --> src/main.rs:1:1
   |
1  | / #![feature(generator_trait)]
2  | | #![feature(generators)]
3  | | #![allow(incomplete_features)]
4  | | #![feature(impl_trait_in_bindings)]
...  |
13 | |     std::pin::Pin::new(&mut gen).resume(());
14 | | }
   | |_^

error[E0391]: cycle detected when processing `main::{{opaque}}#0`
  --> src/main.rs:9:18
   |
9  |     let mut gen: impl Generator =
   |                  ^^^^^^^^^^^^^^
   |
note: ...which requires type-checking `main`...
  --> src/main.rs:8:1
   |
8  | fn main() {
   | ^^^^^^^^^
   = note: ...which again requires processing `main::{{opaque}}#0`, completing the cycle
note: cycle used when checking item types in top-level module
  --> src/main.rs:1:1
   |
1  | / #![feature(generator_trait)]
2  | | #![feature(generators)]
3  | | #![allow(incomplete_features)]
4  | | #![feature(impl_trait_in_bindings)]
...  |
13 | |     std::pin::Pin::new(&mut gen).resume(());
14 | | }
   | |_^

error: aborting due to 2 previous errors

May be must tracked by #63065

@Centril Centril added requires-nightly This issue requires a nightly compiler in some way. A-diagnostics Area: Messages for errors, warnings, and lints F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. F-coroutines `#![feature(coroutines)]` A-coroutines Area: Coroutines A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. labels Apr 10, 2020
@DustinByfuglien
Copy link
Author

Compiler generate error when no error must be.
Woud I propose to add a "C-bug" label?

@eddyb
Copy link
Member

eddyb commented Apr 12, 2020

@DustinByfuglien This is not a bug, but the error doesn't tell you how to fix it
This is the important part:

evaluating trait selection obligation `impl std::ops::Generator: std::marker::Unpin`

You have to write write impl Generator + Unpin if you want to use Pin::new, otherwise the compiler tries to figure it out on the spot and ends up in a cyclic dependency during type-checking.

@DustinByfuglien
Copy link
Author

Thank you.
But what difference is with next example that successfully compiles?

#![feature(generator_trait)]
#![feature(generators)]

use std::ops::Generator;

fn f()-> impl Generator {
    || {
        yield;
    }
}

fn main() {
    std::pin::Pin::new(&mut f()).resume(());
}

(Playground)

@eddyb
Copy link
Member

eddyb commented Apr 13, 2020

@DustinByfuglien Generators, like closures, have type-checking/inference done at the same time as the parent function. By moving the generator into a separate function, you break the cycle as f can be completely type-checked/inferred before main finishes type-checking.

@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Apr 19, 2020
@estebank
Copy link
Contributor

Triage: the error still emits, but it is no longer duplicated.

@kpreid
Copy link
Contributor

kpreid commented Jul 11, 2024

This could probably be closed, because the implementation of impl_trait_in_bindings was removed by #86729.

@oli-obk oli-obk closed this as completed Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coroutines Area: Coroutines A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. F-coroutines `#![feature(coroutines)]` F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` P-low Low priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants