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

NARR limbo due to const_evaluatable_unchecked #1

Open
peter-lyons-kehl opened this issue May 15, 2022 · 1 comment
Open

NARR limbo due to const_evaluatable_unchecked #1

peter-lyons-kehl opened this issue May 15, 2022 · 1 comment
Assignees

Comments

@peter-lyons-kehl
Copy link
Contributor

peter-lyons-kehl commented May 15, 2022

Of course, everything here is on Nightly Rust:

warning: cannot use constants which depend on generic parameters in types
   --> src/slices/mod.rs:48:20
    |
48  |         type NARR: $trait_name<'a, T, $narr_size>;
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
    = note: `#[warn(const_evaluatable_unchecked)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

https://github.com/ranging-rs/slicing-rs/blob/main/src/slices/mod.rs#L48=

@peter-lyons-kehl
Copy link
Contributor Author

peter-lyons-kehl commented May 15, 2022

Can't workaround by having an if/else expression in generic bounds:

trait Foo<const N: usize>
where
    [(); if N>0 { N } else {panic!() }]: Sized,
{
    type Narr: Foo<0>;
}

-> overly complex generic constant

Can't workaround with helper const value-generating macros:

/// Used for `NARR` associative types only. Purpose: When `disable_empty_arrays` feature is enabled, this makes `NARR` not be an array with 0 items (which would fail), but with one item.
#[cfg(not(feature = "disable_empty_arrays"))]
macro_rules! non_array_size {
    () => { 0usize };
}
#[cfg(feature = "disable_empty_arrays")]
macro_rules! non_array_size {
    () => { 1usize };
}

//...
// inside the owner trait:
type NARR: $trait_name<'a, T, non_array_size!()>;

Neither helps const:

#[cfg(not(feature = "disable_empty_arrays"))]
const NARR_SIZE: usize = 0;
#[cfg(feature = "disable_empty_arrays")]
const NARR_SIZE: usize = 1;

//...
// inside the owner trait:
type NARR: $trait_name<'a, T, NARR_SIZE>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant