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: const_panic panics in some cases #85907

Closed
m-ou-se opened this issue Jun 1, 2021 · 5 comments · Fixed by #98560
Closed

ICE: const_panic panics in some cases #85907

m-ou-se opened this issue Jun 1, 2021 · 5 comments · Fixed by #98560
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way.

Comments

@m-ou-se
Copy link
Member

m-ou-se commented Jun 1, 2021

#![feature(const_panic)]

const fn hey() -> usize {
    panic!(123);
}

fn main() {
    let _: [u8; hey()] = todo!();
}

Playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=31e3a36a34e378389943330936b81dbf

Output
   Compiling playground v0.0.1 (/playground)
error: argument to `panic!()` in a const context must have type `&str`
 --> src/main.rs:4:5
  |
4 |     panic!(123);
  |     ^^^^^^^^^^^^
  |
  = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)

thread 'rustc' panicked at '`ref_to_mplace` called on non-ptr type', compiler/rustc_mir/src/interpret/place.rs:307:47
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.54.0-nightly (657bc0188 2021-05-31) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `main::{constant#0}`
#1 [eval_to_const_value_raw] simplifying constant for the type system `main::{constant#0}`
end of query stack
error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.

cc @RalfJung

@m-ou-se m-ou-se added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ C-bug Category: This is a bug. A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) requires-nightly This issue requires a nightly compiler in some way. labels Jun 1, 2021
@RalfJung
Copy link
Member

RalfJung commented Jun 1, 2021

Ah, yes, array lengths... this is like #79047

@RalfJung
Copy link
Member

RalfJung commented Jun 1, 2021

Cc @rust-lang/wg-const-eval

@RalfJung
Copy link
Member

RalfJung commented Jun 1, 2021

This ICEs on stable:

const fn hey() -> usize {
    panic!(123);
}

fn main() {
    let _: [u8; hey()] = todo!();
}

I thought we have an issue for this somewhere? Basically, array lengths (and patterns) side-step all prior checks, including stability checks, and try to evaluate this constant anyway.

@klensy
Copy link
Contributor

klensy commented Jun 1, 2021

version=nightly&mode=debug&edition=2018&
note: this error originates in the macro $crate::panic::panic_2015

Hmm

fanninpm added a commit to fanninpm/glacier that referenced this issue Jun 4, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 5, 2021
@Alexendoo
Copy link
Member

No longer ICEs since #93691

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 13, 2022
@TaKO8Ki TaKO8Ki self-assigned this Jun 26, 2022
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Jun 27, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jun 28, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 28, 2022
…askrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#98548 (rustdoc-json: Allow Typedef to be different in sanity assert)
 - rust-lang#98560 (Add regression test for rust-lang#85907)
 - rust-lang#98564 (Remove references to `./tmp` in-tree)
 - rust-lang#98602 (Add regression test for rust-lang#80074)
 - rust-lang#98606 (:arrow_up: rust-analyzer)
 - rust-lang#98609 (Fix ICE for associated constant generics)
 - rust-lang#98611 (Fix glob import ICE in rustdoc JSON format)
 - rust-lang#98617 (Remove feature `const_option` from std)
 - rust-lang#98619 (Fix mir-opt wg name)
 - rust-lang#98621 (llvm-wrapper: adapt for removal of the ASanGlobalsMetadataAnalysis LLVM API)
 - rust-lang#98623 (fix typo in comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 5c7a045 Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants