Giter VIP home page Giter VIP logo

Comments (5)

theemathas avatar theemathas commented on August 30, 2024

Here's minimized code that causes a different but similarly confusing error message. Unsure if this still preserves the essence of the original code.

async fn listen() {
    let things: Vec<Vec<i32>> = vec![];
    for _ in things.iter().map(|n| n.iter()).flatten() {
        // comment this line and everything compiles
        async {}.await;
    }
}

fn require_send<T: Send>(_x: T) {}

fn foo() {
    let future = listen();
    require_send(future);
}

Playground link

Error message:

   Compiling playground v0.0.1 (/playground)
error: implementation of `FnOnce` is not general enough
  --> src/lib.rs:13:5
   |
13 |     require_send(future);
   |     ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: closure with signature `fn(&'0 Vec<i32>) -> std::slice::Iter<'_, i32>` must implement `FnOnce<(&'1 Vec<i32>,)>`, for any two lifetimes `'0` and `'1`...
   = note: ...but it actually implements `FnOnce<(&Vec<i32>,)>`

error: could not compile `playground` (lib) due to 1 previous error

from rust.

Kolsky avatar Kolsky commented on August 30, 2024

Both fn iter<T>(v: &Vec<T>) -> Iter<'_, T> { v.iter() } replacing closure and .flat_map(|n| n.iter()) make the code compile. The difference between FlatMap and Flatten is that the first one unifies lifetimes of returned U: IntoIterators, and the other tries to unify Map::<I, F: Fn(_) -> _>::Items, but F isn't higher ranked closure, and as such it fails to do so. Feel free to correct me if I'm wrong.

from rust.

veera-sivarajan avatar veera-sivarajan commented on August 30, 2024

@rustbot label -needs-triage +A-diagnostics +A-Async-Await +A-auto-traits +A-traits +D-confusing

from rust.

theemathas avatar theemathas commented on August 30, 2024

This doesn't use closures and has the same issue.

async fn listen() {
    let things: Vec<Vec<i32>> = vec![];
    for _ in things.iter().map(id).flatten() {
        // comment this line and everything compiles
        async {}.await;
    }
}

fn id<T>(x: T) -> T { x }

fn require_send<T: Send>(_x: T) {}

fn foo() {
    let future = listen();
    require_send(future);
}
   Compiling playground v0.0.1 (/playground)
error: implementation of `FnOnce` is not general enough
  --> src/lib.rs:15:5
   |
15 |     require_send(future);
   |     ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: `fn(&'0 Vec<i32>) -> &'0 Vec<i32> {id::<&'0 Vec<i32>>}` must implement `FnOnce<(&'1 Vec<i32>,)>`, for any two lifetimes `'0` and `'1`...
   = note: ...but it actually implements `FnOnce<(&Vec<i32>,)>`

error: could not compile `playground` (lib) due to 1 previous error

from rust.

traviscross avatar traviscross commented on August 30, 2024

@rustbot labels +AsyncAwait-Triaged

We discussed this in the async meeting today. We think this is probably related to:

from rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.