Skip to content

Failure to unify the generic regions in closure #129787

Closed
@dingxiangfei2009

Description

@dingxiangfei2009

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions