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

Open
DustinByfuglien opened this issue Apr 10, 2020 · 5 comments
Labels
A-diagnostics A-generators A-impl-trait C-enhancement D-verbose F-generators F-impl_trait_in_bindings P-low requires-nightly T-compiler

Comments

@DustinByfuglien
Copy link

@DustinByfuglien 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 A-diagnostics F-impl_trait_in_bindings P-low T-compiler D-verbose F-generators A-generators A-impl-trait labels Apr 10, 2020
@DustinByfuglien
Copy link
Author

@DustinByfuglien DustinByfuglien commented Apr 11, 2020

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

@eddyb
Copy link
Member

@eddyb 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

@DustinByfuglien DustinByfuglien commented Apr 13, 2020

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 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 label Apr 19, 2020
@estebank
Copy link
Contributor

@estebank estebank commented Feb 18, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics A-generators A-impl-trait C-enhancement D-verbose F-generators F-impl_trait_in_bindings P-low requires-nightly T-compiler
Projects
None yet
Development

No branches or pull requests

5 participants