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: delegation: index out of bounds wfcheck #119920

Closed
matthiaskrgr opened this issue Jan 13, 2024 · 0 comments · Fixed by #122564
Closed

ICE: delegation: index out of bounds wfcheck #119920

matthiaskrgr opened this issue Jan 13, 2024 · 0 comments · Fixed by #122564
Labels
C-bug Category: This is a bug. F-fn_delegation `#![feature(fn_delegation)]` 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

snippet:

trait Trait {
    fn foo(&self) -> u32 { 0 }
}

struct F;

impl Trait for S {
    reuse to_reuse::foo { self }    
    reuse <F as Trait>::foo;
}

Version information

rustc 1.77.0-nightly (89110dafe 2024-01-13)
binary: rustc
commit-hash: 89110dafe79621fa07d6cd7c8493dd1d0a83cfaf
commit-date: 2024-01-13
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

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

Program output

error[E0201]: duplicate definitions with name `foo`:
 --> /tmp/icemaker_global_tempdir.pqDTncwD9B9h/rustc_testrunner_tmpdir_reporting.TJC3bXBXuUGV/mvce.rs:9:5
  |
2 |     fn foo(&self) -> u32 { 0 }
  |     -------------------------- item in trait
...
8 |     reuse to_reuse::foo { self }    
  |     ---------------------------- previous definition here
9 |     reuse <F as Trait>::foo;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definition

error[E0412]: cannot find type `S` in this scope
 --> /tmp/icemaker_global_tempdir.pqDTncwD9B9h/rustc_testrunner_tmpdir_reporting.TJC3bXBXuUGV/mvce.rs:7:16
  |
5 | struct F;
  | --------- similarly named struct `F` defined here
6 |
7 | impl Trait for S {
  |                ^ help: a struct with a similar name exists: `F`

error[E0658]: functions delegation is not yet fully implemented
 --> /tmp/icemaker_global_tempdir.pqDTncwD9B9h/rustc_testrunner_tmpdir_reporting.TJC3bXBXuUGV/mvce.rs:8:5
  |
8 |     reuse to_reuse::foo { self }    
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information
  = help: add `#![feature(fn_delegation)]` to the crate attributes to enable

error[E0658]: functions delegation is not yet fully implemented
 --> /tmp/icemaker_global_tempdir.pqDTncwD9B9h/rustc_testrunner_tmpdir_reporting.TJC3bXBXuUGV/mvce.rs:9:5
  |
9 |     reuse <F as Trait>::foo;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information
  = help: add `#![feature(fn_delegation)]` to the crate attributes to enable

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

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/check/wfcheck.rs:1571:16:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0:     0x7fcb94c207e6 - std::backtrace_rs::backtrace::libunwind::trace::h4f92a9ab1e969130
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fcb94c207e6 - std::backtrace_rs::backtrace::trace_unsynchronized::hff5adbaff3a8cfb8
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fcb94c207e6 - std::sys_common::backtrace::_print_fmt::h9d3e0e63f6f89eaf
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fcb94c207e6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2d31e6c8aa8ef934
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fcb94c72ec0 - core::fmt::rt::Argument::fmt::hd4eaf83b012a42ab
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/core/src/fmt/rt.rs:142:9
   5:     0x7fcb94c72ec0 - core::fmt::write::hb507e806b3ae16c4
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fcb94c1414f - std::io::Write::write_fmt::h203bf95b6a67c7a0
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/io/mod.rs:1810:15
   7:     0x7fcb94c205c4 - std::sys_common::backtrace::_print::h2f732cf10966ea1c
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fcb94c205c4 - std::sys_common::backtrace::print::hef45416e244164df
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fcb94c23357 - std::panicking::default_hook::{{closure}}::h1a73802a0a993acf
  10:     0x7fcb94c230b9 - std::panicking::default_hook::h34548737700c4b4d
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/panicking.rs:292:9
  11:     0x7fcb9194e80c - std[d6f21989bfff4f42]::panicking::update_hook::<alloc[21b544e6cc75226b]::boxed::Box<rustc_driver_impl[bce72efeea91a1de]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fcb94c23aa6 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb0b823449909a650
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/alloc/src/boxed.rs:2030:9
  13:     0x7fcb94c23aa6 - std::panicking::rust_panic_with_hook::h60e4310ab2a16e4e
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/panicking.rs:785:13
  14:     0x7fcb94c237f2 - std::panicking::begin_panic_handler::{{closure}}::h61737518028fa2b2
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/panicking.rs:659:13
  15:     0x7fcb94c20ce6 - std::sys_common::backtrace::__rust_end_short_backtrace::h7870f48bedce1dac
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7fcb94c23550 - rust_begin_unwind
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/panicking.rs:647:5
  17:     0x7fcb94c6f5c5 - core::panicking::panic_fmt::h01c3f6a1955aca70
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/core/src/panicking.rs:72:14
  18:     0x7fcb94c6f802 - core::panicking::panic_bounds_check::h25b685aaca1db28e
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/core/src/panicking.rs:208:5
  19:     0x7fcb9329bc85 - rustc_hir_analysis[f88d56455d931b67]::check::wfcheck::check_associated_item
  20:     0x7fcb933bd4e2 - rustc_hir_analysis[f88d56455d931b67]::check::wfcheck::check_well_formed
  21:     0x7fcb933bc30d - rustc_query_impl[f8b584d7216df600]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f8b584d7216df600]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[63813a132a817cd4]::query::erase::Erased<[u8; 1usize]>>
  22:     0x7fcb933bba0b - rustc_query_system[13649e0efc92577a]::query::plumbing::try_execute_query::<rustc_query_impl[f8b584d7216df600]::DynamicConfig<rustc_query_system[13649e0efc92577a]::query::caches::VecCache<rustc_hir[4458c78f2716492d]::hir_id::OwnerId, rustc_middle[63813a132a817cd4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f8b584d7216df600]::plumbing::QueryCtxt, false>
  23:     0x7fcb933bb783 - rustc_query_impl[f8b584d7216df600]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7fcb933b92fd - rustc_hir_analysis[f88d56455d931b67]::check::wfcheck::check_mod_type_wf
  25:     0x7fcb933b907b - rustc_query_impl[f8b584d7216df600]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f8b584d7216df600]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[63813a132a817cd4]::query::erase::Erased<[u8; 1usize]>>
  26:     0x7fcb933b823b - rustc_query_system[13649e0efc92577a]::query::plumbing::try_execute_query::<rustc_query_impl[f8b584d7216df600]::DynamicConfig<rustc_query_system[13649e0efc92577a]::query::caches::DefaultCache<rustc_span[6e44e330265df079]::def_id::LocalModDefId, rustc_middle[63813a132a817cd4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f8b584d7216df600]::plumbing::QueryCtxt, false>
  27:     0x7fcb933b7fd1 - rustc_query_impl[f8b584d7216df600]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7fcb931e9eb0 - <rustc_middle[63813a132a817cd4]::hir::map::Map>::try_par_for_each_module::<rustc_hir_analysis[f88d56455d931b67]::check_crate::{closure#4}::{closure#0}>::{closure#0}
  29:     0x7fcb931e8190 - rustc_hir_analysis[f88d56455d931b67]::check_crate
  30:     0x7fcb93694419 - rustc_interface[37b6cebe1bce16]::passes::analysis
  31:     0x7fcb9369405f - rustc_query_impl[f8b584d7216df600]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f8b584d7216df600]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[63813a132a817cd4]::query::erase::Erased<[u8; 1usize]>>
  32:     0x7fcb93bcd040 - rustc_query_system[13649e0efc92577a]::query::plumbing::try_execute_query::<rustc_query_impl[f8b584d7216df600]::DynamicConfig<rustc_query_system[13649e0efc92577a]::query::caches::SingleCache<rustc_middle[63813a132a817cd4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f8b584d7216df600]::plumbing::QueryCtxt, false>
  33:     0x7fcb93bcce47 - rustc_query_impl[f8b584d7216df600]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7fcb939343ed - rustc_interface[37b6cebe1bce16]::interface::run_compiler::<core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>, rustc_driver_impl[bce72efeea91a1de]::run_compiler::{closure#0}>::{closure#0}
  35:     0x7fcb93bf3546 - std[d6f21989bfff4f42]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[37b6cebe1bce16]::util::run_in_thread_with_globals<rustc_interface[37b6cebe1bce16]::util::run_in_thread_pool_with_globals<rustc_interface[37b6cebe1bce16]::interface::run_compiler<core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>, rustc_driver_impl[bce72efeea91a1de]::run_compiler::{closure#0}>::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>
  36:     0x7fcb93bf3373 - <<std[d6f21989bfff4f42]::thread::Builder>::spawn_unchecked_<rustc_interface[37b6cebe1bce16]::util::run_in_thread_with_globals<rustc_interface[37b6cebe1bce16]::util::run_in_thread_pool_with_globals<rustc_interface[37b6cebe1bce16]::interface::run_compiler<core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>, rustc_driver_impl[bce72efeea91a1de]::run_compiler::{closure#0}>::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>::{closure#1} as core[a757d3bbb7cc29b8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  37:     0x7fcb94c2d9d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc62465ce3696edbb
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/alloc/src/boxed.rs:2016:9
  38:     0x7fcb94c2d9d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2898b364df1453ed
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/alloc/src/boxed.rs:2016:9
  39:     0x7fcb94c2d9d5 - std::sys::unix::thread::Thread::new::thread_start::hefe0ce868779f0f1
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys/unix/thread.rs:108:17
  40:     0x7fcb8eaaa9eb - <unknown>
  41:     0x7fcb8eb2e7cc - <unknown>
  42:                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.77.0-nightly (89110dafe 2024-01-13) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.pqDTncwD9B9h/rustc_testrunner_tmpdir_reporting.TJC3bXBXuUGV/mvce.rs:7:1: 7:17>::foo` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error[E0433]: failed to resolve: use of undeclared crate or module `to_reuse`
 --> /tmp/icemaker_global_tempdir.pqDTncwD9B9h/rustc_testrunner_tmpdir_reporting.TJC3bXBXuUGV/mvce.rs:8:11
  |
8 |     reuse to_reuse::foo { self }    
  |           ^^^^^^^^ use of undeclared crate or module `to_reuse`

error: aborting due to 6 previous errors

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

@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 Jan 13, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 13, 2024
@fmease fmease added F-fn_delegation `#![feature(fn_delegation)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 13, 2024
@bors bors closed this as completed in 7b7a7fc Mar 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 17, 2024
Rollup merge of rust-lang#122564 - Bryanskiy:delegation-fixes, r=compiler-errors

Delegation: fix ICE on duplicated associative items

Currently, functions delegation is only supported for delegation items with early resolved paths e.g. free functions and trait methods. During name resolution, information about function signatures is collected, including the number of parameters and whether there are self arguments. This information is then used when lowering from a delegation item into a regular function(`rustc_ast_lowering/src/delegation.rs`). The signature is usually inherited from path resolution id(`path_id`). However, in the case of trait impls `path_id` and `item_id` may be different:

```rust
trait Trait {
    fn foo(&self) -> u32 { 0 }
}

struct S;

mod to_reuse {
    use crate::S;

    pub fn foo(_: &S) -> u32 { 0 }
}

impl Trait for S {
    reuse to_reuse::foo { self }
    //~^ The signature should be inherited from item id instead of resolution id
}

```

Let's now consider an example from [issue](rust-lang#119920). Due to duplicated associative elements partial resolution for one of them will not be recorded:

https://github.com/rust-lang/rust/blob/9023f908cfbe7a475f369717a61cb8eb865cfd25/compiler/rustc_resolve/src/late.rs#L3153-L3162

Which leads to an incorrect `is_in_trait_impl`

https://github.com/rust-lang/rust/blob/9023f908cfbe7a475f369717a61cb8eb865cfd25/compiler/rustc_ast_lowering/src/item.rs#L981-L986

Which leads to an incorrect id for signature inheritance

https://github.com/rust-lang/rust/blob/9023f908cfbe7a475f369717a61cb8eb865cfd25/compiler/rustc_ast_lowering/src/delegation.rs#L99-L105

Which lead to an ICE from original issue.

This patch fixes wrong `is_in_trait_impl`  calculation.

fixes rust-lang#119920
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. F-fn_delegation `#![feature(fn_delegation)]` 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