Repository: rust
Issue: ICE with `proc_macro_expand`: no entry found for key
Labels: I-ICE,A-macros,T-compiler,C-bug,requires-nightly,A-proc-macros,F-proc_macro_expand

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

proc.rs:
```rust
#![feature(proc_macro_expand)]

extern crate proc_macro;

#[proc_macro]
pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    dbg!(input.expand_expr()).unwrap_or_default()
}
```

bug.rs:
```rust
proc::expand!(include!("./doesnt_exist"));

fn main() {}
```

Command:
```shell
rustc --crate-type=proc-macro proc.rs && rustc bug.rs --extern proc=libproc.so
```

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.73.0-nightly (0bdb00d55 2023-08-15)
binary: rustc
commit-hash: 0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab
commit-date: 2023-08-15
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 17.0.0
```

### Error output

```
error: couldn't read ./doesnt_exist: No such file or directory (os error 2)
 --> bug.rs:1:15
  |
1 | proc::expand!(include!("./doesnt_exist"));
  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info)

error: proc macro panicked
 --> bug.rs:1:1
  |
1 | proc::expand!(include!("./doesnt_exist"));
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

<!--
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>Backtrace</strong></summary>
<p>

```
thread 'rustc' panicked at compiler/rustc_resolve/src/def_collector.rs:16:71:
no entry found for key
stack backtrace:
   0:     0x7fa65a5634dc - std::backtrace_rs::backtrace::libunwind::trace::h1a52aadab1e423ed
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fa65a5634dc - std::backtrace_rs::backtrace::trace_unsynchronized::h6ba22d133698223c
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fa65a5634dc - std::sys_common::backtrace::_print_fmt::h109a934708356281
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fa65a5634dc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h616cb33c77b3507c
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fa65a5c962c - core::fmt::rt::Argument::fmt::hc5b672822529f326
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/core/src/fmt/rt.rs:138:9
   5:     0x7fa65a5c962c - core::fmt::write::h65d66d3303e2b93b
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/core/src/fmt/mod.rs:1094:21
   6:     0x7fa65a555f6e - std::io::Write::write_fmt::h6c1f4b97f011d41f
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/io/mod.rs:1714:15
   7:     0x7fa65a5632c4 - std::sys_common::backtrace::_print::h8e31077e74457cbb
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fa65a5632c4 - std::sys_common::backtrace::print::hb32da5910a86799a
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fa65a5663ba - std::panicking::panic_hook_with_disk_dump::{{closure}}::h4239609dadb6dd4b
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/panicking.rs:278:22
  10:     0x7fa65a5660a7 - std::panicking::panic_hook_with_disk_dump::he7a9f97382268d96
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/panicking.rs:312:9
  11:     0x7fa65d76bf59 - rustc_driver_impl[65938c695a923997]::install_ice_hook::{closure#0}
  12:     0x7fa65a566c60 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hf0c2c27361744f38
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/alloc/src/boxed.rs:2021:9
  13:     0x7fa65a566c60 - std::panicking::rust_panic_with_hook::hb07817b642426395
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/panicking.rs:733:13
  14:     0x7fa65a5669e7 - std::panicking::begin_panic_handler::{{closure}}::h488a977f6d0b9662
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/panicking.rs:621:13
  15:     0x7fa65a563a06 - std::sys_common::backtrace::__rust_end_short_backtrace::h795eed542b7fd71a
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7fa65a566732 - rust_begin_unwind
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/panicking.rs:617:5
  17:     0x7fa65a5c5a33 - core::panicking::panic_fmt::h6cea401c88668a39
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/core/src/panicking.rs:67:14
  18:     0x7fa65a5c578a - core::panicking::panic_display::h6d1f308294ef9349
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/core/src/panicking.rs:150:5
  19:     0x7fa65a5c578a - core::panicking::panic_str::h149afc02926435d9
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/core/src/panicking.rs:134:5
  20:     0x7fa65a5c578a - core::option::expect_failed::hb346f79aa4c2fdad
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/core/src/option.rs:1988:5
  21:     0x7fa65c24e7f8 - <rustc_resolve[727b46f32f722939]::Resolver as rustc_expand[a0c8bf28632e4702]::base::ResolverExpand>::visit_ast_fragment_with_placeholders
  22:     0x7fa65c248473 - <rustc_expand[a0c8bf28632e4702]::expand::MacroExpander>::fully_expand_fragment
  23:     0x7fa65c8adc07 - <rustc_expand[a0c8bf28632e4702]::expand::MacroExpander>::expand_crate
  24:     0x7fa65c8aceed - <rustc_session[584b13b7c15f5880]::session::Session>::time::<rustc_ast[7e47edba6e8f4f49]::ast::Crate, rustc_interface[9c67ccc1e80e5966]::passes::configure_and_expand::{closure#1}>
  25:     0x7fa65c8a2851 - rustc_interface[9c67ccc1e80e5966]::passes::resolver_for_lowering
  26:     0x7fa65cc7e3aa - rustc_query_impl[e7344d331a0cd74e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e7344d331a0cd74e]::query_impl::resolver_for_lowering::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e44605746681820e]::query::erase::Erased<[u8; 8usize]>>
  27:     0x7fa65cc7e399 - <rustc_query_impl[e7344d331a0cd74e]::query_impl::resolver_for_lowering::dynamic_query::{closure#2} as core[ac9b6779de401ae6]::ops::function::FnOnce<(rustc_middle[e44605746681820e]::ty::context::TyCtxt, ())>>::call_once
  28:     0x7fa65cbef3fc - rustc_query_system[f713a07e914ef80b]::query::plumbing::try_execute_query::<rustc_query_impl[e7344d331a0cd74e]::DynamicConfig<rustc_query_system[f713a07e914ef80b]::query::caches::SingleCache<rustc_middle[e44605746681820e]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[e7344d331a0cd74e]::plumbing::QueryCtxt, false>
  29:     0x7fa65d0c3955 - rustc_query_impl[e7344d331a0cd74e]::query_impl::resolver_for_lowering::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7fa65ca55825 - <rustc_middle[e44605746681820e]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[65938c695a923997]::run_compiler::{closure#1}::{closure#2}::{closure#4}, &rustc_data_structures[6b3501c1aa0d2423]::steal::Steal<(rustc_middle[e44605746681820e]::ty::ResolverAstLowering, alloc[6066a680f2915695]::rc::Rc<rustc_ast[7e47edba6e8f4f49]::ast::Crate>)>>
  31:     0x7fa65ca54a44 - <rustc_interface[9c67ccc1e80e5966]::interface::Compiler>::enter::<rustc_driver_impl[65938c695a923997]::run_compiler::{closure#1}::{closure#2}, core[ac9b6779de401ae6]::result::Result<core[ac9b6779de401ae6]::option::Option<rustc_interface[9c67ccc1e80e5966]::queries::Linker>, rustc_span[96ddbb965edded7c]::ErrorGuaranteed>>
  32:     0x7fa65ca51e28 - std[2290b8cd92984895]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[9c67ccc1e80e5966]::util::run_in_thread_pool_with_globals<rustc_interface[9c67ccc1e80e5966]::interface::run_compiler<core[ac9b6779de401ae6]::result::Result<(), rustc_span[96ddbb965edded7c]::ErrorGuaranteed>, rustc_driver_impl[65938c695a923997]::run_compiler::{closure#1}>::{closure#0}, core[ac9b6779de401ae6]::result::Result<(), rustc_span[96ddbb965edded7c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ac9b6779de401ae6]::result::Result<(), rustc_span[96ddbb965edded7c]::ErrorGuaranteed>>
  33:     0x7fa65cfd7ae5 - <<std[2290b8cd92984895]::thread::Builder>::spawn_unchecked_<rustc_interface[9c67ccc1e80e5966]::util::run_in_thread_pool_with_globals<rustc_interface[9c67ccc1e80e5966]::interface::run_compiler<core[ac9b6779de401ae6]::result::Result<(), rustc_span[96ddbb965edded7c]::ErrorGuaranteed>, rustc_driver_impl[65938c695a923997]::run_compiler::{closure#1}>::{closure#0}, core[ac9b6779de401ae6]::result::Result<(), rustc_span[96ddbb965edded7c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ac9b6779de401ae6]::result::Result<(), rustc_span[96ddbb965edded7c]::ErrorGuaranteed>>::{closure#1} as core[ac9b6779de401ae6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x7fa65a571455 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4cced11e3b719b0a
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/alloc/src/boxed.rs:2007:9
  35:     0x7fa65a571455 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc891d0d7ae02d2bf
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/alloc/src/boxed.rs:2007:9
  36:     0x7fa65a571455 - std::sys::unix::thread::Thread::new::thread_start::h868c01f62b62c119
                               at /rustc/0bdb00d55aa7d6aebe5a01bc6d3c5bf474a853ab/library/std/src/sys/unix/thread.rs:108:17
  37:     0x7fa65a28c9eb - <unknown>
  38:     0x7fa65a310ebc - <unknown>
  39:                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

query stack during panic:
#0 [resolver_for_lowering] getting the resolver for lowering
end of query stack
error: aborting due to 2 previous errors
```

</p>
</details>