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

Confusing error message when trait bound is "satisfied" from different version of same crate #73560

Closed
bugadani opened this issue Jun 20, 2020 · 1 comment
Labels
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. D-crate-version-mismatch Diagnostics: Errors or lints caused be the use of two different crate versions. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bugadani
Copy link
Contributor

bugadani commented Jun 20, 2020

Hi!

I was trying to make the following extension to heapless in my project:

use heapless::spsc::Consumer;
use heapless::spsc::MultiCore;
use generic_array::ArrayLength;
pub trait ConsumerExt {
    fn flush(&mut self);
}

impl<T, N> ConsumerExt for Consumer<'_, T, N, usize, MultiCore>
where
    N: ArrayLength<T>,
{
    fn flush(&mut self) {
        while self.dequeue().is_some() {}
    }
}

In this case, the compatible type is reexported as heapless::ArrayLength;
I now understand that my generic_array::ArrayLength was from a mismatching version of generic_array. Regardless, the error message is extremely confusing:

error[E0277]: the trait bound `N: generic_array::ArrayLength<T>` is not satisfied
  --> src\utils\mod.rs:58:14
   |
58 |     fn flush(&mut self) {
   |              ^^^^^^^^^ the trait `generic_array::ArrayLength<T>` is not implemented for `N`
   | 
  ::: C:\Users\bugad\.cargo\registry\src\github.com-1285ae84e5963aae\heapless-0.5.5\src\spsc\split.rs:35:8
   |
35 |     N: ArrayLength<T>,
   |        -------------- required by this bound in `heapless::spsc::split::Consumer`
   |
help: consider further restricting this bound
   |
56 |     N: ArrayLength<T> + generic_array::ArrayLength<T>,
@jonas-schievink jonas-schievink added 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 20, 2020
@estebank estebank added D-crate-version-mismatch Diagnostics: Errors or lints caused be the use of two different crate versions. D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Jun 20, 2020
@estebank
Copy link
Contributor

Current output in stable mentions the right re-export:

error[E0277]: the trait bound `N: heapless::ArrayLength<T>` is not satisfied
  --> src/main.rs:8:28
   |
8  | impl<T, N> ConsumerExt for Consumer<'_, T, N, usize, MultiCore>
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `heapless::ArrayLength<T>` is not implemented for `N`
   |
note: required by a bound in `Consumer`
  --> /home/gh-estebank/.cargo/registry/src/index.crates.io-6f17d22bba15001f/heapless-0.5.6/src/spsc/split.rs:35:8
   |
33 | pub struct Consumer<'a, T, N, U = usize, C = MultiCore>
   |            -------- required by a bound in this struct
34 | where
35 |     N: ArrayLength<T>,
   |        ^^^^^^^^^^^^^^ required by this bound in `Consumer`
help: consider further restricting this bound
   |
10 |     N: ArrayLength<T> + heapless::ArrayLength<T>,
   |                       ++++++++++++++++++++++++++

error[E0277]: the trait bound `N: heapless::ArrayLength<T>` is not satisfied
  --> src/main.rs:12:19
   |
12 |     fn flush(&mut self) {
   |                   ^^^^ the trait `heapless::ArrayLength<T>` is not implemented for `N`
   |
note: required by a bound in `Consumer`
  --> /home/gh-estebank/.cargo/registry/src/index.crates.io-6f17d22bba15001f/heapless-0.5.6/src/spsc/split.rs:35:8
   |
33 | pub struct Consumer<'a, T, N, U = usize, C = MultiCore>
   |            -------- required by a bound in this struct
34 | where
35 |     N: ArrayLength<T>,
   |        ^^^^^^^^^^^^^^ required by this bound in `Consumer`
help: consider further restricting this bound
   |
10 |     N: ArrayLength<T> + heapless::ArrayLength<T>,
   |                       ++++++++++++++++++++++++++

error[E0599]: the method `dequeue` exists for mutable reference `&mut Consumer<'_, T, N>`, but its trait bounds were not satisfied
  --> src/main.rs:13:20
   |
13 |         while self.dequeue().is_some() {}
   |                    ^^^^^^^ method cannot be called on `&mut Consumer<'_, T, N>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `N: heapless::ArrayLength<T>`

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-crate-version-mismatch Diagnostics: Errors or lints caused be the use of two different crate versions. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants