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

implementation of FnOnce is not general enough regressed into closure/generator type that references itself #105396

Closed
cynecx opened this issue Dec 6, 2022 · 4 comments · Fixed by #105409
Assignees
Labels
C-bug Category: This is a bug. P-low Low priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cynecx
Copy link
Contributor

cynecx commented Dec 6, 2022

Code

I tried this code:

use core::future::Future;

trait AsyncFn<I, R>: FnMut(I) -> Self::Fut {
    type Fut: Future<Output = R>;
}

impl<F, I, R, Fut> AsyncFn<I, R> for F
where
    Fut: Future<Output = R>,
    F: FnMut(I) -> Fut,
{
    type Fut = Fut;
}

async fn call<C, R, Fn>(mut ctx: C, mut f: Fn) -> Result<R, ()>
where
    Fn: for<'a> AsyncFn<&'a mut C, Result<R, ()>>,
{
    loop {
        match f(&mut ctx).await {
            Ok(val) => return Ok(val),
            Err(_) => continue,
        }
    }
}

fn test(ctx: &mut usize) {
    call(ctx, |ctx| async move {
        let _ctx = ctx;
        Ok(1usize)
    });
}

I expected to see this happen: rustc produces implementation of `FnOnce` is not general enough

Instead, this happened: rustc produces closure/generator type that references itself

Version it worked on

1.65.0

Version with regression

1.67.0-nightly (2022-12-05 e1d8195)

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

@cynecx cynecx added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Dec 6, 2022
@rustbot rustbot added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed regression-untriaged Untriaged performance or correctness regression. labels Dec 6, 2022
@jruderman
Copy link
Contributor

Regression in nightly-2022-11-05 from 6718ea1 (#101834, @compiler-errors, @lcnr)

Bisect command used
cargo-bisect-rustc --preserve --script ./shout.sh --start 2022-08-01 --end 2022-12-05

with this shout.sh:

! rustc --edition=2021 src/main.rs 2>&1 | grep "that references itself"

@compiler-errors
Copy link
Member

compiler-errors commented Dec 6, 2022

I'm not sure if I'd consider this a regression, since this neither is an error -> non-error, nor a non-error -> error... Certainly this is an interesting consequence of #101834, but we don't expect error messages to remain stable across versions.

@apiraino
Copy link
Contributor

apiraino commented Dec 7, 2022

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-low

@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 7, 2022
@apiraino
Copy link
Contributor

apiraino commented Dec 7, 2022

@rustbot label -I-prioritize +P-low

@apiraino apiraino added P-low Low priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 7, 2022
@bors bors closed this as completed in 03b9e1d Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. P-low Low priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants