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

Error message does not list the relevant trait bounds that were not satisfied #68131

Closed
sunjay opened this issue Jan 11, 2020 · 2 comments · Fixed by #69255
Closed

Error message does not list the relevant trait bounds that were not satisfied #68131

sunjay opened this issue Jan 11, 2020 · 2 comments · Fixed by #69255
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sunjay
Copy link
Member

sunjay commented Jan 11, 2020

I don't know for sure, but this feels like an interaction between method dispatch, deref, and possibly Send.

Here's a fairly minimal reproduction of the issue: (Playground)

use std::rc::Rc;

use rayon::prelude::*;

fn main() {
    let x = vec![Rc::new(12)];
    
    let y: Vec<_> = x.into_par_iter().collect();
}

The error message in question:

error[E0599]: no method named `into_par_iter` found for type `std::vec::Vec<std::rc::Rc<{integer}>>` in the current scope
 --> src/main.rs:8:23
  |
8 |     let y: Vec<_> = x.into_par_iter().collect();
  |                       ^^^^^^^^^^^^^ method not found in `std::vec::Vec<std::rc::Rc<{integer}>>`
  |
  = note: the method `into_par_iter` exists but the following trait bounds were not satisfied:
          `[std::rc::Rc<{integer}>] : rayon::iter::IntoParallelIterator`

The type of x is Vec<Rc<i32>>. Rayon has an impl with the following signature:

impl<T: Send> IntoParallelIterator for Vec<T> { ... }

The problem here is that Vec<Rc<i32>>: IntoParallelIterator is not satisfied because Rc<i32>: Send is not satisfied.

Because Vec<Rc<i32>> derefs to [Rc<i32>], the error message lists that as the trait bound to be satisfied. This is very unhelpful because there is no way you could ever satisfy that constraint.

While fixing the message to also list Vec<Rc<i32>> in addition to [Rc<i32>] would be helpful, it doesn't help solve the actual problem which is that Rc<i32> is not Send. The code I initially ran into this with had an Rc about ~15 structs down, so it was not obvious at all what the problem was until I looked at the relevant impl in the rayon docs and added the following to my code:

fn foo<T: Send>() {}
foo::<MyType>();

Once I did that, I got a full error message that nicely lists the entire stack of obligations that led to Send not being fulfilled.

It would be very helpful if the compiler could tell me that Rc<i32>: Send is not satisfied so I could skip all of those steps. (Rc<i32>: Send in my minimal example, MyType: Send in actual code)

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-trait-system Area: Trait system labels Jan 11, 2020
@95th
Copy link
Contributor

95th commented Jan 12, 2020

When I used rayon for the first time, I ran into this problem too many times. I was thinking that some feature flags must be missing or rayon doesn't work.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 27, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 28, 2020
@bors bors closed this as completed in 55aee8d Feb 29, 2020
@sowbug
Copy link

sowbug commented Apr 12, 2023

@sunjay thank you for this code snippet:

fn foo<T: Send>() {}
foo::<MyType>();

I'm exactly where you were three years ago -- searching for the nested struct that isn't Send or Sync to satisfy rayon -- and this has proven invaluable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system 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

Successfully merging a pull request may close this issue.

4 participants