Skip to content

wrong error, confusing traits with rayon ParallelIterator #10822

Closed
@martinxyz

Description

@martinxyz

With the code below, it seems the Iterator trait is wrongly picked over rayon's Paralllelterator, but only in some circumstances. This leads to a wrong error highlight.

  • Happens with master (d3d547abfc) and 2021-10-11-stable
  • All variants compile (tested 2018/2021/nightly/stable)

Dependency: rayon = "1.5"

use rayon::prelude::{IntoParallelIterator, ParallelIterator};

pub fn test() {
    let _result = (0..64)
        .into_par_iter()
        .map(|_| (1, 1, 1)) // changing (1, 1, 1) to (1, 1) or "s" resolves the problem
        // rust-analyzer says this calls fold() of ParalllelIterator (correct)
        .fold(Vec::new, |mut vec, _| {
            vec.push((1, 1)); // - pushing 1 or String::from("a") resolves the problem
                              // - pushing Box::new(1u8) does not resolve it
            vec
        })
        // wrong error here: expected 1 argument, found 2
        // rust-analyzer thinks this calls reduce() on Iterator (incorrect)
        .reduce(Vec::new, |vec1, _vec2| vec1);
    // a type annotation (here or above) resolves the problem
    // let _foo: Vec<_> = _result;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions