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

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

Open
tats-u opened this issue Aug 11, 2022 · 8 comments
Open

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

tats-u opened this issue Aug 11, 2022 · 8 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tats-u
Copy link

tats-u commented Aug 11, 2022

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)
@tats-u tats-u added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 11, 2022
@tats-u tats-u changed the title Compilation error for impl for another const generic trait Compilation error E0207 for impl for another const generic trait Aug 11, 2022
@tats-u
Copy link
Author

tats-u commented Aug 11, 2022

Seems to be similar to #100405

@compiler-errors
Copy link
Member

@tats-u did you mean to link another issue?

@tats-u
Copy link
Author

tats-u commented Aug 14, 2022

@compiler-errors I just thought this is similar to that issue.
Do you think this is duplicated?

@compiler-errors
Copy link
Member

You said that this issue (#100405) is similar to issue #100405... which is this one?

@tats-u
Copy link
Author

tats-u commented Aug 14, 2022

@compiler-errors Sorry, I thought I copied and pasted another issue...

@tats-u
Copy link
Author

tats-u commented Aug 14, 2022

What I have wanted to mention are #68366 or #81985.

@aDogCalledSpot
Copy link

This doesn't appear to be unique to const generics:

trait Foo<T> {}

impl<T, U: Foo<T>> Drop for U {
    fn drop(&mut self) {
        println!("hello");
    }
}

leads to:

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
 --> src/main.rs:3:6
  |
3 | impl<T, U: Foo<T>> Drop for U {
  |      ^ unconstrained type parameter

For more information about this error, try `rustc --explain E0207`.

Using rustc 1.67.0-nightly (53e4b9dd7 2022-12-04).

@BaxHugh
Copy link

BaxHugh commented Aug 11, 2023

I've also got this problem, has any progress been made with this?

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

4 participants