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

Complaint about trait not being implemented #61935

Closed
est31 opened this issue Jun 18, 2019 · 12 comments
Closed

Complaint about trait not being implemented #61935

est31 opened this issue Jun 18, 2019 · 12 comments
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. 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

@est31
Copy link
Member

est31 commented Jun 18, 2019

Rustc complains about the trait not being implemented for [(); _], but actually it's given a [(); 1] literal and for that one, the trait is implemented. Turbofishing foo::<[(); 0]>([]) doesn't help.

cc @varkor @rodrimati1992

see also #61383

Code ↓

#![feature(const_generics)]
trait Foo {}

impl<const N: usize> Foo for [(); N]
where
    Self:FooImpl<{N==0}>
{}

trait FooImpl<const IS_ZERO: bool>{}

impl FooImpl<{0u8==0u8}> for [();0] {}

impl<const N:usize> FooImpl<{0u8!=0u8}> for [();N] {}

fn foo<T: Foo>(v: T) {}

fn main() {
    foo([]);
    foo([()]);
}

Error ↓

error[E0277]: the trait bound `[(); _]: FooImpl<{N==0}>` is not satisfied
  --> src/lib.rs:18:5
   |
18 |     foo([]);
   |     ^^^ the trait `FooImpl<{N==0}>` is not implemented for `[(); _]`
   |
   = help: the following implementations were found:
             <[(); 0] as FooImpl<true>>
             <[(); _] as FooImpl<false>>
   = note: required because of the requirements on the impl of `Foo` for `[(); 0]`
note: required by `foo`
  --> src/lib.rs:15:1
   |
15 | fn foo<T: Foo>(v: T) {}
   | ^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `[(); _]: FooImpl<{N==0}>` is not satisfied
  --> src/lib.rs:19:5
   |
19 |     foo([()]);
   |     ^^^ the trait `FooImpl<{N==0}>` is not implemented for `[(); _]`
   |
   = help: the following implementations were found:
             <[(); 0] as FooImpl<true>>
             <[(); _] as FooImpl<false>>
   = note: required because of the requirements on the impl of `Foo` for `[(); 1]`
note: required by `foo`
  --> src/lib.rs:15:1
   |
15 | fn foo<T: Foo>(v: T) {}
   | ^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 18, 2019
@Centril Centril added F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. labels Aug 6, 2019
@est31
Copy link
Member Author

est31 commented Aug 28, 2019

Checking this example again gives me an ICE similar to #62879.

@est31
Copy link
Member Author

est31 commented Dec 5, 2019

ICE has been downgraded to an error since: #62879 (comment)

@varkor varkor added the A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) label Jan 6, 2020
@Dylan-DPC-zz
Copy link

The error is now:

error[E0391]: cycle detected when const-evaluating + checking `<impl at src/main.rs:4:1: 7:3>::{{constant}}#0`
 --> src/main.rs:6:18
  |
6 |     Self:FooImpl<{N==0}>
  |                  ^^^^^^
  |
note: ...which requires const-evaluating + checking `<impl at src/main.rs:4:1: 7:3>::{{constant}}#0`...
 --> src/main.rs:6:18
  |
6 |     Self:FooImpl<{N==0}>
  |                  ^^^^^^
note: ...which requires const-evaluating `<impl at src/main.rs:4:1: 7:3>::{{constant}}#0`...
 --> src/main.rs:6:18
  |
6 |     Self:FooImpl<{N==0}>
  |                  ^^^^^^
note: ...which requires type-checking `<impl at src/main.rs:4:1: 7:3>::{{constant}}#0`...
 --> src/main.rs:6:18
  |
6 |     Self:FooImpl<{N==0}>
  |                  ^^^^^^
note: ...which requires processing `<impl at src/main.rs:4:1: 7:3>::{{constant}}#0`...
 --> src/main.rs:6:18
  |
6 |     Self:FooImpl<{N==0}>
  |                  ^^^^^^
  = note: ...which again requires const-evaluating + checking `<impl at src/main.rs:4:1: 7:3>::{{constant}}#0`, completing the cycle
note: cycle used when processing `<impl at src/main.rs:4:1: 7:3>`
 --> src/main.rs:4:1
  |
4 | / impl<const N: usize> Foo for [(); N]
5 | | where
6 | |     Self:FooImpl<{N==0}>
7 | | {}
  | |__^

error: aborting due to previous error

@est31
Copy link
Member Author

est31 commented Mar 28, 2020

@Dylan-DPC yeah also see the comment above yours as well as eddyb's reply in that thread.

@Dylan-DPC-zz
Copy link

@est31 i'm aware was just updating so it is easier to check with later

@est31
Copy link
Member Author

est31 commented May 30, 2020

Due to this reddit post I tested it again and now the compile error is gone. Good job guys and girls!

@est31 est31 closed this as completed May 30, 2020
@varkor
Copy link
Member

varkor commented May 30, 2020

Let's make sure we add a regression test.

@varkor varkor reopened this May 30, 2020
@varkor varkor added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels May 30, 2020
@est31
Copy link
Member Author

est31 commented Jun 11, 2020

Now there's a different error:

error: constant expression depends on a generic parameter
 --> src/main.rs:6:10
  |
6 |     Self:FooImpl<{N==0}>
  |          ^^^^^^^^^^^^^^^
  |
  = note: this may fail depending on what value the parameter takes

@lcnr
Copy link
Contributor

lcnr commented Jun 30, 2020

This error is expected fallout of #70107

We also already have a regression test for some reason 😅
https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/issues/issue-61935.rs

@lcnr lcnr closed this as completed Jun 30, 2020
@est31
Copy link
Member Author

est31 commented Jun 30, 2020

@lcnr is there an issue that tracks the fallout of that PR? I'd like the code I posted to work so I'm curious.

@lcnr
Copy link
Contributor

lcnr commented Jun 30, 2020

Not really, it might be a good idea to open an issue for this though 🤔

#![feature(const_generics)]
fn foo<const B: bool>() {}

fn bar<const N: usize>() {
    foo::<{ N == 0 }>();
}

I am not really sure how much design + implementation is still needed here, so
I can't give you a good estimate on when we will be able to soundly enable this again.

@est31
Copy link
Member Author

est31 commented Jun 30, 2020

Filed an issue: #73899

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jul 1, 2020
remove duplicate test for rust-lang#61935

Apparently I somehow messed up the issue number in rust-lang#67890
which caused us to add this test twice, both as https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/issues/issue-61935.rs and https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/lazy-normalization/issue-71922.rs

rust-lang#61935 is the actually fixed issue while rust-lang#71922 is still not working, as it depends on lazy norm of repeat expressions
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 1, 2020
remove duplicate test for rust-lang#61935

Apparently I somehow messed up the issue number in rust-lang#67890
which caused us to add this test twice, both as https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/issues/issue-61935.rs and https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/lazy-normalization/issue-71922.rs

rust-lang#61935 is the actually fixed issue while rust-lang#71922 is still not working, as it depends on lazy norm of repeat expressions
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 2, 2020
remove duplicate test for rust-lang#61935

Apparently I somehow messed up the issue number in rust-lang#67890
which caused us to add this test twice, both as https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/issues/issue-61935.rs and https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/lazy-normalization/issue-71922.rs

rust-lang#61935 is the actually fixed issue while rust-lang#71922 is still not working, as it depends on lazy norm of repeat expressions
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 2, 2020
remove duplicate test for rust-lang#61935

Apparently I somehow messed up the issue number in rust-lang#67890
which caused us to add this test twice, both as https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/issues/issue-61935.rs and https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/lazy-normalization/issue-71922.rs

rust-lang#61935 is the actually fixed issue while rust-lang#71922 is still not working, as it depends on lazy norm of repeat expressions
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 2, 2020
remove duplicate test for rust-lang#61935

Apparently I somehow messed up the issue number in rust-lang#67890
which caused us to add this test twice, both as https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/issues/issue-61935.rs and https://github.com/rust-lang/rust/blob/master/src/test/ui/const-generics/lazy-normalization/issue-71922.rs

rust-lang#61935 is the actually fixed issue while rust-lang#71922 is still not working, as it depends on lazy norm of repeat expressions
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 2, 2020
…arth

Rollup of 16 pull requests

Successful merges:

 - rust-lang#72569 (Remove legacy InnoSetup GUI installer)
 - rust-lang#73306 (Don't implement Fn* traits for #[target_feature] functions)
 - rust-lang#73345 (expand: Stop using nonterminals for passing tokens to attribute and derive macros)
 - rust-lang#73449 (Provide more information on duplicate lang item error.)
 - rust-lang#73569 (Handle `macro_rules!` tokens consistently across crates)
 - rust-lang#73803 (Recover extra trailing angle brackets in struct definition)
 - rust-lang#73839 (Split and expand nonstandard-style lints unicode unit test.)
 - rust-lang#73841 (Remove defunct `-Z print-region-graph`)
 - rust-lang#73848 (Fix markdown rendering in librustc_lexer docs)
 - rust-lang#73865 (Fix Zulip topic format)
 - rust-lang#73892 (Clean up E0712 explanation)
 - rust-lang#73898 (remove duplicate test for rust-lang#61935)
 - rust-lang#73906 (Add missing backtick in `ty_error_with_message`)
 - rust-lang#73909 (`#[deny(unsafe_op_in_unsafe_fn)]` in libstd/fs.rs)
 - rust-lang#73910 (Rewrite a few manual index loops with while-let)
 - rust-lang#73929 (Fix comment typo)

Failed merges:

r? @ghost
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) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. 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

6 participants