commit 5bfd624afa79cf07e93d09306d8d97822fd62b8c Author: Alex Janka Date: Fri Aug 2 12:11:20 2024 +1000 repro diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fac57f6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +rustc-ice-*.txt diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..14a76d3 --- /dev/null +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..1a1ffdc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +members = ["binary", "library"] +resolver = "2" diff --git a/binary/Cargo.toml b/binary/Cargo.toml new file mode 100644 index 0000000..1920c4b --- /dev/null +++ b/binary/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "binary" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "binary" +path = "main.rs" + + +[dependencies] +library = { path = "../library" } diff --git a/binary/main.rs b/binary/main.rs new file mode 100644 index 0000000..ab26035 --- /dev/null +++ b/binary/main.rs @@ -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], + }); +} diff --git a/library/Cargo.toml b/library/Cargo.toml new file mode 100644 index 0000000..6a3c415 --- /dev/null +++ b/library/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "library" +version = "0.1.0" +edition = "2021" + +[lib] +path = "lib.rs" diff --git a/library/lib.rs b/library/lib.rs new file mode 100644 index 0000000..ca475dc --- /dev/null +++ b/library/lib.rs @@ -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 { + pub config: [u8; N], +} + +pub struct ImplementsTraitOverConstGeneric; + +impl LibTrait for ImplementsTraitOverConstGeneric { + 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; + +impl NonTraitWithConstGeneric { + pub const NUM: usize = N; + + pub fn configure(&mut self, _: &Config<{ Self::NUM }>) {} +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..5d56faf --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly"