rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.01k stars 12.79k forks source link

ICE: `could not resolve DefId` #132126

Open matthiaskrgr opened 1 month ago

matthiaskrgr commented 1 month ago

auto-reduced (treereduce-rust):

trait UnsafeCopy<'a, T: Copy>
where
    for<'b> <Self as UnsafeCopy<'b, T>>::Item: use<'i, 'a, Self>,
{
}

original:

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

Program output

``` 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> >::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> >::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> >::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> >::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> >::Item: use<'i, 'a, Self>, | ^^^^ thread 'rustc' panicked at compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs:1435:14: Box stack backtrace: 0: 0x77b4b869d63a - ::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::>::{closure#0} 7: 0x77b4b86a00a8 - std::panicking::rust_panic_with_hook::h87bc2ca479f0c940 8: 0x77b4b7756971 - std[a585c2783b39f442]::panicking::begin_panic::::{closure#0} 9: 0x77b4b7749916 - std[a585c2783b39f442]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 10: 0x77b4b7744f19 - std[a585c2783b39f442]::panicking::begin_panic:: 11: 0x77b4b77604e1 - ::emit_producing_guarantee 12: 0x77b4b780626f - ::span_bug:: 13: 0x77b4b963459b - ::resolve_type_ref 14: 0x77b4b963571d - ::visit_where_predicate 15: 0x77b4b9634ddf - ::visit_generics 16: 0x77b4b9632080 - rustc_hir[5879a0835a2abccf]::intravisit::walk_item:: 17: 0x77b4b9631459 - ::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::> 20: 0x77b4b962a066 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::>, 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::> 23: 0x77b4b962a066 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::>, 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 - ::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::> 29: 0x77b4b9aec2eb - >::call_once 30: 0x77b4b9aebdc4 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::>, 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::>> 33: 0x77b4b928e4f9 - rustc_query_impl[cf4848b6d652eea9]::plumbing::__rust_begin_short_backtrace::> 34: 0x77b4b928d6e6 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::>, 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::> 38: 0x77b4b928d6ce - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::>, 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 - ::visit_item 41: 0x77b4b5dcb518 - rustc_hir_analysis[e81663bf6ec75b26]::check::wfcheck::check_well_formed 42: 0x77b4b9728c09 - rustc_query_impl[cf4848b6d652eea9]::plumbing::__rust_begin_short_backtrace::> 43: 0x77b4b9728359 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::>, 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::> 47: 0x77b4b9d38ec3 - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::>, 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::> 53: 0x77b4b9d471ee - rustc_query_system[b2d751a8ce89225a]::query::plumbing::try_execute_query::>, 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::, rustc_driver_impl[a403acafb158cb6a]::run_compiler::{closure#0}>::{closure#1} 56: 0x77b4b9c996d4 - std[a585c2783b39f442]::sys::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - 60: 0x77b4bb48b49c - 61: 0x0 - 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`. ```

cyrgani commented 1 month ago

Reduced:

trait UnsafeCopy where Self: use<Self> {}
jieyouxu commented 1 month ago

Huh, this ICEs on stable

jieyouxu commented 1 month ago

searched nightlies: from nightly-2024-05-01 to nightly-2024-07-01 regressed nightly: nightly-2024-06-19 searched commit range: https://github.com/rust-lang/rust/compare/59e2c01c2217a01546222e4d9ff4e6695ee8a1db...8fcd4dd08e2ba3e922d917d819ba0be066bdb005 regressed commit: https://github.com/rust-lang/rust/commit/c1f62a7c35349438ea9728abbe1bcf1cebd426b7

bisected with cargo-bisect-rustc v0.6.8 Host triple: aarch64-unknown-linux-gnu Reproduce with: ```bash cargo bisect-rustc --end=2024-07-01 --without-cargo --regress=ice --script=rustc -- check.rs ```
jieyouxu commented 1 month ago

Bisection isn't very useful because it basically just says "this has always ICE'd since the precise capturing rework" in #126049.

cc @compiler-errors since you know best about the precise capturing feature.

cyrgani commented 3 weeks ago

@rustbot label: +S-bug-has-test