Skip to content

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

Closed
@bugadani

Description

@bugadani

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>,

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-crate-version-mismatchDiagnostics: Errors or lints caused be the use of two different crate versions.T-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