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: compiling binary against lib with feature(generic_const_exprs) #88882

Closed
gkanwar opened this issue Sep 12, 2021 · 3 comments
Closed

ICE: compiling binary against lib with feature(generic_const_exprs) #88882

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

Comments

@gkanwar
Copy link

gkanwar commented Sep 12, 2021

I am finding an ICE when splitting a single binary with #![feature(generic_const_exprs)] into a binary plus a library crate that implements the structs and traits. This only occurs when I fail to add #![feature(generic_const_exprs)] to the binary crate as well. (Am I using the terminology crate correctly? I am still new to the whole rust environment...)

I think it is reasonable to expect the feature to be marked in the binary as well, but I would not expect an ICE when it is left out.

Code

This code compiles correctly as a standalone binary:

#![feature(generic_const_exprs)]

pub trait TraitWithAssocConst {
  const SIZE: usize;
}

pub struct Test;
impl TraitWithAssocConst for Test {
  const SIZE: usize = 8;
}

pub trait TraitDependingOnAssocConst {
  fn dummy<T>(&self, u: &T) -> ()
  where T : TraitWithAssocConst,
  [(); T::SIZE]: ;
}

pub struct Test2;
impl TraitDependingOnAssocConst for Test2 {
  fn dummy<T>(&self, u: &T) -> ()
  where T : TraitWithAssocConst,
  [(); T::SIZE]:
  {
  }
}

fn main() -> () {
  let t1 = Test;
  let t2 = Test2;
  t2.dummy(&t1);
}

Now I split this into a library crate mylib and a binary depending on it, but fail to include #![feature(generic_const_exprs)] in the binary:

// Binary crate:
// I "forget" to enable the feature here.
// #![feature(generic_const_exprs)]

use mylib::*;

fn main() -> () {
  let t1 = Test;
  let t2 = Test2;
  t2.dummy(&t1);
}
// Library crate mylib:
// I do enable the feature here.
#![feature(generic_const_exprs)]

pub trait TraitWithAssocConst {
  const SIZE: usize;
}

pub struct Test;
impl TraitWithAssocConst for Test {
  const SIZE: usize = 8;
}

pub trait TraitDependingOnAssocConst {
  fn dummy<T>(&self, u: &T) -> ()
  where T : TraitWithAssocConst,
  [(); T::SIZE]: ;
}

pub struct Test2;
impl TraitDependingOnAssocConst for Test2 {
  fn dummy<T>(&self, u: &T) -> ()
  where T : TraitWithAssocConst,
  [(); T::SIZE]:
  {
  }
}

The binary then fails to compile with the ICE trace given below.

Meta

rustc --version --verbose:

rustc 1.57.0-nightly (8c2b6ea37 2021-09-11)
binary: rustc
commit-hash: 8c2b6ea37d7719a0370bd404030eef9702c1752c
commit-date: 2021-09-11
host: x86_64-apple-darwin
release: 1.57.0-nightly
LLVM version: 13.0.0

Error output

   Compiling tmp v0.1.0 (/Users/gkanwar/tmp)
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/lib/lib.rs:1:12
  |
1 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information

warning: unused variable: `u`
  --> src/lib/lib.rs:20:22
   |
20 |   fn dummy<T>(&self, u: &T) -> ()
   |                      ^ help: if this is intentional, prefix it with an underscore: `_u`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: `tmp` (lib) generated 2 warnings
warning: Error finalizing incremental compilation session directory `/Users/gkanwar/tmp/target/debug/incremental/test-1wbxzdr6ui2on/s-g2aqzqcst1-1hgx4sl-working`: No such file or directory (os error 2)

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<^0 as mylib::TraitWithAssocConst>, [Ty(Anon)])` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:68:32

error: internal compiler error: ty::ConstKind::Error constructed but no error reported.
  |
  = note: delayed at /rustc/8c2b6ea37d7719a0370bd404030eef9702c1752c/compiler/rustc_middle/src/ty/consts.rs:183:43

error: internal compiler error: `ErrorReported` without an error
 --> src/bin/test.rs:9:6
  |
9 |   t2.dummy(&t1);
  |      ^^^^^
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs:843:31

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1165:13
stack backtrace:
   0: _rust_begin_unwind
   1: std::panicking::begin_panic_fmt
   2: rustc_errors::HandlerInner::flush_delayed
   3: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   4: core::ptr::drop_in_place<rustc_session::parse::ParseSess>
   5: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
   6: core::ptr::drop_in_place<rustc_interface::interface::Compiler>
   7: rustc_span::with_source_map
   8: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

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 (8c2b6ea37 2021-09-11) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
end of query stack
warning: `tmp` (bin "test") generated 1 warning
error: could not compile `tmp`; 1 warning emitted
@gkanwar gkanwar 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 12, 2021
gkanwar added a commit to gkanwar/rs-lattice that referenced this issue Sep 12, 2021
This was causing an ICE before, now everything runs again! Submitted the bug
to the Rust Github issues tracker here:
rust-lang/rust#88882
@hellow554
Copy link
Contributor

Indeed, I only can trigger the ICE if I have a lib and a binary.

main.rs:

use abc::dummy;

fn main() -> () {
    dummy(());
}

lib.rs:

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

pub trait TraitWithAssocConst {
    const SIZE: usize;
}

impl TraitWithAssocConst for () {
    const SIZE: usize = 8;
}

pub fn dummy<T>(_: T)
where
    T: TraitWithAssocConst,
    [(); T::SIZE]: ,
{
}

Before:

error: constant expression depends on a generic parameter
  --> src/lib.rs:15:5
   |
15 |     [(); T::SIZE]: ,
   |     ^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

Regressed somewhere between e2be5f5...a1947b3

@BoxyUwU
Copy link
Member

BoxyUwU commented Sep 15, 2021

Probably a duplicate of #79018 see this comment

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

gkanwar commented Sep 15, 2021

Thanks, I think you are right that this bug is an instance of that issue. Should this one be closed?

@BoxyUwU BoxyUwU closed this as completed Sep 24, 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

3 participants