Compiler Hangs When Compiling Code with `generic_const_exprs`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#![feature(generic_const_exprs)]
trait MyFn<Args> {
type Output;
fn call(self, args: Args) -> Self::Output;
}
struct Bubble<T, const N: u8> {
t: std::marker::PhantomData<T>,
}
impl<T> MyFn<T> for Bubble<T, 1> {
type Output = [T; 1];
fn call(self, args: T) -> [T; 1] {
[args]
}
}
impl<T, const N: u8> MyFn<T> for Bubble<T, N>
where
[(); { N - 1 }]:,
Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
{
type Output = [T; N];
fn call(self, args: T) -> [T; N] {
let f = Bubble::<[T; N], { N - 1 }> {
t: std::marker::PhantomData,
};
f.call([args])
}
}
impl<T, const N: u8> MyFn<T> for Bubble<T, N>
where
[(); { N - 1 }]:,
Bubble<[T; N], { N - 1 }>: MyFn<[T; N]>,
{
type Output = [T; 1];
fn call(self, args: T) -> [T; 1] {
let f = Bubble::<[T; 1], { N - 1 }> {
t: std::marker::PhantomData,
};
f.call([args])
}
}
fn main() {}
I expected to see this happen: The compiler compiles successfully or outputs an error message.
Instead, this happened: The code, as provided below, appears to encounter a hang
Interestingly, when I remove #![feature(generic_const_exprs)] , this piece of code quickly compiles and produces error messages.
Meta
rustc --version --verbose:
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2
The same problem is reproduced on the nightly version(1.75.0-nightly aa1a71e9e 2023-10-26)
what's more, to get more information,I also tried '-Z time-passes' (using nighly version):
Output
time: 0.000; rss: 29MB -> 31MB ( +2MB) parse_crate
time: 0.003; rss: 35MB -> 49MB ( +14MB) expand_crate
time: 0.003; rss: 35MB -> 49MB ( +14MB) macro_expand_crate
time: 0.001; rss: 49MB -> 52MB ( +3MB) late_resolve_crate
time: 0.001; rss: 49MB -> 52MB ( +3MB) resolve_crate
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
--> code.rs:1:12
|
1 | #![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: unnecessary braces around const expression
--> code.rs:17:10
|
17 | [(); { N - 1 }]:,
| ^^ ^^
|
= note: `#[warn(unused_braces)]` on by default
help: remove these braces
|
17 - [(); { N - 1 }]:,
17 + [(); N - 1]:,
|
warning: unnecessary braces around const expression
--> code.rs:30:10
|
30 | [(); { N - 1 }]:,
| ^^ ^^
|
help: remove these braces
|
30 - [(); { N - 1 }]:,
30 + [(); N - 1]:,
|
time: 0.007; rss: 52MB -> 58MB ( +6MB) looking_for_entry_point
time: 0.007; rss: 52MB -> 58MB ( +6MB) misc_checking_1
time: 0.001; rss: 58MB -> 61MB ( +3MB) type_collecting
error[E0080]: evaluation of `<Bubble<[!0; 1], { N - 1 }> as MyFn<[!0; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!1; 1], 0> as MyFn<[!1; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!2; 1], 0> as MyFn<[!2; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!3; 1], 0> as MyFn<[!3; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!4; 1], 0> as MyFn<[!4; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!5; 1], 0> as MyFn<[!5; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!6; 1], 0> as MyFn<[!6; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!7; 1], 0> as MyFn<[!7; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!8; 1], 0> as MyFn<[!8; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!9; 1], 0> as MyFn<[!9; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!10; 1], 0> as MyFn<[!10; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!11; 1], 0> as MyFn<[!11; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!12; 1], 0> as MyFn<[!12; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!13; 1], 0> as MyFn<[!13; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!14; 1], 0> as MyFn<[!14; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!15; 1], 0> as MyFn<[!15; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!16; 1], 0> as MyFn<[!16; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
error[E0080]: evaluation of `<Bubble<[!17; 1], 0> as MyFn<[!17; 1]>>::{constant#2}` failed
--> code.rs:18:22
|
18 | Bubble<[T; 1], { N - 1 }>: MyFn<[T; 1]>,
| ^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
……
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the supplied reproducer with the reported nightly compiler and compare its behavior with the timing output in the issue. The fix is complete when this code terminates with diagnostics instead of hanging; no repository files or tests are identified in the report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100