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: removal index (is 0) should be < len (is 0) / glacier fixed/81899.rs #88434

Closed
matthiaskrgr opened this issue Aug 28, 2021 · 5 comments · Fixed by #88698
Closed

ICE: removal index (is 0) should be < len (is 0) / glacier fixed/81899.rs #88434

matthiaskrgr opened this issue Aug 28, 2021 · 5 comments · Fixed by #88698
Assignees
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Aug 28, 2021

Code

code from glacier fixed/81899.rs

const _CONST: &[u8] = &f(&[], |_| {});

const fn f<F>(_: &[u8], _: F) -> &[u8]
where
    F: FnMut(&u8),
{
    panic!()
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (ac50a5335 2021-08-27)
binary: rustc
commit-hash: ac50a53359328a5d7f2f558833e63d59d372e4f7
commit-date: 2021-08-27
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'removal index (is 0) should be < len (is 0)', compiler/rustc_mir/src/borrow_check/region_infer/mod.rs:2148:26
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.56.0-nightly (ac50a5335 2021-08-27) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `_CONST`
#1 [analysis] running analysis passes on this crate
end of query stack
Backtrace

thread 'rustc' panicked at 'removal index (is 0) should be < len (is 0)', compiler/rustc_mir/src/borrow_check/region_infer/mod.rs:2148:26
stack backtrace:
   0:     0x7f6afd08f26c - std::backtrace_rs::backtrace::libunwind::trace::hf16bab017f241aa7
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7f6afd08f26c - std::backtrace_rs::backtrace::trace_unsynchronized::hfc27e8424e499412
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f6afd08f26c - std::sys_common::backtrace::_print_fmt::h5be1efcd85b410a6
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f6afd08f26c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h73cf7b443adc9274
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f6afd0ecf3c - core::fmt::write::h9a6d9c74526a6c1b
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/core/src/fmt/mod.rs:1150:17
   5:     0x7f6afd080305 - std::io::Write::write_fmt::hb955fdedb1f691a8
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/io/mod.rs:1667:15
   6:     0x7f6afd0927c0 - std::sys_common::backtrace::_print::hd5ba2c14c2d68f09
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f6afd0927c0 - std::sys_common::backtrace::print::h3b3d8e691bd3d5e8
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f6afd0927c0 - std::panicking::default_hook::{{closure}}::h703c292cd78e95a9
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/panicking.rs:210:50
   9:     0x7f6afd09237b - std::panicking::default_hook::h23aea4a9b2140559
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/panicking.rs:227:9
  10:     0x7f6afd864fb1 - rustc_driver::DEFAULT_HOOK::{{closure}}::{{closure}}::h470d093cda0f164a
  11:     0x7f6afd092fd9 - std::panicking::rust_panic_with_hook::hde97eb7782db5504
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/panicking.rs:628:17
  12:     0x7f6afd092a90 - std::panicking::begin_panic_handler::{{closure}}::h531b374cb1cba3c4
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/panicking.rs:521:13
  13:     0x7f6afd08f714 - std::sys_common::backtrace::__rust_end_short_backtrace::h170e7849f1857b98
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7f6afd0929f9 - rust_begin_unwind
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/panicking.rs:517:5
  15:     0x7f6afd058761 - core::panicking::panic_fmt::hcf5f6d96e1dd7099
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/core/src/panicking.rs:101:14
  16:     0x7f6afd058562 - alloc::vec::Vec<T,A>::remove::assert_failed::h051d4dc566b2d8cf
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/alloc/src/vec/mod.rs:1390:13
  17:     0x7f6afeeac476 - rustc_mir::borrow_check::region_infer::RegionInferenceContext::find_outlives_blame_span::h6eb564df239b09b8
  18:     0x7f6afee5a521 - rustc_mir::borrow_check::do_mir_borrowck::h51a94d100c5e3888
  19:     0x7f6afedcdf2a - rustc_infer::infer::InferCtxtBuilder::enter::h646b279d9c768cff
  20:     0x7f6afee57dcc - rustc_mir::borrow_check::mir_borrowck::h6c76a3d9979e297a
  21:     0x7f6afee4f9ea - core::ops::function::FnOnce::call_once::habe1f175ab86996b
  22:     0x7f6afeee5cc9 - rustc_query_system::query::plumbing::get_query_impl::h2ccb16f3af1c7b60
  23:     0x7f6afef7b80b - <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck::h04071480a6190c53
  24:     0x7f6afe9af3c6 - rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners::h7dc05cca49a9f847
  25:     0x7f6aff378bc5 - rustc_interface::passes::analysis::h9dedef5d4f497722
  26:     0x7f6aff86af1f - rustc_query_system::query::plumbing::get_query_impl::h57cd2e389f82820b
  27:     0x7f6aff9ce4bd - <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis::h71bb1ebf7eea66a8
  28:     0x7f6aff36f9a7 - rustc_interface::passes::QueryContext::enter::h8700e1ecccfeda2c
  29:     0x7f6aff356811 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::h0161b9a0a28c5115
  30:     0x7f6aff34392c - rustc_span::with_source_map::h4517cd205ea168e7
  31:     0x7f6aff356148 - scoped_tls::ScopedKey<T>::set::hf5457a6127e91291
  32:     0x7f6aff3440ab - std::sys_common::backtrace::__rust_begin_short_backtrace::h967f189214a28c38
  33:     0x7f6aff343095 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hbf5ef41d18b70b15
  34:     0x7f6afd09f633 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h132ab4ac45190c0c
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/alloc/src/boxed.rs:1636:9
  35:     0x7f6afd09f633 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf5feeb35085fa69e
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/alloc/src/boxed.rs:1636:9
  36:     0x7f6afd09f633 - std::sys::unix::thread::Thread::new::thread_start::h21e4b7c982487240
                               at /rustc/ac50a53359328a5d7f2f558833e63d59d372e4f7/library/std/src/sys/unix/thread.rs:106:17
  37:     0x7f6afcfa8259 - start_thread
  38:     0x7f6afcebd5e3 - __GI___clone
  39:                0x0 - <unknown>

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.56.0-nightly (ac50a5335 2021-08-27) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `_CONST`
#1 [analysis] running analysis passes on this crate
end of query stack

@matthiaskrgr matthiaskrgr 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 Aug 28, 2021
@matthiaskrgr
Copy link
Member Author

This one also crashes beta and stable release channel.

@camelid
Copy link
Member

camelid commented Aug 29, 2021

code from glacier fixed/81899.rs

Huh, why was this not detected earlier if it was tracked in glacier as fixed?

@Noble-Mushtak
Copy link
Contributor

If you add a 'static annotation to the trait bound on F, then it no longer ICEs. Here's the code:

// build-pass
// Regression test for issue 88434

const _CONST: &[u8] = &f(&[], |_| {});

const fn f<F>(_: &[u8], _: F) -> &[u8]
where
    F: FnMut(&'static u8),
{
    panic!()
}

fn main() {}

Output:

error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
 --> src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs:6:12
  |
6 | const fn f<F>(_: &[u8], _: F) -> &[u8]
  |            ^
  |
  = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
  = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable

error[E0658]: panicking in constant functions is unstable
  --> src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs:10:5
   |
10 |     panic!()
   |     ^^^^^^^^
   |
   = note: see issue #51999 <https://github.com/rust-lang/rust/issues/51999> for more information
   = help: add `#![feature(const_panic)]` to the crate attributes to enable
   = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.

And if you add the two feature attributes the above messages ask you to enable, it still does not ICE, but correctly errors with "evaluation of constant value failed."

warning: function is never used: `f`
 --> src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs:8:10
  |
8 | const fn f<F>(_: &[u8], _: F) -> &[u8]
  |          ^
  |
  = note: `#[warn(dead_code)]` on by default

error[E0080]: evaluation of constant value failed
  --> src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs:12:5
   |
6  | const _CONST: &[u8] = &f(&[], |_| {});
   |                        -------------- inside `_CONST` at src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs:6:24
...
12 |     panic!()
   |     ^^^^^^^^
   |     |
   |     the evaluated program panicked at 'explicit panic', src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs:12:5
   |     inside `f::<[closure@src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs:6:31: 6:37]>` at /home/noble/Desktop/rust/library/std/src/panic.rs:18:9
   |
   = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0080`.

Based on some debugging which I described here, I think this ICE has to do with the lifetime 'a in the bound F: for<'a> FnMut(&'a u8), although I'm not exactly sure how.

I am new to the Rust compiler, and I just chose this issue because it seemed like a good first issue to work on, so I will read the Rustc development guide more (thanks to @camelid for sharing this) and try to further debug this.

@camelid
Copy link
Member

camelid commented Aug 30, 2021

@Noble-Mushtak If you plan to work on this issue, I recommend claiming it so other people know that and don't start working on it too. You can claim the issue by commenting with @rustbot claim. More details about how to use rustbot are in the rustc-dev-guide.

You may also want to read the "Getting Started" section of the guide.

@Noble-Mushtak
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

Successfully merging a pull request may close this issue.

4 participants