Skip to content

error: internal compiler error: Encountered anon const with inference variable args but no error reported #139376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
listentodella opened this issue Apr 4, 2025 · 5 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@listentodella
Copy link

listentodella commented Apr 4, 2025

Code

#![no_std]
#![no_main]

use core::fmt::Write;
use core::str::from_utf8;

use cortex_m_rt::entry;
use defmt::*;
use embassy_executor::Executor;
use embassy_stm32::mode::Async;
use embassy_stm32::time::mhz;
use embassy_stm32::{spi, Config};
use heapless::String;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};use embassy_time::Delay;

use embassy_executor::Spawner;
use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Speed};
use icm426xx;

static EXECUTOR: StaticCell<Executor> = StaticCell::new();

#[embassy_executor::main]
async fn main(_spawner:Spawner) {
    info!("Hello World!");

    let mut config = Config::default();
    {
        use embassy_stm32::rcc::*;
        config.rcc.hsi = Some(HSIPrescaler::DIV1);
        config.rcc.csi = true;
        config.rcc.pll1 = Some(Pll {
            source: PllSource::HSI,
            prediv: PllPreDiv::DIV4,
            mul: PllMul::MUL50,
            divp: Some(PllDiv::DIV2),
            divq: Some(PllDiv::DIV8), // used by SPI3. 100Mhz.
            divr: None,
        });
        config.rcc.sys = Sysclk::PLL1_P; // 400 Mhz
        config.rcc.ahb_pre = AHBPrescaler::DIV2; // 200 Mhz
        config.rcc.apb1_pre = APBPrescaler::DIV2; // 100 Mhz
        config.rcc.apb2_pre = APBPrescaler::DIV2; // 100 Mhz
        config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz
        config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz
        config.rcc.voltage_scale = VoltageScale::Scale1;
    }
    let p = embassy_stm32::init(config);

    let mut spi_config = spi::Config::default();
    spi_config.frequency = mhz(1);

    let mut spi = spi::Spi::new(p.SPI3, p.PB3, p.PB5, p.PB4, p.DMA1_CH3, p.DMA1_CH4, spi_config);

    let spidev = embedded_hal_bus::spi::ExclusiveDevice::new_no_delay(spi, cs).unwrap();
    let mut icm = icm426xx::ICM42688::new(spidev);

    let mut icm = icm.initialize(Delay).await.unwrap();
    let mut bank = icm.ll().bank::<{icm426xx::register_bank::BANK0}>();
    // if I uncomment this line, the issue can be reproduced
    // let who_am_i = bank.who_am_i().async_read().await.unwrap().value(); //<<<<<----- it seems that this line cause the error
    info!("get chipid = 0x{:#x}", who_am_i);

    loop {

    }
}

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (00095b3da 2025-04-03)
binary: rustc
commit-hash: 00095b3da4f23d9b3e7a809ac6a4e2b2530df84c
commit-date: 2025-04-03
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Error output

error: internal compiler error: Encountered anon const with inference variable args but no error reported
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/mod.rs:596:27 - disabled backtrace

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/leo/work/embassy/examples/stm32h7/rustc-ice-2025-04-04T14_42_48-31640.txt` to your bug report

note: compiler flags: --crate-type bin -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 -C debug-assertions=on -C link-arg=--nmagic -C link-arg=-Tlink.x -C lin
k-arg=-Tdefmt.x

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
warning: `embassy-stm32h7-examples` (bin "spi_dma") generated 11 warnings (run `cargo fix --bin "spi_dma"` to apply 9 suggestions)
error: could not compile `embassy-stm32h7-examples` (bin "spi_dma"); 11 warnings emitted

Caused by:
  process didn't exit successfully: `/home/leo/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name spi_dma --edition=2021 src/bin/spi_dma.rs --error-format=
json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=179 --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -
C debuginfo=2 -C debug-assertions=on --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=2bdb7c4fd593f481 -C extra-filename=-86719187e8012ce3 --out-dir
 /home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps --target thumbv7em-none-eabihf -L dependency=/home/leo/work/embassy/examples/stm32h7/target/thumbv
7em-none-eabihf/debug/deps -L dependency=/home/leo/work/embassy/examples/stm32h7/target/debug/deps --extern assign_resources=/home/leo/work/embassy/examples/stm32h7/target/thumbv7
em-none-eabihf/debug/deps/libassign_resources-a8ad23844ca8282e.rlib --extern chrono=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libchrono-e1173
b2a55b51fbf.rlib --extern cortex_m=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libcortex_m-d96d34f7713cfde1.rlib --extern cortex_m_rt=/home/leo
/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libcortex_m_rt-436b434cafd666a5.rlib --extern critical_section=/home/leo/work/embassy/examples/stm32h7/targe
t/thumbv7em-none-eabihf/debug/deps/libcritical_section-85b6d083eff1692d.rlib --extern defmt=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libdefm
t-b15d774c8616d99c.rlib --extern defmt_rtt=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libdefmt_rtt-60a210810af7c078.rlib --extern embassy_embe
dded_hal=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libembassy_embedded_hal-bd212896216db6b1.rlib --extern embassy_executor=/home/leo/work/emb
assy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libembassy_executor-a4508d60ae1f7b29.rlib --extern embassy_futures=/home/leo/work/embassy/examples/stm32h7/target/thu
mbv7em-none-eabihf/debug/deps/libembassy_futures-673fa8760bb06c6f.rlib --extern embassy_net=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libemba
ssy_net-99d5f9de0f762709.rlib --extern embassy_stm32=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libembassy_stm32-10289614d195af4f.rlib --exter
n embassy_sync=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libembassy_sync-29ae7d830ba7f4ac.rlib --extern embassy_time=/home/leo/work/embassy/e
xamples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libembassy_time-685bc263d447be95.rlib --extern embassy_usb=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-ea
bihf/debug/deps/libembassy_usb-b2f6bca3be9ae1bd.rlib --extern embedded_hal=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libembedded_hal-550dc44a
5338bf01.rlib --extern embedded_hal_1=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libembedded_hal-40bd8cf5da55c092.rlib --extern embedded_hal_a
sync=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libembedded_hal_async-66e44975dced0295.rlib --extern embedded_hal_bus=/home/leo/work/embassy/e
xamples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libembedded_hal_bus-ee06384c4502eceb.rlib --extern embedded_io_async=/home/leo/work/embassy/examples/stm32h7/target/thumbv7
em-none-eabihf/debug/deps/libembedded_io_async-8dc4af71ed8f38f4.rlib --extern embedded_nal_async=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/li
bembedded_nal_async-8805cff95a22ee77.rlib --extern embedded_storage=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libembedded_storage-ddef47d58c0
9c877.rlib --extern grounded=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libgrounded-af89f5fd33915bfe.rlib --extern heapless=/home/leo/work/emb
assy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libheapless-fcb499525897e55d.rlib --extern icm426xx=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eab
ihf/debug/deps/libicm426xx-e7284d93b6741366.rlib --extern micromath=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libmicromath-08c3463a94f165ff.r
lib --extern panic_probe=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libpanic_probe-3c78894b1b265f51.rlib --extern rand_core=/home/leo/work/emb
assy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/librand_core-2359442b6839047b.rlib --extern static_cell=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none
-eabihf/debug/deps/libstatic_cell-c70e5aa98a2c3668.rlib --extern stm32_fmc=/home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/deps/libstm32_fmc-0a20c37b4c8
1f3bb.rlib -L /home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/build/embassy-stm32h7-examples-2ccab6f71a7cafbb/out -C link-arg=--nmagic -C link-arg=-Tlin
k.x -C link-arg=-Tdefmt.x -L /home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/build/cortex-m-781aa842728db867/out -L /home/leo/work/embassy/examples/stm3
2h7/target/thumbv7em-none-eabihf/debug/build/cortex-m-rt-9adfe51c2d4b61cf/out -L /home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/build/defmt-0fe16b8168f
5dcd2/out -L /home/leo/work/embassy/examples/stm32h7/target/thumbv7em-none-eabihf/debug/build/embassy-stm32-87b75f0ebfe9c21f/out -L /home/leo/.cargo/registry/src/index.crates.io-1
949cf8c6b5b557f/stm32-metapac-16.0.0/src/chips/stm32h750vb` (exit status: 101)

Backtrace

<backtrace>

rustc-ice-2025-04-04T14_42_48-31640.txt

@listentodella listentodella added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 4, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 4, 2025
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Apr 4, 2025

Could you provide a small example that can reproduce the ICE?

@TaKO8Ki TaKO8Ki added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Apr 4, 2025
@listentodella
Copy link
Author

Could you provide a small example that can reproduce the ICE?

I updated the Sample code. The crate is icm426xx with features=async.

@dare-to-recurse
Copy link

I believe I've also hit this ICE in some of the tests here, though I haven't had the opportunity to create a more minimal reproduction yet.

running cargo test --features="compile-time-ratio" in my repo triggers the ICE.

Meta

rustc 1.88.0-nightly (934880f58 2025-04-09)
binary: rustc
commit-hash: 934880f586f6ac1f952c7090e2a943fcd7775e7b
commit-date: 2025-04-09
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

@nazar-pc
Copy link

I hit this when using generic_const_exprs in a dependency. Confusingly (I just know it from experience in another issue) adding generic_const_exprs to the crate that uses a dependency with generic_const_exprs helps with compilation.

@moxian
Copy link
Contributor

moxian commented May 1, 2025

Minimized static-rc crate from #139376 (comment)
Requires two-crate setup (or a separate bin):

# Cargo.toml
[package]
name = "mycrate"
version = "0.1.0"
edition = "2024"

[[bin]]
name="run"
// src/lib.rs
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

pub struct StaticRc<const NUM: usize> {}

impl<const N: usize> StaticRc<N> {
    pub fn new() -> Self
    where
        [(); N - 1]: Sized,
    {
        loop {}
    }
    pub fn get_mut(this: &mut Self) -> &mut () {
        loop {}
    }
}
// src/bin/run.rs
use mycrate::StaticRc;

type Full = StaticRc<1>;

fn main() {
    let mut rc = Full::new();
    let r: &mut () = Full::get_mut(&mut rc);
}

trigger ICE with cargo build.

However, I shall note that I was not able to reproduce the issue with the original code, as it requires either knowledge or the tooling suitable for stm32 microcontrollers which I do not have (in other words: i was unable to compile the code; perhaps me being on windows is part of the issue)

The static-rc example bisects to #132927, same as #133199 . So I would hazard a guess this is a duplicate. And I would optimistically hope that the OP has the exact same root cause and will not require extra investigation.

@rustbot label: -E-needs-mcve +S-has-mcve +S-has-bisection +F-generic_const_exprs +A-const-generics +requires-incomplete-features

@rustbot rustbot added F-generic_const_exprs `#![feature(generic_const_exprs)]` S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue A-const-generics Area: const generics (parameters and arguments) requires-incomplete-features This issue requires the use of incomplete features. and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels May 1, 2025
@jieyouxu jieyouxu closed this as completed May 1, 2025
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants