Skip to content

In presence of impl <T: Trait1> Trait2 for T, when X: Trait2 fails, Rust guides you towards satisfying X: Trait1 instead of X: Trait2 #124802

Open
@GrigorenkoPV

Description

@GrigorenkoPV

Code

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

pub fn parallelize<T>(v: Vec<T>) -> impl ParallelIterator<Item = T>
where
    // T: Send,
{
    v.into_par_iter()
}

Current output

error[E0599]: the method `into_par_iter` exists for struct `Vec<T>`, but its trait bounds were not satisfied
 --> src/lib.rs:7:7
  |
7 |     v.into_par_iter()
  |       ^^^^^^^^^^^^^
  |
  = note: the following trait bounds were not satisfied:
          `[T]: Sized`
          which is required by `[T]: IntoParallelIterator`
          `[T]: ParallelIterator`
          which is required by `[T]: IntoParallelIterator`

warning: unused import: `IntoParallelIterator`
 --> src/lib.rs:1:19
  |
1 | use rayon::iter::{IntoParallelIterator, ParallelIterator};
  |                   ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Desired output

What's really missing is a T: Send bound.

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.79.0-beta.3 (f5d04caa7 2024-05-03)
binary: rustc
commit-hash: f5d04caa74a1dfa5ffc4082c2c8f621f25336bbc
commit-date: 2024-05-03
host: x86_64-unknown-linux-gnu
release: 1.79.0-beta.3
LLVM version: 18.1.4

Anything else?

I will try to provide a MCVE. In the meantime, @rustbot label +E-needs-mcve

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-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