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

Can't use generic_const_exprs #416

Open
yyy33 opened this issue Apr 16, 2024 · 1 comment
Open

Can't use generic_const_exprs #416

yyy33 opened this issue Apr 16, 2024 · 1 comment
Labels
C-bug Category: Bug

Comments

@yyy33
Copy link

yyy33 commented Apr 16, 2024

I tried this code:

#![feature(generic_const_exprs)]
#![feature(portable_simd)]

use target_features::CURRENT_TARGET;
use std::simd::Simd;

fn main() {}

struct BitVec<const BIT_LEN: usize> 
where [(); { inline_unit_len(BIT_LEN) }]:
{
    inline: Simd<u8, { inline_unit_len(BIT_LEN) }>,
}

type Lane = usize;

const fn inline_unit_len(bit_len: usize) -> usize {
    8
}

I expected to see this happen: No compilation error

Instead, this happened: * compilation error*

❯ cargo run --
   Compiling test44 v0.1.0 (/home/yyy/test44)
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
    --> src/main.rs:1766:12
     |
1766 | #![feature(generic_const_exprs)]
     |            ^^^^^^^^^^^^^^^^^^^
     |
     = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
     = note: `#[warn(incomplete_features)]` on by default

warning: unused import: `target_features::CURRENT_TARGET`
    --> src/main.rs:1769:5
     |
1769 | use target_features::CURRENT_TARGET;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: `#[warn(unused_imports)]` on by default

warning: unnecessary braces around const expression
    --> src/main.rs:1775:12
     |
1775 | where [(); { inline_unit_len(BIT_LEN) }]:
     |            ^^                        ^^
     |
     = note: `#[warn(unused_braces)]` on by default
help: remove these braces
     |
1775 - where [(); { inline_unit_len(BIT_LEN) }]:
1775 + where [(); inline_unit_len(BIT_LEN)]:
     |

error[E0277]: the trait bound `LaneCount<{ inline_unit_len(BIT_LEN) }>: SupportedLaneCount` is not satisfied
    --> src/main.rs:1777:13
     |
1777 |     inline: Simd<u8, { inline_unit_len(BIT_LEN) }>,
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SupportedLaneCount` is not implemented for `LaneCount<{ inline_unit_len(BIT_LEN) }>`
     |
     = help: the following other types implement trait `SupportedLaneCount`:
               LaneCount<1>
               LaneCount<2>
               LaneCount<4>
               LaneCount<8>
               LaneCount<16>
               LaneCount<32>
               LaneCount<64>
note: required by a bound in `Simd`
    --> /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/core/src/../../portable-simd/crates/core_simd/src/vector.rs:103:1

warning: unused variable: `bit_len`
    --> src/main.rs:1782:26
     |
1782 | const fn inline_unit_len(bit_len: usize) -> usize {
     |                          ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_bit_len`
     |
     = note: `#[warn(unused_variables)]` on by default

For more information about this error, try `rustc --explain E0277`.
warning: `test44` (bin "test44") generated 4 warnings
error: could not compile `test44` (bin "test44") due to 1 previous error; 4 warnings emitted

Meta

rustc --version --verbose:

❯ rustc --version --verbose
rustc 1.78.0-nightly (381d69953 2024-02-24)
binary: rustc
commit-hash: 381d69953bb7c3390cec0fee200f24529cb6320f
commit-date: 2024-02-24
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
@yyy33 yyy33 added the C-bug Category: Bug label Apr 16, 2024
@calebzulawski
Copy link
Member

This is mostly a limitation of generic const exprs, but issues like this is one of the reasons I would like to change length validation to a post-mono check (see #364)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Bug
Projects
None yet
Development

No branches or pull requests

2 participants