Skip to content
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

ICE when normalizing associated types with generic_const_exprs cross-crate #89355

Closed
T-Dark0 opened this issue Sep 29, 2021 · 2 comments
Closed
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@T-Dark0
Copy link

T-Dark0 commented Sep 29, 2021

The following code ICEs. Strangely enough, it works perfectly well when used within a single crate, but attempting to use the first snippet from a crate other than its own will ICE.

Code

in src/lib.rs

pub struct BoundedTest<const MIN: u8, const MAX: u8>(pub u8);

impl<const LMIN: u8, const LMAX: u8, const RMIN: u8, const RMAX: u8> Add<BoundedTest<RMIN, RMAX>>
    for BoundedTest<LMIN, LMAX>
where
    Evaluator<{ LMIN + RMIN }>: ,
    Evaluator<{ LMAX + RMAX }>: ,
{
    type Output = BoundedTest<{ LMIN + RMIN }, { LMAX + RMAX }>;

    fn add(self, rhs: BoundedTest<RMIN, RMAX>) -> Self::Output {
        BoundedTest(self.0 + rhs.0)
    }
}

pub struct Evaluator<const N: u8>;

in tests/test.rs

// This does not ICE if you put it in a unit test
#[test]
fn test() {
    use bounded_int::BoundedTest;
    let foo = BoundedTest::<10, 20>(15);
    let bar = BoundedTest::<25, 30>(27);
    let baz: BoundedTest<35, 50> = foo + bar;
}

Meta

rustc --version --verbose:

rustc 1.57.0-nightly (8f8092cc3 2021-09-28)
binary: rustc
commit-hash: 8f8092cc32ec171becef8ceacec7dbb06c5d7d7e
commit-date: 2021-09-28
host: x86_64-pc-windows-msvc
release: 1.57.0-nightly
LLVM version: 13.0.0

Error output

The output of cargo test -- --test is

error: internal compiler error: compiler\rustc_traits\src\normalize_erasing_regions.rs:54:32: could not fully normalize `<bounded_int::BoundedTest<LMIN, LMAX> as std::ops::Add<bounded_int::BoundedTest<RMIN, RMAX>>>::Output`

thread 'rustc' panicked at 'Box<dyn Any>', compiler\rustc_errors\src\lib.rs:1146:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

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: rustc 1.57.0-nightly (8f8092cc3 2021-09-28) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental

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

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<bounded_int::BoundedTest<LMIN, LMAX> as core::ops::arith::Add<bounded_int::BoundedTest<RMIN, RMAX>>>::Output`
#1 [fn_abi_of_instance] computing call ABI of `<bounded_int::BoundedTest<10_u8, 20_u8> as core::ops::arith::Add<bounded_int::BoundedTest<25_u8, 30_u8>>>::add`   
end of query stack
warning: `bounded_int` (test "test") generated 1 warning
error: could not compile `bounded_int`; 1 warning emitted
@T-Dark0 T-Dark0 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 Sep 29, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Sep 29, 2021

both crates need feature(generic_const_exprs) enabled, if you don't have the feature enabled in your other crate this might be a duplicate of #79018

@BoxyUwU BoxyUwU added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Sep 29, 2021
@T-Dark0
Copy link
Author

T-Dark0 commented Oct 1, 2021

Oh, oops. It's probably a duplicate then. I'd taken a look, but didn't find that issue

@BoxyUwU BoxyUwU closed this as completed Oct 2, 2021
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) ❄️ 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

2 participants