Skip to content

Non-static generators should always be unpin #16

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

Closed
compiler-errors opened this issue Mar 29, 2023 · 1 comment · Fixed by rust-lang/rust#110207
Closed

Non-static generators should always be unpin #16

compiler-errors opened this issue Mar 29, 2023 · 1 comment · Fixed by rust-lang/rust#110207
Labels
has-fix A fix is up

Comments

@compiler-errors
Copy link
Owner

#![feature(generators, generator_trait)]

use std::marker::{PhantomPinned, Unpin};

fn assert_unpin<G: Unpin>(_: G) {
}

fn main() {
    // Even though this generator holds a `PhantomPinned` in its environment, it
    // remains `Unpin`.
    assert_unpin(|| {
        let pinned = PhantomPinned;
        yield;
        drop(pinned);
    });
}

Just needs special logic added to builtin impls.

@compiler-errors compiler-errors added the needs-fix An easy fix needs to be put up and applied label Mar 29, 2023
@compiler-errors
Copy link
Owner Author

compiler-errors commented Mar 29, 2023

Conversely:

use std::marker::Unpin;

fn assert_unpin<T: Unpin>(_: T) {
}

fn main() {
    let mut generator = static || {
        yield;
    };
    assert_unpin(generator); //~ ERROR E0277
}

passes but it should not.

@compiler-errors compiler-errors changed the title Non-static generators are always unpin Non-static generators should always be unpin Mar 30, 2023
@compiler-errors compiler-errors added has-fix A fix is up and removed needs-fix An easy fix needs to be put up and applied labels Apr 12, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 14, 2023
…r=lcnr

Assemble `Unpin` candidates specially for generators in new solver

Fixes compiler-errors/next-solver-hir-issues#16

r? `@lcnr`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 14, 2023
…r=lcnr

Assemble `Unpin` candidates specially for generators in new solver

Fixes compiler-errors/next-solver-hir-issues#16

r? ``@lcnr``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-fix A fix is up
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant