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

Error reporting bug with const_generics and const_evaluatable_checked #82959

Closed
AuroransSolis opened this issue Mar 10, 2021 · 1 comment
Closed
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]`

Comments

@AuroransSolis
Copy link

Issue three of three I'll be filing tonight.

This is the code that causes the bug:

#![feature(const_generics, const_evaluatable_checked, array_map)]

pub struct ConstCheck<const CHECK: bool>;

pub trait True {}
impl True for ConstCheck<true> {}

pub trait OrdesDec {
    type Newlen;
    type Output;

    fn pop(self) -> (Self::Newlen, Self::Output);
}

impl<T, const N: usize> OrdesDec for [T; N]
where
    ConstCheck<{N > 1}>: True,
    ConstCheck<{N - 1 != 0}>: True,
{
    type Newlen = [T; N - 1];
    type Output = T;

    fn pop(self) -> (Self::Newlen, Self::Output) {
        let mut iter = IntoIter::new(self);
        let end = iter.next_back().unwrap();
        let new = [(); N - 1].map(move |()| iter.next().unwrap());
        (new, end)
    }
}

I don't remember why I tried this, but I did. And the error messages I got on it were wild:

error[E0283]: type annotations needed
  --> src/nightly_arr.rs:24:28
   |
6  | pub trait True {}
   | -------------- required by this bound in `True`
...
24 |     ConstCheck<{ N > 1 }>: True,
   |                            ^^^^ cannot infer type for struct `ConstCheck<{ N > 1 }>`
   |
   = note: cannot satisfy `ConstCheck<{ N > 1 }>: True`

error[E0283]: type annotations needed
  --> src/nightly_arr.rs:28:5
   |
24 |     ConstCheck<{ N > 1 }>: True,
   |                            ---- required by this bound in `nightly_arr::<impl OrdesDec for [T; N]>`
...
28 |     type Newlen = [T; N - 1];
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for struct `ConstCheck<{ N > 1 }>`
   |
   = note: cannot satisfy `ConstCheck<{ N > 1 }>: True`
help: consider specifying the type arguments in the function call
   |
28 |     type Newlen = [T; N - 1];::<T, N>
   |                              ^^^^^^^^

error[E0283]: type annotations needed
  --> src/nightly_arr.rs:31:5
   |
31 | /     fn pop(self) -> (Self::Newlen, Self::Output) {
32 | |         let mut iter = IntoIter::new(self);
33 | |         let end = iter.next_back().unwrap();
34 | |         let new = [(); N - 1].map(move |()| iter.next().unwrap());
35 | |         (new, end)
36 | |     }
   | |_____^ cannot infer type for struct `ConstCheck<{ N > 1 }>`
   |
   = note: cannot satisfy `ConstCheck<{ N > 1 }>: True`
   = note: required because of the requirements on the impl of `OrdesDec` for `[T; N]`

error: aborting due to 3 previous errors

Now you're probably thinking to yourself, "Hey Auro, isn't that exactly the same code as in #82956? Oh, and #82957? And isn't it silly to pull the same dumb gag twice?" To answer the last question: yes, definitely. To answer the other two: no, not quite. Check out the constraints on the OrdesDec impl: [T; N - 1]: Sized has been swapped out for ConstCheck<{N - 1 != 0}>: True. I don't even know what's going on in those error messages, if I'm honest. They confuse me.

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (35dbef235 2021-03-02)
binary: rustc
commit-hash: 35dbef235048f9a2939dc20effe083ca483c37ff
commit-date: 2021-03-02
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1
@AuroransSolis AuroransSolis added the C-bug Category: This is a bug. label Mar 10, 2021
@BoxyUwU BoxyUwU added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Sep 2, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 24, 2022

This compiles fine now with self.into_iter()/std::array::IntoIter::new(self). with IntoIter::new(self) it gives an error from not having IntoIter imported:

error[[E0433]](https://doc.rust-lang.org/nightly/error-index.html#E0433): failed to resolve: use of undeclared type `IntoIter`
  --> src/lib.rs:24:24
   |
24 |         let mut iter = IntoIter::new(self);
   |                        ^^^^^^^^ not found in this scope
   |
help: consider importing one of these items
   |
3  | [use arrayvec::IntoIter;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018#)
   |
3  | [use bit_vec::IntoIter;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018#)
   |
3  | [use bytes::buf::IntoIter;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018#)
   |
3  | [use core::array::IntoIter;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018#)
   |
     and 58 other candidates

@BoxyUwU BoxyUwU closed this as completed Jun 24, 2022
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. F-generic_const_exprs `#![feature(generic_const_exprs)]`
Projects
None yet
Development

No branches or pull requests

2 participants