This commit is contained in:
Alex Janka 2024-08-02 12:11:20 +10:00
commit 5bfd624afa
8 changed files with 92 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
rustc-ice-*.txt

14
Cargo.lock generated Normal file
View 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
View file

@ -0,0 +1,3 @@
[workspace]
members = ["binary", "library"]
resolver = "2"

12
binary/Cargo.toml Normal file
View 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
View 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
View file

@ -0,0 +1,7 @@
[package]
name = "library"
version = "0.1.0"
edition = "2021"
[lib]
path = "lib.rs"

38
library/lib.rs Normal file
View 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
View file

@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"