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 #138362

Closed
matthiaskrgr opened this issue Mar 11, 2025 · 3 comments · Fixed by #138403
Closed

ICE: delegation: index out of bounds #138362

matthiaskrgr opened this issue Mar 11, 2025 · 3 comments · Fixed by #138403
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

auto-reduced (treereduce-rust):

mod inner {
    pub trait TraitFoo {
        fn foo(&self) -> u8;
    }
    

    
    
}

trait Trait {
    fn foo<T>();
    
}

impl Trait for u8 {
    reuse inner::TraitFoo::*;
    ;
}

original:

//@ check-pass

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

mod inner {
    pub trait TraitFoo {
        fn foo(&self) -> u8;
    }
    pub trait TraitBar {
        fn bar(&self) -> u8;
    }

    impl TraitFoo for u8 {
        fn foo(&self) -> u8 { 0 }
    }
    impl TraitBar for u8 {
        fn bar(&self) -> u8 { 1 }
    }
}

trait Trait {
    fn foo<T>();
    fn bar(&self) -> u8;
}

impl Trait for u8 {
    reuse inner::TraitFoo::*;
    reuse inner::TraitBar::*;
}

fn main() {
    let u = 0u8;
    u.foo();
    u.bar();
}

Version information

rustc 1.87.0-nightly (ebf0cf75d 2025-03-11)
binary: rustc
commit-hash: ebf0cf75d368c035f4c7e7246d203bd469ee4a51
commit-date: 2025-03-11
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:

None,
);
let segment = self.arena.alloc(segment);
self.arena.alloc(hir::Expr {
hir_id: self.next_id(),
kind: hir::ExprKind::MethodCall(segment, &args[0], &args[1..], span),
span,
})
} else {
let path = self.lower_qpath(
delegation.id,
&delegation.qself,

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

Program output

error: non-item in item list
  --> /tmp/icemaker_global_tempdir.vsOshhe321Ji/rustc_testrunner_tmpdir_reporting.25P4hBretFbI/mvce.rs:23:5
   |
21 | impl Trait for u8 {
   |                   - item list starts here
22 |     reuse inner::TraitFoo::*;
23 |     ;
   |     ^ non-item starts here
24 | }
   | - item list ends here

error[E0658]: functions delegation is not yet fully implemented
  --> /tmp/icemaker_global_tempdir.vsOshhe321Ji/rustc_testrunner_tmpdir_reporting.25P4hBretFbI/mvce.rs:22:5
   |
22 |     reuse inner::TraitFoo::*;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = 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
   = note: this compiler was built on 2025-03-11; consider upgrading it if it is out of date


thread 'rustc' panicked at compiler/rustc_ast_lowering/src/delegation.rs:347:59:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0:     0x798183825b33 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h7fb80f6afbe41a33
   1:     0x7981840059d8 - core::fmt::write::h000527be0eea6fe8
   2:     0x79818544ffd1 - std::io::Write::write_fmt::h4991a22851475fb5
   3:     0x798183825992 - std::sys::backtrace::BacktraceLock::print::hffad87dde00cbe3e
   4:     0x7981838282b8 - std::panicking::default_hook::{{closure}}::ha46397973bec1239
   5:     0x798183827dd7 - std::panicking::default_hook::h706de72a1550eed4
   6:     0x798182893abf - std[ea0914bf68e3efbf]::panicking::update_hook::<alloc[3dfe61f71ba45cfe]::boxed::Box<rustc_driver_impl[23cd132fe59c5dfc]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x798183828b23 - std::panicking::rust_panic_with_hook::h6666776865bd21f5
   8:     0x79818382881a - std::panicking::begin_panic_handler::{{closure}}::hb8595612365d24db
   9:     0x798183825ff9 - std::sys::backtrace::__rust_end_short_backtrace::h7037f177c7ae4ed3
  10:     0x7981838284dd - rust_begin_unwind
  11:     0x798180270ea0 - core::panicking::panic_fmt::hd26142fa9828e2a3
  12:     0x7981819eb70c - core::panicking::panic_bounds_check::hd986af7ff0a8c80a
  13:     0x79818247dda3 - <rustc_ast_lowering[e55d79e744b523df]::LoweringContext>::lower_delegation
  14:     0x7981847b3538 - <rustc_ast_lowering[e55d79e744b523df]::LoweringContext>::lower_assoc_item
  15:     0x7981844c6d96 - <rustc_ast_lowering[e55d79e744b523df]::item::ItemLowerer>::lower_node
  16:     0x7981844c4b54 - rustc_ast_lowering[e55d79e744b523df]::lower_to_hir
  17:     0x79818511f9a2 - rustc_query_impl[977456df771add7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[977456df771add7]::query_impl::hir_crate::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8b56cfa39295cc9e]::query::erase::Erased<[u8; 8usize]>>
  18:     0x79818511dbc7 - rustc_query_system[f942f53a11d60297]::query::plumbing::try_execute_query::<rustc_query_impl[977456df771add7]::DynamicConfig<rustc_query_system[f942f53a11d60297]::query::caches::SingleCache<rustc_middle[8b56cfa39295cc9e]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[977456df771add7]::plumbing::QueryCtxt, false>
  19:     0x79818511d841 - rustc_query_impl[977456df771add7]::query_impl::hir_crate::get_query_non_incr::__rust_end_short_backtrace
  20:     0x79818449025e - rustc_query_impl[977456df771add7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[977456df771add7]::query_impl::hir_attrs::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8b56cfa39295cc9e]::query::erase::Erased<[u8; 8usize]>>
  21:     0x79818448f879 - rustc_query_system[f942f53a11d60297]::query::plumbing::try_execute_query::<rustc_query_impl[977456df771add7]::DynamicConfig<rustc_data_structures[a5b0ed65aaf1af1]::vec_cache::VecCache<rustc_hir[9c8f1de648b82ae]::hir_id::OwnerId, rustc_middle[8b56cfa39295cc9e]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[f942f53a11d60297]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[977456df771add7]::plumbing::QueryCtxt, false>
  22:     0x79818448f5cd - rustc_query_impl[977456df771add7]::query_impl::hir_attrs::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7981844812f5 - <rustc_middle[8b56cfa39295cc9e]::hir::map::Map>::attrs
  24:     0x798185367b00 - rustc_passes[e91b22d0fd073176]::entry::entry_fn
  25:     0x798185367a98 - rustc_query_impl[977456df771add7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[977456df771add7]::query_impl::entry_fn::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8b56cfa39295cc9e]::query::erase::Erased<[u8; 12usize]>>
  26:     0x798185367a73 - <rustc_query_impl[977456df771add7]::query_impl::entry_fn::dynamic_query::{closure#2} as core[72d9f83855d8cc5b]::ops::function::FnOnce<(rustc_middle[8b56cfa39295cc9e]::ty::context::TyCtxt, ())>>::call_once
  27:     0x7981853673e4 - rustc_query_system[f942f53a11d60297]::query::plumbing::try_execute_query::<rustc_query_impl[977456df771add7]::DynamicConfig<rustc_query_system[f942f53a11d60297]::query::caches::SingleCache<rustc_middle[8b56cfa39295cc9e]::query::erase::Erased<[u8; 12usize]>>, false, false, false>, rustc_query_impl[977456df771add7]::plumbing::QueryCtxt, false>
  28:     0x79818536718f - rustc_query_impl[977456df771add7]::query_impl::entry_fn::get_query_non_incr::__rust_end_short_backtrace
  29:     0x798184452be9 - rustc_interface[15b2602f89c3a5c0]::passes::run_required_analyses
  30:     0x798184ffa6f8 - rustc_interface[15b2602f89c3a5c0]::passes::analysis
  31:     0x798184ffa6d7 - rustc_query_impl[977456df771add7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[977456df771add7]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8b56cfa39295cc9e]::query::erase::Erased<[u8; 0usize]>>
  32:     0x79818511c981 - rustc_query_system[f942f53a11d60297]::query::plumbing::try_execute_query::<rustc_query_impl[977456df771add7]::DynamicConfig<rustc_query_system[f942f53a11d60297]::query::caches::SingleCache<rustc_middle[8b56cfa39295cc9e]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[977456df771add7]::plumbing::QueryCtxt, false>
  33:     0x79818511c674 - rustc_query_impl[977456df771add7]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  34:     0x79818535bfbc - rustc_interface[15b2602f89c3a5c0]::passes::create_and_enter_global_ctxt::<core[72d9f83855d8cc5b]::option::Option<rustc_interface[15b2602f89c3a5c0]::queries::Linker>, rustc_driver_impl[23cd132fe59c5dfc]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  35:     0x798185174c97 - rustc_interface[15b2602f89c3a5c0]::interface::run_compiler::<(), rustc_driver_impl[23cd132fe59c5dfc]::run_compiler::{closure#0}>::{closure#1}
  36:     0x798184fd97c8 - std[ea0914bf68e3efbf]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[15b2602f89c3a5c0]::util::run_in_thread_with_globals<rustc_interface[15b2602f89c3a5c0]::util::run_in_thread_pool_with_globals<rustc_interface[15b2602f89c3a5c0]::interface::run_compiler<(), rustc_driver_impl[23cd132fe59c5dfc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  37:     0x798184fda0b4 - <<std[ea0914bf68e3efbf]::thread::Builder>::spawn_unchecked_<rustc_interface[15b2602f89c3a5c0]::util::run_in_thread_with_globals<rustc_interface[15b2602f89c3a5c0]::util::run_in_thread_pool_with_globals<rustc_interface[15b2602f89c3a5c0]::interface::run_compiler<(), rustc_driver_impl[23cd132fe59c5dfc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[72d9f83855d8cc5b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x798184fdb4b7 - std::sys::pal::unix::thread::Thread::new::thread_start::ha1530b93ff336c49
  39:     0x79817eea370a - <unknown>
  40:     0x79817ef27aac - <unknown>
  41:                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: please make sure that you have updated to the latest nightly

note: rustc 1.87.0-nightly (ebf0cf75d 2025-03-11) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [hir_crate] getting the crate HIR
#1 [hir_attrs] getting HIR owner attributes in ``
#2 [entry_fn] looking up the entry function of a crate
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

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

@rustbot label +F-fn_delegation

@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 Mar 11, 2025
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-fn_delegation `#![feature(fn_delegation)]` labels Mar 11, 2025
@matthiaskrgr
Copy link
Member Author

smaller:

mod a {
    pub trait b {
        fn c(self);
    }
}
trait d {
    fn c();
    
}
impl d for e {
    reuse a::b::*;
}

@petrochenkov
Copy link
Contributor

petrochenkov commented Mar 11, 2025

Likely fixed by #138278.

Further minimized and cleaned up from non-relevant diagnostics:

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

trait HasSelf {
    fn method(self);
}
trait NoSelf {
    fn method();
}
impl NoSelf for u8 {
    reuse HasSelf::method;
}

@matthiaskrgr
Copy link
Member Author

Likely fixed

ebf0cf7 already includes #138278

@bors bors closed this as completed in 8d28328 Mar 13, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 13, 2025
Rollup merge of rust-lang#138403 - Bryanskiy:delegation-ice-2, r=petrochenkov

Delegation: one more ICE fix for `MethodCall` generation

self-explanatory

Fixes rust-lang#138362

r? `@petrochenkov`
jieyouxu pushed a commit to jieyouxu/rustc-dev-guide that referenced this issue Mar 13, 2025
Delegation: one more ICE fix for `MethodCall` generation

self-explanatory

Fixes rust-lang/rust#138362

r? `@petrochenkov`
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 26, 2025
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.

4 participants