Repository: rust
Issue: ICE: `could not resolve DefId`
Labels: I-ICE,T-compiler,C-bug,S-has-mcve,S-bug-has-test,F-precise_capturing,S-has-bisection

<!--
[31mICE[0m: Rustc ./a.rs '' 'error: internal compiler error: could not resolve DefId(0:3 ~ a[cd3a]::UnsafeCopy)', 'error: internal compiler error: could not resolve DefId(0:3 ~ a[cd3a]::UnsafeCopy)'
File: /tmp/im/a.rs
-->

auto-reduced (treereduce-rust):
````rust
trait UnsafeCopy<'a, T: Copy>
where
    for<'b> <Self as UnsafeCopy<'b, T>>::Item: use<'i, 'a, Self>,
{
}

````

original:
````rust
trait UnsafeCopy<'a, T: Copy>
where
    for<'b> <Self as UnsafeCopy<'b, T>>::Item: use<'i, 'a, Self>,
{
    type Item;

    fn bug(item: &Self::Item) -> (
        //~^ ERROR `dyn` is a keyword
        //~| WARN this is accepted in the current edition

            // Note that we do not lint nor fix occurrences under macros
            dyn
    ) {
        let x: Monster = **item;
        &x as *const _;
    }
}

impl<T: Copy + std::ops::Deref> UnsafeCopy<'_, T> for T {
    type Item = T;
    //~^ type mismatch resolving `<T as Deref>::Target == T`
}

pub fn main() {
    <&'static str>::bug(&"");
    //~^ type mismatch resolving `<&str as Deref>::Target == &str`
}

````

Version information
````
rustc 1.84.0-nightly (788202a2c 2024-10-25)
binary: rustc
commit-hash: 788202a2cef5dde0743490fd51515f373d4207a6
commit-date: 2024-10-25
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

````

Possibly related line of code:
https://github.com/rust-lang/rust/blob/788202a2cef5dde0743490fd51515f373d4207a6/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs#L1429-L1441

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

<details><summary><strong>Program output</strong></summary>
<p>

```
error: `use<...>` precise capturing syntax not allowed in bounds
 --> /tmp/icemaker_global_tempdir.Xk7Jb50ziwEv/rustc_testrunner_tmpdir_reporting.iDnmKNe3NCiP/mvce.rs:3:48
  |
3 |     for<'b> <Self as UnsafeCopy<'b, T>>::Item: use<'i, 'a, Self>,
  |                                                ^^^^^^^^^^^^^^^^^

error[E0261]: use of undeclared lifetime name `'i`
 --> /tmp/icemaker_global_tempdir.Xk7Jb50ziwEv/rustc_testrunner_tmpdir_reporting.iDnmKNe3NCiP/mvce.rs:3:52
  |
3 |     for<'b> <Self as UnsafeCopy<'b, T>>::Item: use<'i, 'a, Self>,
  |                                                    ^^ undeclared lifetime
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'i` lifetime
  |
3 |     for<'i, 'b> <Self as UnsafeCopy<'b, T>>::Item: use<'i, 'a, Self>,
  |         +++
help: consider introducing lifetime `'i` here
  |
1 | trait UnsafeCopy<'i, 'a, T: Copy>
  |                  +++

error[E0576]: cannot find associated type `Item` in trait `UnsafeCopy`
 --> /tmp/icemaker_global_tempdir.Xk7Jb50ziwEv/rustc_testrunner_tmpdir_reporting.iDnmKNe3NCiP/mvce.rs:3:42
  |
3 |     for<'b> <Self as UnsafeCopy<'b, T>>::Item: use<'i, 'a, Self>,
  |                                          ^^^^ not found in `UnsafeCopy`

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

error: internal compiler error: could not resolve DefId(0:3 ~ mvce[1259]::UnsafeCopy)
 --> /tmp/icemaker_global_tempdir.Xk7Jb50ziwEv/rustc_testrunner_tmpdir_reporting.iDnmKNe3NCiP/mvce.rs:3:60
  |
3 |     for<'b> <Self as UnsafeCopy<'b, T>>::Item: use<'i, 'a, Self>,
  |                                                            ^^^^

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:1435:14:
Box<dyn Any>
stack backtrace:
   0:     0x77b4b869d63a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h5e8099de960d4cc6
   1:     0x77b4b8e041ca - core::fmt::write::hf87b533eacaf516a
   2:     0x77b4ba0a72d1 - std::io::Write::write_fmt::hb58c604a9dfe85f1
   3:     0x77b4b869d492 - std::sys::backtrace::BacktraceLock::print::h922a09e37c27473c
   4:     0x77b4b869f996 - std::panicking::default_hook::{{closure}}::ha4ce1ceabb39d9dc
   5:     0x77b4b869f7e0 - std::panicking::default_hook::hdbfa0836e0b339ee
   6:     0x77b4b771d2ef - std[a585c2783b39f442]::panicking::update_hook::<alloc[4209cb77a293fca]::boxed::Box<rustc_driver_impl[a403acafb158cb6a]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x77b4b86a00a8 - std::panicking::rust_panic_with_hook::h87bc2ca479f0c940
   8:     0x77b4b7756971 - std[a585c2783b39f442]::panicking::begin_panic::<rustc_errors[5a9eb276510fb09c]::ExplicitBug>::{closure#0}
   9:     0x77b4b7749916 - std[a585c2783b39f442]::sys::backtrace::__rust_end_short_backtrace::<std[a585c2783b39f442]::panicking::begin_panic<rustc_errors[5a9eb276510fb09c]::ExplicitBug>::{closure#0}, !>
  10:     0x77b4b7744f19 - std[a585c2783b39f442]::panicking::begin_panic::<rustc_errors[5a9eb276510fb09c]::ExplicitBug>
  11:     0x77b4b77604e1 - <rustc_errors[5a9eb276510fb09c]::diagnostic::BugAbort as rustc_errors[5a9eb276510fb09c]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x77b4b780626f - <rustc_errors[5a9eb276510fb09c]::DiagCtxtHandle>::span_bug::<rustc_span[babd1ca03564a0eb]::span_encoding::Span, alloc[4209cb77a293fca]::string::String>
  13:     0x77b4b963459b - <rustc_hir_analysis[e81663bf6ec75b26]::collect::resolve_bound_vars::BoundVarContext>::resolve_type_ref
  14:     0x77b4b963571d - <rustc_hir_analysis[e81663bf6ec75b26]::collect::resolve_bound_vars::BoundVarContext as rustc_hir[5879a0835a2abccf]::intravisit::Visitor>::visit_where_predicate
  15:     0x77b4b9634ddf - <rustc_hir_analysis[e81663bf6ec75b26]::collect::resolve_bound_vars::BoundVarContext as rustc_hir[5879a0835a2abccf]::intravisit::Visitor>::visit_generics
  16:     0x77b4b9632080 - rustc_hir[5879a0835a2abccf]::intravisit::walk_item::<rustc_hir_analysis[e81663bf6ec75b26]::collect::resolve_bound_vars::BoundVarContext>
  17:     0x77b4b9631459 - <rustc_hir_analysis[e81663bf6ec75b26]::collect::resolve_bound_vars::BoundVarContext as rustc_hir[5879a0835a2abccf]::intravisit::Visitor>::visit_item
  18:     0x77b4b962d8b6 - rustc_hir_analysis[e81663bf6ec75b26]::collect::resolve_bound_vars::resolve_bound_vars
  19:     0x77b4b962d2dc - rustc_query_impl[cf4848b6d652eea9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cf4848b6d652eea9]::query_impl::resolve_bound_vars::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 8usize]>>
  20:     0x77b4b962a066 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::<rustc_query_impl[cf4848b6d652eea9]::DynamicConfig<rustc_query_system[b2d751a8ce89225a]::query::caches::VecCache<rustc_hir[5879a0835a2abccf]::hir_id::OwnerId, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cf4848b6d652eea9]::plumbing::QueryCtxt, false>
  21:     0x77b4b9629a0d - rustc_query_impl[cf4848b6d652eea9]::query_impl::resolve_bound_vars::get_query_non_incr::__rust_end_short_backtrace
  22:     0x77b4b96297ec - rustc_query_impl[cf4848b6d652eea9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cf4848b6d652eea9]::query_impl::named_variable_map::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 8usize]>>
  23:     0x77b4b962a066 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::<rustc_query_impl[cf4848b6d652eea9]::DynamicConfig<rustc_query_system[b2d751a8ce89225a]::query::caches::VecCache<rustc_hir[5879a0835a2abccf]::hir_id::OwnerId, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cf4848b6d652eea9]::plumbing::QueryCtxt, false>
  24:     0x77b4b9629acd - rustc_query_impl[cf4848b6d652eea9]::query_impl::named_variable_map::get_query_non_incr::__rust_end_short_backtrace
  25:     0x77b4b97aa25e - <rustc_middle[5b3bbff2208691d6]::ty::context::TyCtxt>::named_bound_var
  26:     0x77b4b929508c - rustc_hir_analysis[e81663bf6ec75b26]::collect::predicates_of::gather_explicit_predicates_of
  27:     0x77b4b9aec38e - rustc_hir_analysis[e81663bf6ec75b26]::collect::predicates_of::trait_explicit_predicates_and_bounds
  28:     0x77b4b9aec318 - rustc_query_impl[cf4848b6d652eea9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cf4848b6d652eea9]::query_impl::trait_explicit_predicates_and_bounds::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 32usize]>>
  29:     0x77b4b9aec2eb - <rustc_query_impl[cf4848b6d652eea9]::query_impl::trait_explicit_predicates_and_bounds::dynamic_query::{closure#2} as core[c9fb322ef39a2568]::ops::function::FnOnce<(rustc_middle[5b3bbff2208691d6]::ty::context::TyCtxt, rustc_span[babd1ca03564a0eb]::def_id::LocalDefId)>>::call_once
  30:     0x77b4b9aebdc4 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::<rustc_query_impl[cf4848b6d652eea9]::DynamicConfig<rustc_query_system[b2d751a8ce89225a]::query::caches::VecCache<rustc_span[babd1ca03564a0eb]::def_id::LocalDefId, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[cf4848b6d652eea9]::plumbing::QueryCtxt, false>
  31:     0x77b4b9aebb2b - rustc_query_impl[cf4848b6d652eea9]::query_impl::trait_explicit_predicates_and_bounds::get_query_non_incr::__rust_end_short_backtrace
  32:     0x77b4b9aeba56 - rustc_middle[5b3bbff2208691d6]::query::plumbing::query_get_at::<rustc_query_system[b2d751a8ce89225a]::query::caches::VecCache<rustc_span[babd1ca03564a0eb]::def_id::LocalDefId, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 32usize]>>>
  33:     0x77b4b928e4f9 - rustc_query_impl[cf4848b6d652eea9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cf4848b6d652eea9]::query_impl::explicit_predicates_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 32usize]>>
  34:     0x77b4b928d6e6 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::<rustc_query_impl[cf4848b6d652eea9]::DynamicConfig<rustc_query_system[b2d751a8ce89225a]::query::caches::DefIdCache<rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[cf4848b6d652eea9]::plumbing::QueryCtxt, false>
  35:     0x77b4b928d3a3 - rustc_query_impl[cf4848b6d652eea9]::query_impl::explicit_predicates_of::get_query_non_incr::__rust_end_short_backtrace
  36:     0x77b4b928c28c - rustc_hir_analysis[e81663bf6ec75b26]::collect::predicates_of::predicates_of
  37:     0x77b4b928c19f - rustc_query_impl[cf4848b6d652eea9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cf4848b6d652eea9]::query_impl::predicates_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 32usize]>>
  38:     0x77b4b928d6ce - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::<rustc_query_impl[cf4848b6d652eea9]::DynamicConfig<rustc_query_system[b2d751a8ce89225a]::query::caches::DefIdCache<rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[cf4848b6d652eea9]::plumbing::QueryCtxt, false>
  39:     0x77b4b928d2a3 - rustc_query_impl[cf4848b6d652eea9]::query_impl::predicates_of::get_query_non_incr::__rust_end_short_backtrace
  40:     0x77b4b916fac4 - <rustc_hir_analysis[e81663bf6ec75b26]::collect::CollectItemTypesVisitor as rustc_hir[5879a0835a2abccf]::intravisit::Visitor>::visit_item
  41:     0x77b4b5dcb518 - rustc_hir_analysis[e81663bf6ec75b26]::check::wfcheck::check_well_formed
  42:     0x77b4b9728c09 - rustc_query_impl[cf4848b6d652eea9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cf4848b6d652eea9]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 1usize]>>
  43:     0x77b4b9728359 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::<rustc_query_impl[cf4848b6d652eea9]::DynamicConfig<rustc_query_system[b2d751a8ce89225a]::query::caches::VecCache<rustc_span[babd1ca03564a0eb]::def_id::LocalDefId, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[cf4848b6d652eea9]::plumbing::QueryCtxt, false>
  44:     0x77b4b9727fd0 - rustc_query_impl[cf4848b6d652eea9]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  45:     0x77b4b9728e86 - rustc_hir_analysis[e81663bf6ec75b26]::check::wfcheck::check_mod_type_wf
  46:     0x77b4b9728cb1 - rustc_query_impl[cf4848b6d652eea9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cf4848b6d652eea9]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 1usize]>>
  47:     0x77b4b9d38ec3 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::<rustc_query_impl[cf4848b6d652eea9]::DynamicConfig<rustc_query_system[b2d751a8ce89225a]::query::caches::DefaultCache<rustc_span[babd1ca03564a0eb]::def_id::LocalModDefId, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[cf4848b6d652eea9]::plumbing::QueryCtxt, false>
  48:     0x77b4b9d38c71 - rustc_query_impl[cf4848b6d652eea9]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  49:     0x77b4b8f9fb51 - rustc_hir_analysis[e81663bf6ec75b26]::check_crate
  50:     0x77b4b969e117 - rustc_interface[14453d2331067b08]::passes::run_required_analyses
  51:     0x77b4b9b85a1e - rustc_interface[14453d2331067b08]::passes::analysis
  52:     0x77b4b9b859f1 - rustc_query_impl[cf4848b6d652eea9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cf4848b6d652eea9]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 1usize]>>
  53:     0x77b4b9d471ee - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::<rustc_query_impl[cf4848b6d652eea9]::DynamicConfig<rustc_query_system[b2d751a8ce89225a]::query::caches::SingleCache<rustc_middle[5b3bbff2208691d6]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[cf4848b6d652eea9]::plumbing::QueryCtxt, false>
  54:     0x77b4b9d46ecf - rustc_query_impl[cf4848b6d652eea9]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  55:     0x77b4b9c265b1 - rustc_interface[14453d2331067b08]::interface::run_compiler::<core[c9fb322ef39a2568]::result::Result<(), rustc_span[babd1ca03564a0eb]::ErrorGuaranteed>, rustc_driver_impl[a403acafb158cb6a]::run_compiler::{closure#0}>::{closure#1}
  56:     0x77b4b9c996d4 - std[a585c2783b39f442]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[14453d2331067b08]::util::run_in_thread_with_globals<rustc_interface[14453d2331067b08]::util::run_in_thread_pool_with_globals<rustc_interface[14453d2331067b08]::interface::run_compiler<core[c9fb322ef39a2568]::result::Result<(), rustc_span[babd1ca03564a0eb]::ErrorGuaranteed>, rustc_driver_impl[a403acafb158cb6a]::run_compiler::{closure#0}>::{closure#1}, core[c9fb322ef39a2568]::result::Result<(), rustc_span[babd1ca03564a0eb]::ErrorGuaranteed>>::{closure#0}, core[c9fb322ef39a2568]::result::Result<(), rustc_span[babd1ca03564a0eb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c9fb322ef39a2568]::result::Result<(), rustc_span[babd1ca03564a0eb]::ErrorGuaranteed>>
  57:     0x77b4b9c99b0d - <<std[a585c2783b39f442]::thread::Builder>::spawn_unchecked_<rustc_interface[14453d2331067b08]::util::run_in_thread_with_globals<rustc_interface[14453d2331067b08]::util::run_in_thread_pool_with_globals<rustc_interface[14453d2331067b08]::interface::run_compiler<core[c9fb322ef39a2568]::result::Result<(), rustc_span[babd1ca03564a0eb]::ErrorGuaranteed>, rustc_driver_impl[a403acafb158cb6a]::run_compiler::{closure#0}>::{closure#1}, core[c9fb322ef39a2568]::result::Result<(), rustc_span[babd1ca03564a0eb]::ErrorGuaranteed>>::{closure#0}, core[c9fb322ef39a2568]::result::Result<(), rustc_span[babd1ca03564a0eb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c9fb322ef39a2568]::result::Result<(), rustc_span[babd1ca03564a0eb]::ErrorGuaranteed>>::{closure#1} as core[c9fb322ef39a2568]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  58:     0x77b4b9c9a5ab - std::sys::pal::unix::thread::Thread::new::thread_start::h197af60b272f0d26
  59:     0x77b4bb40639d - <unknown>
  60:     0x77b4bb48b49c - <unknown>
  61:                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.84.0-nightly (788202a2c 2024-10-25) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [resolve_bound_vars] resolving lifetimes for `UnsafeCopy`
#1 [named_variable_map] looking up a named region inside `UnsafeCopy`
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0261, E0576, E0601.
For more information about an error, try `rustc --explain E0261`.

```

</p>
</details>

<!--
query stack:
#0 [resolve_bound_vars] resolving lifetimes for `UnsafeCopy`
#1 [named_variable_map] looking up a named region inside `UnsafeCopy`

-->