ICE / `Unexpected initial operand type`
Open
Nobody has claimed this yet.
A-debuginfo
C-bug
F-adt_const_params
F-generic_const_exprs
I-ICE
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
#![feature(adt_const_params, generic_const_exprs)]
#![allow(incomplete_features)]
mod lib {
const N_ISLANDS: usize = 4;
const N_BRIDGES: usize = 7;
const BRIDGES: [(usize, usize); 7] = [(0, 1), (0, 1), (0, 2), (0, 3), (0, 3), (1, 2), (2, 3)];
pub type Matrix = [[usize; N_ISLANDS]; N_ISLANDS];
const EMPTY_MATRIX: Matrix = [[0; N_ISLANDS]; N_ISLANDS];
const fn build(mut matrix: Matrix, (to, from): (usize, usize)) -> Matrix {
matrix[to][from] += 1;
matrix[from][to] += 1;
matrix
}
pub const fn walk(mut matrix: Matrix, from: usize, to: usize) -> Matrix {
matrix[from][to] -= 1;
matrix[to][from] -= 1;
matrix
}
const fn to_matrix(bridges: [(usize, usize); N_BRIDGES]) -> Matrix {
let matrix = EMPTY_MATRIX;
let matrix = build(matrix, bridges[0]);
let matrix = build(matrix, bridges[1]);
let matrix = build(matrix, bridges[2]);
let matrix = build(matrix, bridges[3]);
let matrix = build(matrix, bridges[4]);
let matrix = build(matrix, bridges[5]);
let matrix = build(matrix, bridges[6]);
matrix
}
const BRIDGE_MATRIX: [[usize; N_ISLANDS]; N_ISLANDS] = to_matrix(BRIDGES);
pub struct Walk<const CURRENT: usize, const REMAINING: Matrix> {
_p: (),
}
impl Walk<0, BRIDGE_MATRIX> {
pub const fn new() -> Self {
Self { _p: () }
}
}
impl<const CURRENT: usize, const REMAINING: Matrix> Walk<CURRENT, REMAINING> {
pub fn proceed_to<const NEXT: usize>(
self,
) -> Walk<NEXT, { walk(REMAINING, CURRENT, NEXT) }> {
Walk { _p: () }
}
}
pub struct Trophy {
_p: (),
}
impl<const CURRENT: usize> Walk<CURRENT, EMPTY_MATRIX> {
pub fn collect_prize(self) -> Trophy {
Trophy { _p: () }
}
}
}
pub use lib::{Trophy, Walk};
fn main() {
// Example, taking the first step
let _ = Walk::new().proceed_to::<1>();
// Don't be so eager to collect the trophy
// let trophy = Walk::new()
// .proceed_to::<1>()
// .proceed_to::<0>()
// .collect_prize();
// Can't just make a Trophy out of thin air, you must earn it
// let trophy: Trophy = Trophy { _p: () };
// Can you collect the Trophy?
}
Meta
rustc --version --verbose:
rustc 1.80.0-nightly (76e7a0849 2024-06-06)
binary: rustc
commit-hash: 76e7a0849c07d73e4d9afde8036ee8c450127cc8
commit-date: 2024-06-06
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.7
Error output
rustc -Cdebuginfo=2
<output>
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 provided minimal reproducer with the reported nightly toolchain and inspect where the Unexpected initial operand type ICE is emitted. No source file or test is named in the issue; trace the ICE to its responsible compiler subsystem, then add a regression test showing the reproducer no longer panics.
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