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

"trait not implemented" errors can be very confusing when the trait has an associated type with bounds #61768

Closed
jplatte opened this issue Jun 12, 2019 · 0 comments · Fixed by #69255
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jplatte
Copy link
Contributor

jplatte commented Jun 12, 2019

Simple example using rayon (playground):

use rayon::prelude::*;

fn main() {
    let v: Vec<*const usize> = Vec::new();

    v.par_iter();
    (&v).into_par_iter();
    <Vec<*const usize> as IntoParallelRefMutIterator>::par_iter(&v);
    <&Vec<*const usize> as IntoParallelIterator>::into_par_iter(&v);
}

This code rightly doesn't compile because rayons IntoParallelIterator has a Send bound on its Item type. However, none of the error messages for the methods called in the code above ever mention that bound or the associated type:

error[E0576]: cannot find method or associated constant `par_iter` in trait `IntoParallelRefMutIterator`
 --> src/lib.rs:8:56
  |
8 |     <Vec<*const usize> as IntoParallelRefMutIterator>::par_iter(&v);
  |                                                        ^^^^^^^^ not found in `IntoParallelRefMutIterator`

error[E0599]: no method named `par_iter` found for type `std::vec::Vec<*const usize>` in the current scope
 --> src/lib.rs:6:7
  |
6 |     v.par_iter();
  |       ^^^^^^^^
  |
  = note: the method `par_iter` exists but the following trait bounds were not satisfied:
          `[*const usize] : rayon::iter::IntoParallelRefIterator`
          `std::vec::Vec<*const usize> : rayon::iter::IntoParallelRefIterator`

error[E0599]: no method named `into_par_iter` found for type `&std::vec::Vec<*const usize>` in the current scope
 --> src/lib.rs:7:10
  |
7 |     (&v).into_par_iter();
  |          ^^^^^^^^^^^^^
  |
  = note: the method `into_par_iter` exists but the following trait bounds were not satisfied:
          `&&std::vec::Vec<*const usize> : rayon::iter::IntoParallelIterator`
          `&mut &std::vec::Vec<*const usize> : rayon::iter::IntoParallelIterator`
          `[*const usize] : rayon::iter::IntoParallelIterator`

error[E0277]: the trait bound `&std::vec::Vec<*const usize>: rayon::iter::IntoParallelIterator` is not satisfied
 --> src/lib.rs:9:5
  |
9 |     <&Vec<*const usize> as IntoParallelIterator>::into_par_iter(&v);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `rayon::iter::IntoParallelIterator` is not implemented for `&std::vec::Vec<*const usize>`
  |
  = help: the following implementations were found:
            <&'data mut std::vec::Vec<T> as rayon::iter::IntoParallelIterator>
            <&'data std::vec::Vec<T> as rayon::iter::IntoParallelIterator>
            <std::vec::Vec<T> as rayon::iter::IntoParallelIterator>
@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 12, 2019
@estebank estebank added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Oct 7, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. 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.

3 participants