mirror of
https://github.com/italicsjenga/generic-const-exprs-panic-repro.git
synced 2024-11-27 11:41:30 +11:00
repro
This commit is contained in:
commit
5bfd624afa
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
rustc-ice-*.txt
|
14
Cargo.lock
generated
Normal file
14
Cargo.lock
generated
Normal file
|
@ -0,0 +1,14 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "binary"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"library",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "library"
|
||||
version = "0.1.0"
|
3
Cargo.toml
Normal file
3
Cargo.toml
Normal file
|
@ -0,0 +1,3 @@
|
|||
[workspace]
|
||||
members = ["binary", "library"]
|
||||
resolver = "2"
|
12
binary/Cargo.toml
Normal file
12
binary/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "binary"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[[bin]]
|
||||
name = "binary"
|
||||
path = "main.rs"
|
||||
|
||||
|
||||
[dependencies]
|
||||
library = { path = "../library" }
|
14
binary/main.rs
Normal file
14
binary/main.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use library::*;
|
||||
|
||||
fn main() {
|
||||
// this doesn't compile
|
||||
let mut inner = ImplementsTraitOverConstGeneric::<4>;
|
||||
|
||||
// but this would
|
||||
// let mut inner = NonTraitWithConstGeneric::<4>;
|
||||
|
||||
// if we don't call this function then it'll compile fine
|
||||
inner.configure(&Config {
|
||||
config: [0, 0, 0, 0],
|
||||
});
|
||||
}
|
7
library/Cargo.toml
Normal file
7
library/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "library"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
38
library/lib.rs
Normal file
38
library/lib.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
pub trait LibTrait {
|
||||
const NUM: usize;
|
||||
|
||||
fn configure(&mut self, cfg: &Config<{ Self::NUM }>);
|
||||
}
|
||||
|
||||
pub struct Config<const N: usize> {
|
||||
pub config: [u8; N],
|
||||
}
|
||||
|
||||
pub struct ImplementsTraitOverConstGeneric<const N: usize>;
|
||||
|
||||
impl<const N: usize> LibTrait for ImplementsTraitOverConstGeneric<N> {
|
||||
const NUM: usize = N;
|
||||
|
||||
fn configure(&mut self, _: &Config<{ Self::NUM }>) {}
|
||||
}
|
||||
|
||||
// but this works:
|
||||
|
||||
// impl LibTrait for ImplementsTraitOverConstGeneric<4> {
|
||||
// const NUM: usize = 4;
|
||||
|
||||
// fn configure(&mut self, _: &Config<{ Self::NUM }>) {}
|
||||
// }
|
||||
|
||||
// or this:
|
||||
|
||||
pub struct NonTraitWithConstGeneric<const N: usize>;
|
||||
|
||||
impl<const N: usize> NonTraitWithConstGeneric<N> {
|
||||
pub const NUM: usize = N;
|
||||
|
||||
pub fn configure(&mut self, _: &Config<{ Self::NUM }>) {}
|
||||
}
|
2
rust-toolchain.toml
Normal file
2
rust-toolchain.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
[toolchain]
|
||||
channel = "nightly"
|
Loading…
Reference in a new issue