Skip to content

Compilation error E0207 for impl for another const generic trait #100405

Open
@tats-u

Description

@tats-u

Given the following code:

pub trait ExtraFieldHeader {
    fn header_id(&self) -> u16;
}

pub trait FixedIDZIPExtraField<const ID: u16> {
    const HEADER_ID: u16 = ID;
    /// Gets header ID (Unique for each type of extra fields)
    fn header_id(&self) -> u16 {
        Self::HEADER_ID
    }
}

impl<T, const ID: u16> ExtraFieldHeader for T where T: FixedIDZIPExtraField<ID> {}

The current output is:

error[E0207]: the const parameter `ID` is not constrained by the impl trait, self type, or predicates
  --> src\zip_extra_field.rs:27:9
   |
27 | impl<T, const ID: u16> ExtraFieldHeader for T where T: FixedIDZIPExtraField<ID> {}
   |         ^^^^^^^^^^^^^ unconstrained const parameter
   |
   = note: expressions using a const parameter must map each value to a distinct output value
   = note: proving the result of expressions other than the parameter are unique is not supported

Ideally the output should look like:

(no errors)

I believe ID is constrained for FiexedIDZIPExtraField<ID> and this error must not be raised. Could someone provide a solution?

rustc --version
rustc 1.62.1 (e092d0b6b 2022-07-16)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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