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

Failure to unify the generic regions in closure #129787

Closed
dingxiangfei2009 opened this issue Aug 30, 2024 · 5 comments
Closed

Failure to unify the generic regions in closure #129787

dingxiangfei2009 opened this issue Aug 30, 2024 · 5 comments
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dingxiangfei2009
Copy link
Contributor

dingxiangfei2009 commented Aug 30, 2024

I tried this code:

//@ edition: 2021
use futures::StreamExt; # futures: 0.3.30
use std::future::Future;

fn f() -> impl Future<Output = ()> + Send {
    async {
        let data: &[_] = &[0u8];
        futures::stream::iter([data])
            .map(|data| async {})
            .buffer_unordered(4)
            .for_each_concurrent(4, |_| async {})
            .await;
    }
}

I expected to see this happen: check-pass

Instead, this happened: check-failed

warning: unused variable: `data`
 --> src/lib.rs:8:19
  |
8 |             .map(|data| async {})
  |                   ^^^^ help: if this is intentional, prefix it with an underscore: `_data`
  |
  = note: `#[warn(unused_variables)]` on by default

error: implementation of `FnOnce` is not general enough
  --> src/lib.rs:5:5
   |
5  | /     async {
6  | |         let data: &[_] = &[0u8];
7  | |         futures::stream::iter([data])
8  | |             .map(|data| async {})
...  |
11 | |             .await;
12 | |     }
   | |_____^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'0 [u8]) -> {async block@src/lib.rs:8:25: 8:33}` must implement `FnOnce<(&'1 [u8],)>`, for any two lifetimes `'0` and `'1`...
   = note: ...but it actually implements `FnOnce<(&[u8],)>`

Meta

This is happening on 1.80.1

rustc --version --verbose:

rustc 1.80.1 (3f5fd8dd4 2024-08-06)
Backtrace

N/A

@dingxiangfei2009 dingxiangfei2009 added the C-bug Category: This is a bug. label Aug 30, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 30, 2024
@compiler-errors
Copy link
Member

FnOnce is a supertrait of FnMut, so ignore the name of the exact trait. The real issue here is just a higher-ranked closure problem.

@dingxiangfei2009 dingxiangfei2009 changed the title Weird Fn flavour inference result and failure to unify the generic regions in closure Failure to unify the generic regions in closure Aug 30, 2024
@compiler-errors
Copy link
Member

This is just another #110338

@dingxiangfei2009
Copy link
Contributor Author

@compiler-errors you means it is a duplicate of #114177 specifically?

@compiler-errors
Copy link
Member

Yes, it's probably a duplicate of that one.

@dingxiangfei2009
Copy link
Contributor Author

I am closing as duplicate. Cheers! I will follow up with a reduction over there.

@saethlin saethlin added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 31, 2024
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. 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

4 participants