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: diagnostics/mutability_errors.rs: index out of bounds #121004

Closed
matthiaskrgr opened this issue Feb 13, 2024 · 2 comments · Fixed by #121020
Closed

ICE: diagnostics/mutability_errors.rs: index out of bounds #121004

matthiaskrgr opened this issue Feb 13, 2024 · 2 comments · Fixed by #121020
Labels
C-bug Category: This is a bug. D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. 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

auto-reduced (treereduce-rust):

trait Hello {
    fn example(val: T);
}

struct Test1(i32);

impl Hello for Test1 {
    fn example(&self, input: &i32) {
        *input = self.0;
    }
}

original:

trait Hello {
  fn example(val: T); // should suggest here
}

struct Test1(i32);

impl Hello for Test1 {
  fn example(&self, input: &i32) { // should not suggest here
      *input = self.0; //~ ERROR cannot assign
  }
}

struct Test2(i32);

impl Hello for Test2 {
  fn example(&self, input: &i32) { // should not suggest here
    self.0 += *input; //~ ERROR cannot assign
  }
}

fn main() { }

Version information

rustc 1.78.0-nightly (b381d3ab2 2024-02-12)
binary: rustc
commit-hash: b381d3ab27f788f990551100c4425bb782d26d76
commit-date: 2024-02-12
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0412]: cannot find type `T` in this scope
 --> /tmp/icemaker_global_tempdir.r53dfo7rqFNJ/rustc_testrunner_tmpdir_reporting.0vPBTfW1Hynm/mvce.rs:2:21
  |
2 |     fn example(val: T);
  |                     ^ not found in this scope

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.r53dfo7rqFNJ/rustc_testrunner_tmpdir_reporting.0vPBTfW1Hynm/mvce.rs:11:2
   |
11 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.r53dfo7rqFNJ/rustc_testrunner_tmpdir_reporting.0vPBTfW1Hynm/mvce.rs`

error[E0185]: method `example` has a `&self` declaration in the impl, but not in the trait
 --> /tmp/icemaker_global_tempdir.r53dfo7rqFNJ/rustc_testrunner_tmpdir_reporting.0vPBTfW1Hynm/mvce.rs:8:5
  |
2 |     fn example(val: T);
  |     ------------------- trait method declared without `&self`
...
8 |     fn example(&self, input: &i32) {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&self` used in impl

thread 'rustc' panicked at compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs:703:60:
index out of bounds: the len is 1 but the index is 1
stack backtrace:
   0:     0x7f211a988476 - std::backtrace_rs::backtrace::libunwind::trace::h3f288a3148e8bb15
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f211a988476 - std::backtrace_rs::backtrace::trace_unsynchronized::h7277353061928bc0
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f211a988476 - std::sys_common::backtrace::_print_fmt::hbf79f06a8c92ca0e
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f211a988476 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0afd1ff8e38a8a84
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f211a9db030 - core::fmt::rt::Argument::fmt::h7f26a9b6a6522b09
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/core/src/fmt/rt.rs:142:9
   5:     0x7f211a9db030 - core::fmt::write::he7de9de816f98016
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f211a97bc6f - std::io::Write::write_fmt::h38e65bf4265dc66c
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/io/mod.rs:1854:15
   7:     0x7f211a988254 - std::sys_common::backtrace::_print::hf1424a842a74edeb
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f211a988254 - std::sys_common::backtrace::print::hbb43acdb160822bd
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f211a98b047 - std::panicking::default_hook::{{closure}}::h9c602a562527e529
  10:     0x7f211a98ada9 - std::panicking::default_hook::h9cb3bf5f6c73326f
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/panicking.rs:292:9
  11:     0x7f211775cfdc - std[73253c920228642]::panicking::update_hook::<alloc[940273873142bb35]::boxed::Box<rustc_driver_impl[f037f419b039420a]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f211a98b796 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h1e0fe9ec90d27cc3
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/alloc/src/boxed.rs:2030:9
  13:     0x7f211a98b796 - std::panicking::rust_panic_with_hook::hb5ad56797fd964c4
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/panicking.rs:785:13
  14:     0x7f211a98b4e2 - std::panicking::begin_panic_handler::{{closure}}::hd364aeee29433213
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/panicking.rs:659:13
  15:     0x7f211a988976 - std::sys_common::backtrace::__rust_end_short_backtrace::ha10bb1568b9ec73d
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f211a98b234 - rust_begin_unwind
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/panicking.rs:647:5
  17:     0x7f211a9d7785 - core::panicking::panic_fmt::h91fa7152f33c7717
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/core/src/panicking.rs:72:14
  18:     0x7f211a9d79d2 - core::panicking::panic_bounds_check::h0d1f1f7efe646722
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/core/src/panicking.rs:208:5
  19:     0x7f211757016b - <rustc_borrowck[80a3d1af88a5539b]::MirBorrowckCtxt>::suggest_make_local_mut
  20:     0x7f2117044ba7 - <rustc_borrowck[80a3d1af88a5539b]::MirBorrowckCtxt>::report_mutability_error
  21:     0x7f211986556b - rustc_borrowck[80a3d1af88a5539b]::do_mir_borrowck
  22:     0x7f211981bb8f - rustc_borrowck[80a3d1af88a5539b]::mir_borrowck
  23:     0x7f211981b5d9 - rustc_query_impl[b78e7f0549dc02d3]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b78e7f0549dc02d3]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dbb6cff8550fbced]::query::erase::Erased<[u8; 8usize]>>
  24:     0x7f2118b70bfa - rustc_query_system[74854bfa6cddafab]::query::plumbing::try_execute_query::<rustc_query_impl[b78e7f0549dc02d3]::DynamicConfig<rustc_query_system[74854bfa6cddafab]::query::caches::VecCache<rustc_span[a4806a91d128f927]::def_id::LocalDefId, rustc_middle[dbb6cff8550fbced]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[b78e7f0549dc02d3]::plumbing::QueryCtxt, false>
  25:     0x7f2118b70590 - rustc_query_impl[b78e7f0549dc02d3]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7f21193e0576 - rustc_interface[ceb207a8fb5539d]::passes::analysis
  27:     0x7f21193e005f - rustc_query_impl[b78e7f0549dc02d3]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b78e7f0549dc02d3]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dbb6cff8550fbced]::query::erase::Erased<[u8; 1usize]>>
  28:     0x7f21198c6064 - rustc_query_system[74854bfa6cddafab]::query::plumbing::try_execute_query::<rustc_query_impl[b78e7f0549dc02d3]::DynamicConfig<rustc_query_system[74854bfa6cddafab]::query::caches::SingleCache<rustc_middle[dbb6cff8550fbced]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[b78e7f0549dc02d3]::plumbing::QueryCtxt, false>
  29:     0x7f21198c5dc7 - rustc_query_impl[b78e7f0549dc02d3]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7f21197409fb - rustc_interface[ceb207a8fb5539d]::interface::run_compiler::<core[ed182bbac36ed604]::result::Result<(), rustc_span[a4806a91d128f927]::ErrorGuaranteed>, rustc_driver_impl[f037f419b039420a]::run_compiler::{closure#0}>::{closure#0}
  31:     0x7f211996ef12 - std[73253c920228642]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ceb207a8fb5539d]::util::run_in_thread_with_globals<rustc_interface[ceb207a8fb5539d]::util::run_in_thread_pool_with_globals<rustc_interface[ceb207a8fb5539d]::interface::run_compiler<core[ed182bbac36ed604]::result::Result<(), rustc_span[a4806a91d128f927]::ErrorGuaranteed>, rustc_driver_impl[f037f419b039420a]::run_compiler::{closure#0}>::{closure#0}, core[ed182bbac36ed604]::result::Result<(), rustc_span[a4806a91d128f927]::ErrorGuaranteed>>::{closure#0}, core[ed182bbac36ed604]::result::Result<(), rustc_span[a4806a91d128f927]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ed182bbac36ed604]::result::Result<(), rustc_span[a4806a91d128f927]::ErrorGuaranteed>>
  32:     0x7f211996ed3e - <<std[73253c920228642]::thread::Builder>::spawn_unchecked_<rustc_interface[ceb207a8fb5539d]::util::run_in_thread_with_globals<rustc_interface[ceb207a8fb5539d]::util::run_in_thread_pool_with_globals<rustc_interface[ceb207a8fb5539d]::interface::run_compiler<core[ed182bbac36ed604]::result::Result<(), rustc_span[a4806a91d128f927]::ErrorGuaranteed>, rustc_driver_impl[f037f419b039420a]::run_compiler::{closure#0}>::{closure#0}, core[ed182bbac36ed604]::result::Result<(), rustc_span[a4806a91d128f927]::ErrorGuaranteed>>::{closure#0}, core[ed182bbac36ed604]::result::Result<(), rustc_span[a4806a91d128f927]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ed182bbac36ed604]::result::Result<(), rustc_span[a4806a91d128f927]::ErrorGuaranteed>>::{closure#1} as core[ed182bbac36ed604]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7f211a994985 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h37d86e7af57ec8cf
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/alloc/src/boxed.rs:2016:9
  34:     0x7f211a994985 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h99a2218ed45ac1ce
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/alloc/src/boxed.rs:2016:9
  35:     0x7f211a994985 - std::sys::pal::unix::thread::Thread::new::thread_start::h6344e9d30547345d
                               at /rustc/b381d3ab27f788f990551100c4425bb782d26d76/library/std/src/sys/pal/unix/thread.rs:108:17
  36:     0x7f21148749eb - <unknown>
  37:     0x7f21148f87cc - <unknown>
  38:                0x0 - <unknown>

error: 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.78.0-nightly (b381d3ab2 2024-02-12) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `<impl at /tmp/icemaker_global_tempdir.r53dfo7rqFNJ/rustc_testrunner_tmpdir_reporting.0vPBTfW1Hynm/mvce.rs:7:1: 7:21>::example`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0185, E0412, E0601.
For more information about an error, try `rustc --explain E0185`.

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Feb 13, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 13, 2024
@matthiaskrgr
Copy link
Member Author

#120550 cc @oli-obk

@jieyouxu
Copy link
Contributor

@rustbot label +D-diagnostic-infra -needs-triage

@rustbot rustbot added D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 14, 2024
@bors bors closed this as completed in e5a743c Feb 16, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 16, 2024
Rollup merge of rust-lang#121020 - oli-obk:diagnostics_ice, r=davidtwco

Avoid an ICE in diagnostics

fixes rust-lang#121004

just a slice usage in diagnostics code. Sadly we can't yet bubble the `ErrorGuaranteed` from wf check to borrowck for these cases, as that causes cycle errors iirc
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. D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. 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.

3 participants