Skip to content

Const generics, the trait bound is not satisfied #68385

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

Closed
tamasfe opened this issue Jan 20, 2020 · 2 comments
Closed

Const generics, the trait bound is not satisfied #68385

tamasfe opened this issue Jan 20, 2020 · 2 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tamasfe
Copy link
Contributor

tamasfe commented Jan 20, 2020

I would expect the following code to work with different const values just as it does with different types:

trait Trait<const PARAM: &'static str> {
    fn do_stuff(&self);
}

struct Struct;

impl Trait<"param"> for Struct {
    fn do_stuff(&self) {}
}

impl Trait<"another_param"> for Struct {
    fn do_stuff(&self) {}
}

fn stuff() {
    let s = Struct;

    <Struct as Trait<"param">>::do_stuff(&s);
}

However it fails with:

the trait bound `Struct: Trait<"param">` is not satisfied
the following implementations were found:
  <Struct as Trait<"another_param">>
  <Struct as Trait<"param">> rustc(E0277)

If implemented with only one value, the compiler infers it correctly (universal function call still doesn't work however), also adding brackets anywhere makes no difference.

rustc 1.40.0-nightly (4a8c5b20c 2019-10-23)
binary: rustc
commit-hash: 4a8c5b20c7772bc5342b83d4b0696ea216ef75a7
commit-date: 2019-10-23
host: x86_64-unknown-linux-gnu
release: 1.40.0-nightly
LLVM version: 9.0
@Centril Centril added F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 20, 2020
@varkor
Copy link
Member

varkor commented Apr 8, 2020

This now appears to be working.

@varkor varkor added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. A-const-generics Area: const generics (parameters and arguments) labels Apr 8, 2020
@varkor
Copy link
Member

varkor commented Apr 8, 2020

Closing as a duplicate of #66596.

@varkor varkor closed this as completed Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. 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