Repository: rust
Issue: ICE: `expected item, found (root_crate)`
Labels: I-ICE,T-compiler,C-bug,S-has-mcve,S-bug-has-test,F-fn_delegation

<!--
[31mICE[0m: Rustc ./a.rs '' 'error: internal compiler error: compiler/rustc_middle/src/hir/map/mod.rs:694:18: expected item, found (root_crate)', 'error: internal compiler error: compiler/rustc_middle/src/hir/map/mod.rs:694:18: expected item, found (root_crate)'
File: /tmp/im/a.rs
-->

auto-reduced (treereduce-rust):
````rust
fn a(&self) {
    15
}

reuse a as b {  struct S; }


````

original:
````rust
#![rustc_dummy]
#![allow(as)]

fn a(&self) { 15 }

reuse a as b { #![feature(fn_delegation)] struct S; }

fn main(self) {
    const_fn();
    const_fn_extern();
}

````

Version information
````
rustc 1.82.0-nightly (54be9ad5e 2024-07-25)
binary: rustc
commit-hash: 54be9ad5eb47207d155904f6c912a9526133f75f
commit-date: 2024-07-25
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7

````

Command:
`/home/matthias/.rustup/toolchains/master/bin/rustc `

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Program output</strong></summary>
<p>

```
error: `self` parameter is only allowed in associated functions
 --> /tmp/icemaker_global_tempdir.Xm44oviEaTg6/rustc_testrunner_tmpdir_reporting.4oFYSg3eBqPr/mvce.rs:1:6
  |
1 | fn a(&self) {
  |      ^^^^^ not semantically valid as function parameter
  |
  = note: associated functions are those in `impl` or `trait` definitions

error[E0658]: functions delegation is not yet fully implemented
 --> /tmp/icemaker_global_tempdir.Xm44oviEaTg6/rustc_testrunner_tmpdir_reporting.4oFYSg3eBqPr/mvce.rs:5:1
  |
5 | reuse a as b {  struct S; }
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = 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 2024-07-25; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.Xm44oviEaTg6/rustc_testrunner_tmpdir_reporting.4oFYSg3eBqPr/mvce.rs:5:28
  |
5 | reuse a as b {  struct S; }
  |                            ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.Xm44oviEaTg6/rustc_testrunner_tmpdir_reporting.4oFYSg3eBqPr/mvce.rs`

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.Xm44oviEaTg6/rustc_testrunner_tmpdir_reporting.4oFYSg3eBqPr/mvce.rs:2:5
  |
1 | fn a(&self) {
  |            - help: try adding a return type: `-> i32`
2 |     15
  |     ^^ expected `()`, found integer

error: internal compiler error: compiler/rustc_middle/src/hir/map/mod.rs:694:18: expected item, found (root_crate)

thread 'rustc' panicked at compiler/rustc_middle/src/hir/map/mod.rs:694:18:
Box<dyn Any>
stack backtrace:
   0:     0x7adb2a44a015 - std::backtrace_rs::backtrace::libunwind::trace::h40979b3cf07e4302
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7adb2a44a015 - std::backtrace_rs::backtrace::trace_unsynchronized::hc25be74c83b982ea
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7adb2a44a015 - std::sys::backtrace::_print_fmt::he0e7b21c916cf37e
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/std/src/sys/backtrace.rs:68:9
   3:     0x7adb2a44a015 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hdae9b4b38b07800f
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/std/src/sys/backtrace.rs:41:26
   4:     0x7adb2a4999eb - core::fmt::rt::Argument::fmt::h23f55724cbf6fed3
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/core/src/fmt/rt.rs:173:76
   5:     0x7adb2a4999eb - core::fmt::write::heb69bd2b65d4670c
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/core/src/fmt/mod.rs:1182:21
   6:     0x7adb2a43e85f - std::io::Write::write_fmt::hb10e609dc145c64e
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/std/src/io/mod.rs:1827:15
   7:     0x7adb2a44c801 - std::sys::backtrace::BacktraceLock::print::h151b0d7b810486c7
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/std/src/sys/backtrace.rs:44:9
   8:     0x7adb2a44c801 - std::panicking::default_hook::{{closure}}::h6076738be33ec9e8
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/std/src/panicking.rs:269:22
   9:     0x7adb2a44c4dc - std::panicking::default_hook::h304663758ec021ea
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/std/src/panicking.rs:296:9
  10:     0x7adb268333da - std[f69981ba459e4be9]::panicking::update_hook::<alloc[5611d3b43b061168]::boxed::Box<rustc_driver_impl[a70ed56c5c805152]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7adb2a44d1cf - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3898ed4990ae07d7
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/alloc/src/boxed.rs:2163:9
  12:     0x7adb2a44d1cf - std::panicking::rust_panic_with_hook::hb301fa95c486ca11
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/std/src/panicking.rs:808:13
  13:     0x7adb2686d981 - std[f69981ba459e4be9]::panicking::begin_panic::<rustc_errors[3ba03a0031862738]::ExplicitBug>::{closure#0}
  14:     0x7adb26860936 - std[f69981ba459e4be9]::sys::backtrace::__rust_end_short_backtrace::<std[f69981ba459e4be9]::panicking::begin_panic<rustc_errors[3ba03a0031862738]::ExplicitBug>::{closure#0}, !>
  15:     0x7adb268608e6 - std[f69981ba459e4be9]::panicking::begin_panic::<rustc_errors[3ba03a0031862738]::ExplicitBug>
  16:     0x7adb26876fc1 - <rustc_errors[3ba03a0031862738]::diagnostic::BugAbort as rustc_errors[3ba03a0031862738]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  17:     0x7adb26e21414 - rustc_middle[eb4fa39c1860cd4]::util::bug::opt_span_bug_fmt::<rustc_span[b68f95fc1bdef1eb]::span_encoding::Span>::{closure#0}
  18:     0x7adb26e0707a - rustc_middle[eb4fa39c1860cd4]::ty::context::tls::with_opt::<rustc_middle[eb4fa39c1860cd4]::util::bug::opt_span_bug_fmt<rustc_span[b68f95fc1bdef1eb]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  19:     0x7adb26e06f1b - rustc_middle[eb4fa39c1860cd4]::ty::context::tls::with_context_opt::<rustc_middle[eb4fa39c1860cd4]::ty::context::tls::with_opt<rustc_middle[eb4fa39c1860cd4]::util::bug::opt_span_bug_fmt<rustc_span[b68f95fc1bdef1eb]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  20:     0x7adb24c0ce30 - rustc_middle[eb4fa39c1860cd4]::util::bug::bug_fmt
  21:     0x7adb2816e840 - <rustc_middle[eb4fa39c1860cd4]::hir::map::Map>::expect_item
  22:     0x7adb280fa8d7 - rustc_query_impl[abbe88964be750a7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[abbe88964be750a7]::query_impl::associated_item::dynamic_query::{closure#2}::{closure#0}, rustc_middle[eb4fa39c1860cd4]::query::erase::Erased<[u8; 40usize]>>
  23:     0x7adb280f9bc2 - rustc_query_system[274de9dac1528dd3]::query::plumbing::try_execute_query::<rustc_query_impl[abbe88964be750a7]::DynamicConfig<rustc_query_system[274de9dac1528dd3]::query::caches::DefIdCache<rustc_middle[eb4fa39c1860cd4]::query::erase::Erased<[u8; 40usize]>>, false, false, false>, rustc_query_impl[abbe88964be750a7]::plumbing::QueryCtxt, false>
  24:     0x7adb280f98a3 - rustc_query_impl[abbe88964be750a7]::query_impl::associated_item::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7adb26a4e47d - rustc_middle[eb4fa39c1860cd4]::query::plumbing::query_get_at::<rustc_query_system[274de9dac1528dd3]::query::caches::DefIdCache<rustc_middle[eb4fa39c1860cd4]::query::erase::Erased<[u8; 40usize]>>>
  26:     0x7adb24759446 - <rustc_hir_typeck[9ad8e17cc0d5c271]::fn_ctxt::FnCtxt>::lookup_probe
  27:     0x7adb28847e69 - <rustc_hir_typeck[9ad8e17cc0d5c271]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x7adb288416f5 - <rustc_hir_typeck[9ad8e17cc0d5c271]::fn_ctxt::FnCtxt>::check_block_with_expected
  29:     0x7adb28847d5d - <rustc_hir_typeck[9ad8e17cc0d5c271]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30:     0x7adb28062dcf - rustc_hir_typeck[9ad8e17cc0d5c271]::check::check_fn
  31:     0x7adb28059183 - rustc_hir_typeck[9ad8e17cc0d5c271]::typeck
  32:     0x7adb28058b29 - rustc_query_impl[abbe88964be750a7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[abbe88964be750a7]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[eb4fa39c1860cd4]::query::erase::Erased<[u8; 8usize]>>
  33:     0x7adb2806c2f3 - rustc_query_system[274de9dac1528dd3]::query::plumbing::try_execute_query::<rustc_query_impl[abbe88964be750a7]::DynamicConfig<rustc_query_system[274de9dac1528dd3]::query::caches::VecCache<rustc_span[b68f95fc1bdef1eb]::def_id::LocalDefId, rustc_middle[eb4fa39c1860cd4]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[abbe88964be750a7]::plumbing::QueryCtxt, false>
  34:     0x7adb2806b4cd - rustc_query_impl[abbe88964be750a7]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7adb2806b0c4 - <rustc_middle[eb4fa39c1860cd4]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[40d7e38617de2bd]::check_crate::{closure#4}>::{closure#0}
  36:     0x7adb28068efc - rustc_hir_analysis[40d7e38617de2bd]::check_crate
  37:     0x7adb28a2a815 - rustc_interface[73e2d76034883eaa]::passes::analysis
  38:     0x7adb28a2a3db - rustc_query_impl[abbe88964be750a7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[abbe88964be750a7]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[eb4fa39c1860cd4]::query::erase::Erased<[u8; 1usize]>>
  39:     0x7adb28c5f8a5 - rustc_query_system[274de9dac1528dd3]::query::plumbing::try_execute_query::<rustc_query_impl[abbe88964be750a7]::DynamicConfig<rustc_query_system[274de9dac1528dd3]::query::caches::SingleCache<rustc_middle[eb4fa39c1860cd4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[abbe88964be750a7]::plumbing::QueryCtxt, false>
  40:     0x7adb28c5f60f - rustc_query_impl[abbe88964be750a7]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7adb28b5e185 - rustc_interface[73e2d76034883eaa]::interface::run_compiler::<core[4b0752be9b74dadf]::result::Result<(), rustc_span[b68f95fc1bdef1eb]::ErrorGuaranteed>, rustc_driver_impl[a70ed56c5c805152]::run_compiler::{closure#0}>::{closure#1}
  42:     0x7adb28b44689 - std[f69981ba459e4be9]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[73e2d76034883eaa]::util::run_in_thread_with_globals<rustc_interface[73e2d76034883eaa]::util::run_in_thread_pool_with_globals<rustc_interface[73e2d76034883eaa]::interface::run_compiler<core[4b0752be9b74dadf]::result::Result<(), rustc_span[b68f95fc1bdef1eb]::ErrorGuaranteed>, rustc_driver_impl[a70ed56c5c805152]::run_compiler::{closure#0}>::{closure#1}, core[4b0752be9b74dadf]::result::Result<(), rustc_span[b68f95fc1bdef1eb]::ErrorGuaranteed>>::{closure#0}, core[4b0752be9b74dadf]::result::Result<(), rustc_span[b68f95fc1bdef1eb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[4b0752be9b74dadf]::result::Result<(), rustc_span[b68f95fc1bdef1eb]::ErrorGuaranteed>>
  43:     0x7adb28b4443a - <<std[f69981ba459e4be9]::thread::Builder>::spawn_unchecked_<rustc_interface[73e2d76034883eaa]::util::run_in_thread_with_globals<rustc_interface[73e2d76034883eaa]::util::run_in_thread_pool_with_globals<rustc_interface[73e2d76034883eaa]::interface::run_compiler<core[4b0752be9b74dadf]::result::Result<(), rustc_span[b68f95fc1bdef1eb]::ErrorGuaranteed>, rustc_driver_impl[a70ed56c5c805152]::run_compiler::{closure#0}>::{closure#1}, core[4b0752be9b74dadf]::result::Result<(), rustc_span[b68f95fc1bdef1eb]::ErrorGuaranteed>>::{closure#0}, core[4b0752be9b74dadf]::result::Result<(), rustc_span[b68f95fc1bdef1eb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[4b0752be9b74dadf]::result::Result<(), rustc_span[b68f95fc1bdef1eb]::ErrorGuaranteed>>::{closure#1} as core[4b0752be9b74dadf]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  44:     0x7adb2a45711b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h00bda9a3a6915a28
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/alloc/src/boxed.rs:2149:9
  45:     0x7adb2a45711b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3ee855f42fb95cb5
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/alloc/src/boxed.rs:2149:9
  46:     0x7adb2a45711b - std::sys::pal::unix::thread::Thread::new::thread_start::h31514268db3ccba4
                               at /rustc/54be9ad5eb47207d155904f6c912a9526133f75f/library/std/src/sys/pal/unix/thread.rs:108:17
  47:     0x7adb2a1eaded - <unknown>
  48:     0x7adb2a26e0dc - <unknown>
  49:                0x0 - <unknown>

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.82.0-nightly (54be9ad5e 2024-07-25) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [associated_item] computing associated item data for `a`
#1 [typeck] type-checking `b`
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0308, E0601, E0658.
For more information about an error, try `rustc --explain E0308`.

```

</p>
</details>

<!--
query stack:
#0 [associated_item] computing associated item data for `a`
#1 [typeck] type-checking `b`

-->
@rustbot label +F-fn_delegation