Repository: rust
Issue: ICE in rustc_metadata::creader::CrateLoader::maybe_resolve_crate
Labels: I-ICE,T-compiler,C-bug

<!--
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

I don't have code that reproduces this; I saw it in CI while compiling `clap`.

It looks to be happening on `env::current_dir().unwrap()` here: https://github.com/rust-lang/rust/blob/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/compiler/rustc_metadata/src/creader.rs#L672

### 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.72.1 (d5c2e9c34 2023-09-13) running on x86_64-unknown-linux-gnu
```

### Error output

```
<output>
```

<!--
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>

```
2023-10-04T16:41:23.0017742Z thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', compiler/rustc_metadata/src/creader.rs:672:39
2023-10-04T16:41:23.0018627Z stack backtrace:
2023-10-04T16:41:23.3358295Z    0:     0x7ffa52962b51 - std::backtrace_rs::backtrace::libunwind::trace::h66dc1c6acf794faa
2023-10-04T16:41:23.3365356Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
2023-10-04T16:41:23.3370776Z    1:     0x7ffa52962b51 - std::backtrace_rs::backtrace::trace_unsynchronized::ha80d20099a67f790
2023-10-04T16:41:23.3377026Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2023-10-04T16:41:23.3382746Z    2:     0x7ffa52962b51 - std::sys_common::backtrace::_print_fmt::h7b959d43f35f16d4
2023-10-04T16:41:23.3389329Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys_common/backtrace.rs:65:5
2023-10-04T16:41:23.3395807Z    3:     0x7ffa52962b51 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdaa196410d9ee0b9
2023-10-04T16:41:23.3402077Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys_common/backtrace.rs:44:22
2023-10-04T16:41:23.3494758Z    4:     0x7ffa529c96ff - core::fmt::rt::Argument::fmt::h0ddfbbe8be3f80d0
2023-10-04T16:41:23.3500387Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/fmt/rt.rs:138:9
2023-10-04T16:41:23.3504797Z    5:     0x7ffa529c96ff - core::fmt::write::h66b3c629f3d623e4
2023-10-04T16:41:23.3510409Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/fmt/mod.rs:1094:21
2023-10-04T16:41:23.3515963Z    6:     0x7ffa52955497 - std::io::Write::write_fmt::hb6d80fba4115e0c2
2023-10-04T16:41:23.3521486Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/io/mod.rs:1714:15
2023-10-04T16:41:23.3526503Z    7:     0x7ffa52962965 - std::sys_common::backtrace::_print::h1a49cfb0cf3cce17
2023-10-04T16:41:23.3531847Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys_common/backtrace.rs:47:5
2023-10-04T16:41:23.3536395Z    8:     0x7ffa52962965 - std::sys_common::backtrace::print::hca95c2d0055e42a2
2023-10-04T16:41:23.3541773Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys_common/backtrace.rs:34:9
2023-10-04T16:41:23.3547514Z    9:     0x7ffa52965743 - std::panicking::default_hook::{{closure}}::hc03c01c56bca600c
2023-10-04T16:41:23.3553207Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:269:22
2023-10-04T16:41:23.3558946Z   10:     0x7ffa529654d4 - std::panicking::default_hook::hb2cb5315b6634f1c
2023-10-04T16:41:23.3564700Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:288:9
2023-10-04T16:41:24.0084142Z   11:     0x7ffa55c6b60b - rustc_driver_impl[e91af841be79713a]::install_ice_hook::{closure#0}
2023-10-04T16:41:24.0092496Z   12:     0x7ffa52965f6e - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb3a915ffd78277c6
2023-10-04T16:41:24.0098032Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/alloc/src/boxed.rs:2007:9
2023-10-04T16:41:24.0102570Z   13:     0x7ffa52965f6e - std::panicking::rust_panic_with_hook::h75cd912a39a34e8a
2023-10-04T16:41:24.0108284Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:709:13
2023-10-04T16:41:24.0113409Z   14:     0x7ffa52965cf7 - std::panicking::begin_panic_handler::{{closure}}::h1498b46f7849e167
2023-10-04T16:41:24.0118822Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:597:13
2023-10-04T16:41:24.0123655Z   15:     0x7ffa52962fb6 - std::sys_common::backtrace::__rust_end_short_backtrace::hd36a39b27b98086b
2023-10-04T16:41:24.0129201Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys_common/backtrace.rs:151:18
2023-10-04T16:41:24.0133244Z   16:     0x7ffa52965a42 - rust_begin_unwind
2023-10-04T16:41:24.0138581Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:593:5
2023-10-04T16:41:24.0143119Z   17:     0x7ffa529c5973 - core::panicking::panic_fmt::h98ef273141454c23
2023-10-04T16:41:24.0148880Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:67:14
2023-10-04T16:41:24.0154632Z   18:     0x7ffa529c5f93 - core::result::unwrap_failed::h26e7d1a596cddd61
2023-10-04T16:41:24.0160431Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/result.rs:1651:5
2023-10-04T16:41:24.0233049Z   19:     0x7ffa550120fb - <rustc_metadata[b3cdd52576a10033]::creader::CrateLoader>::maybe_resolve_crate
2023-10-04T16:41:24.0475537Z   20:     0x7ffa54ca7802 - <rustc_resolve[1095f176748759de]::Resolver>::early_resolve_ident_in_lexical_scope
2023-10-04T16:41:24.0481327Z   21:     0x7ffa53fc4ebc - <rustc_resolve[1095f176748759de]::Resolver>::resolve_ident_in_module_unadjusted_ext
2023-10-04T16:41:24.0487153Z   22:     0x7ffa5483f842 - <rustc_resolve[1095f176748759de]::Resolver>::resolve_import::{closure#0}
2023-10-04T16:41:24.0559705Z   23:     0x7ffa54839660 - <rustc_resolve[1095f176748759de]::Resolver as rustc_expand[e91cf605287b8bbb]::base::ResolverExpand>::resolve_imports
2023-10-04T16:41:24.0646574Z   24:     0x7ffa5469f2f1 - <rustc_expand[e91cf605287b8bbb]::expand::MacroExpander>::fully_expand_fragment
2023-10-04T16:41:24.0651656Z   25:     0x7ffa54cd2067 - <rustc_expand[e91cf605287b8bbb]::expand::MacroExpander>::expand_crate
2023-10-04T16:41:24.0757956Z   26:     0x7ffa54cd1490 - <rustc_session[7bc6f0e7ff11a78e]::session::Session>::time::<rustc_ast[aa587559a0856461]::ast::Crate, rustc_interface[9522ab489a5f66e6]::passes::configure_and_expand::{closure#1}>
2023-10-04T16:41:24.0824718Z   27:     0x7ffa54c7dcc8 - rustc_interface[9522ab489a5f66e6]::passes::resolver_for_lowering
2023-10-04T16:41:24.0955055Z   28:     0x7ffa5508f47a - rustc_query_impl[e7af9ba2ee20c49a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e7af9ba2ee20c49a]::query_impl::resolver_for_lowering::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fbd75b4db2cdb7e6]::query::erase::Erased<[u8; 8usize]>>
2023-10-04T16:41:24.1125540Z   29:     0x7ffa5508f469 - <rustc_query_impl[e7af9ba2ee20c49a]::query_impl::resolver_for_lowering::dynamic_query::{closure#2} as core[63ccc595abf60ca6]::ops::function::FnOnce<(rustc_middle[fbd75b4db2cdb7e6]::ty::context::TyCtxt, ())>>::call_once
2023-10-04T16:41:24.1367731Z   30:     0x7ffa54fd052c - rustc_query_system[8b63fd0ca5778b73]::query::plumbing::try_execute_query::<rustc_query_impl[e7af9ba2ee20c49a]::DynamicConfig<rustc_query_system[8b63fd0ca5778b73]::query::caches::SingleCache<rustc_middle[fbd75b4db2cdb7e6]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[e7af9ba2ee20c49a]::plumbing::QueryCtxt, false>
2023-10-04T16:41:24.1374566Z   31:     0x7ffa555cc6d7 - rustc_query_impl[e7af9ba2ee20c49a]::query_impl::resolver_for_lowering::get_query_non_incr::__rust_end_short_backtrace
2023-10-04T16:41:24.1772467Z   32:     0x7ffa55123a70 - <rustc_interface[9522ab489a5f66e6]::queries::QueryResult<&rustc_middle[fbd75b4db2cdb7e6]::ty::context::GlobalCtxt>>::enter::<&rustc_data_structures[bf281432ed14a641]::steal::Steal<(rustc_middle[fbd75b4db2cdb7e6]::ty::ResolverAstLowering, alloc[1f40c6002c873f6d]::rc::Rc<rustc_ast[aa587559a0856461]::ast::Crate>)>, rustc_driver_impl[e91af841be79713a]::run_compiler::{closure#1}::{closure#2}::{closure#2}>
2023-10-04T16:41:24.1788054Z   33:     0x7ffa551224ab - <rustc_interface[9522ab489a5f66e6]::interface::Compiler>::enter::<rustc_driver_impl[e91af841be79713a]::run_compiler::{closure#1}::{closure#2}, core[63ccc595abf60ca6]::result::Result<core[63ccc595abf60ca6]::option::Option<rustc_interface[9522ab489a5f66e6]::queries::Linker>, rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>>
2023-10-04T16:41:24.1799215Z   34:     0x7ffa5511f7b5 - rustc_span[ca0c6fb73220b455]::set_source_map::<core[63ccc595abf60ca6]::result::Result<(), rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>, rustc_interface[9522ab489a5f66e6]::interface::run_compiler<core[63ccc595abf60ca6]::result::Result<(), rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>, rustc_driver_impl[e91af841be79713a]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
2023-10-04T16:41:24.1811006Z   35:     0x7ffa5511f226 - <scoped_tls[35a2f59988e0a19c]::ScopedKey<rustc_span[ca0c6fb73220b455]::SessionGlobals>>::set::<rustc_interface[9522ab489a5f66e6]::interface::run_compiler<core[63ccc595abf60ca6]::result::Result<(), rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>, rustc_driver_impl[e91af841be79713a]::run_compiler::{closure#1}>::{closure#0}, core[63ccc595abf60ca6]::result::Result<(), rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>>
2023-10-04T16:41:24.1825099Z   36:     0x7ffa5511e7ec - std[74d10c9f32099e86]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[9522ab489a5f66e6]::util::run_in_thread_pool_with_globals<rustc_interface[9522ab489a5f66e6]::interface::run_compiler<core[63ccc595abf60ca6]::result::Result<(), rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>, rustc_driver_impl[e91af841be79713a]::run_compiler::{closure#1}>::{closure#0}, core[63ccc595abf60ca6]::result::Result<(), rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[63ccc595abf60ca6]::result::Result<(), rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>>
2023-10-04T16:41:24.1902720Z   37:     0x7ffa554a53b5 - <<std[74d10c9f32099e86]::thread::Builder>::spawn_unchecked_<rustc_interface[9522ab489a5f66e6]::util::run_in_thread_pool_with_globals<rustc_interface[9522ab489a5f66e6]::interface::run_compiler<core[63ccc595abf60ca6]::result::Result<(), rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>, rustc_driver_impl[e91af841be79713a]::run_compiler::{closure#1}>::{closure#0}, core[63ccc595abf60ca6]::result::Result<(), rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[63ccc595abf60ca6]::result::Result<(), rustc_span[ca0c6fb73220b455]::ErrorGuaranteed>>::{closure#1} as core[63ccc595abf60ca6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
2023-10-04T16:41:24.1910337Z   38:     0x7ffa52970425 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hde6e666388faa495
2023-10-04T16:41:24.1914766Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/alloc/src/boxed.rs:1993:9
2023-10-04T16:41:24.1919745Z   39:     0x7ffa52970425 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9b6389e489a4842f
2023-10-04T16:41:24.1924404Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/alloc/src/boxed.rs:1993:9
2023-10-04T16:41:24.1928419Z   40:     0x7ffa52970425 - std::sys::unix::thread::Thread::new::thread_start::hcab660740b858b1f
2023-10-04T16:41:24.1932825Z                                at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys/unix/thread.rs:108:17
2023-10-04T16:41:24.1939422Z   41:     0x7ffa52694ac3 - <unknown>
2023-10-04T16:41:24.1942414Z   42:     0x7ffa52726a40 - <unknown>
2023-10-04T16:41:24.1946148Z   43:                0x0 - <unknown>
2023-10-04T16:41:24.1948109Z 
2023-10-04T16:41:24.1981954Z error: the compiler unexpectedly panicked. this is a bug.
2023-10-04T16:41:24.1983447Z 
2023-10-04T16:41:24.1991240Z 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
2023-10-04T16:41:24.1994229Z 
2023-10-04T16:41:24.1997315Z note: rustc 1.72.1 (d5c2e9c34 2023-09-13) running on x86_64-unknown-linux-gnu
2023-10-04T16:41:24.2000113Z 
2023-10-04T16:41:24.2003866Z note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2
2023-10-04T16:41:24.2006998Z 
2023-10-04T16:41:24.2010179Z note: some of the compiler flags provided by cargo are hidden
2023-10-04T16:41:24.2013309Z 
2023-10-04T16:41:24.2016442Z query stack during panic:
2023-10-04T16:41:24.2251160Z #0 [resolver_for_lowering] getting the resolver for lowering
2023-10-04T16:41:24.2313245Z end of query stack
2023-10-04T16:41:24.3720463Z [0m[0m[1m[31merror[0m[1m:[0m could not compile `clap` (lib)
2023-10-04T16:41:24.3721532Z [0m[0m[1m[33mwarning[0m[1m:[0m build failed, waiting for other jobs to finish...
2023-10-04T16:41:26.9891898Z ##[endgroup]
```

</p>
</details>