rust-lang / rust

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

ICE: `ty type is a ref but hir type is not` #121816

Closed turalcar closed 2 months ago

turalcar commented 7 months ago

I'll even accept that this is probably UB if I somehow make it work but crashing on cargo check is probably not the way. Replacing some & with &mut, or 'static with a second lifetime parameter correctly rejects the code.

Code

fn f<'a, T>(_: &'static &'a (), x: &'a T) -> &'static T {
    x
}
trait W<'a> {
    fn g<T>(self, x: &'a T) -> &'static T;
}
impl<'a> W<'a> for &'static () {
    fn g<T>(self, x: &'a T) -> &'static T {
        f(&self, x)
    }
}

Meta

rustc --version --verbose:

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: aarch64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

Error output

error: internal compiler error: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs:3308:33: ty type is a ref but hir type is not

thread 'rustc' panicked at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/compiler/rustc_errors/src/lib.rs:1119:75:
Box<dyn Any>
Backtrace

``` stack backtrace: 0: 0x7bd23da164 - std::backtrace_rs::backtrace::libunwind::trace::hee9690ac22774636 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5 1: 0x7bd23da164 - std::backtrace_rs::backtrace::trace_unsynchronized::ha30111b5438e6e61 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7bd23da164 - std::sys_common::backtrace::_print_fmt::hc2516686a74b2a42 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:68:5 3: 0x7bd23da164 - ::fmt::h8984c88846573cbb at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7bd2423e4c - core::fmt::rt::Argument::fmt::h071bdaa21123c9ed at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/fmt/rt.rs:142:9 5: 0x7bd2423e4c - core::fmt::write::h3f4921a7ddfa57a8 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/fmt/mod.rs:1120:17 6: 0x7bd23d00a8 - std::io::Write::write_fmt::h0923e211983fe028 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/io/mod.rs:1810:15 7: 0x7bd23d9f90 - std::sys_common::backtrace::_print::h39d471a7e51d9dbd at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7bd23d9f90 - std::sys_common::backtrace::print::h6306cb106d0c42e1 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7bd23dc9fc - std::panicking::default_hook::{{closure}}::h2a94c4f92161a016 10: 0x7bd23dc730 - std::panicking::default_hook::hd3c29c68b55e9f50 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:292:9 11: 0x7bd2f31580 - as core[7817230e571a6e0a]::ops::function::Fn<(&dyn for<'a, 'b> core[7817230e571a6e0a]::ops::function::Fn<(&'a core[7817230e571a6e0a]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[7817230e571a6e0a]::marker::Sync + core[7817230e571a6e0a]::marker::Send, &core[7817230e571a6e0a]::panic::panic_info::PanicInfo)>>::call 12: 0x7bd23dd0ec - as core::ops::function::Fn>::call::h44043f3b7ad3e11e at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2029:9 13: 0x7bd23dd0ec - std::panicking::rust_panic_with_hook::ha00bbb72a4f1b899 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:783:13 14: 0x7bd7ea6764 - std[b7bdf322e3c58453]::panicking::begin_panic::::{closure#0} 15: 0x7bd7ea31a0 - std[b7bdf322e3c58453]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7bd2e66a64 - std[b7bdf322e3c58453]::panicking::begin_panic:: 17: 0x7bd7e97b50 - ::diagnostic_builder_emit_producing_guarantee 18: 0x7bd7d19744 - ::bug:: 19: 0x7bd7d32f68 - rustc_middle[eb966daf5a04f996]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7bd7d29210 - rustc_middle[eb966daf5a04f996]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7bd7d291e0 - rustc_middle[eb966daf5a04f996]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7bd2e3f9c4 - rustc_middle[eb966daf5a04f996]::util::bug::bug_fmt 23: 0x7bd6b2a140 - ::annotate_fn_sig 24: 0x7bd6b14854 - >::or_else::<::annotate_argument_and_return_for_borrow::{closure#0}> 25: 0x7bd6b3f060 - ::report_borrowed_value_does_not_live_long_enough 26: 0x7bd6b46684 - ::check_for_invalidation_at_exit 27: 0x7bd6b39f5c - >::visit_terminator_after_primary_effect 28: 0x7bd6b5e524 - rustc_mir_dataflow[fff4b8d1cfe00ad]::framework::visitor::visit_results::, rustc_middle[eb966daf5a04f996]::mir::traversal::reverse_postorder::{closure#0}>, rustc_borrowck[356365c0c94964c2]::do_mir_borrowck::{closure#2}>, rustc_borrowck[356365c0c94964c2]::MirBorrowckCtxt> 29: 0x7bd6b439fc - rustc_borrowck[356365c0c94964c2]::do_mir_borrowck 30: 0x7bd6b39468 - rustc_borrowck[356365c0c94964c2]::mir_borrowck 31: 0x7bd6e11538 - rustc_query_impl[d9f355b74a2388ce]::plumbing::__rust_begin_short_backtrace::> 32: 0x7bd6fa6940 - >::call_once 33: 0x7bd705860c - rustc_query_system[25eac70257f58599]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[d9f355b74a2388ce]::plumbing::QueryCtxt, true> 34: 0x7bd6e72524 - rustc_query_impl[d9f355b74a2388ce]::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace 35: 0x7bd30c9538 - std[b7bdf322e3c58453]::panicking::try::<(), core[7817230e571a6e0a]::panic::unwind_safe::AssertUnwindSafe::par_body_owners::{closure#0}>::{closure#0}::{closure#0}::{closure#0}>> 36: 0x7bd311e8dc - rustc_data_structures[a56d6f77dfab58ce]::sync::parallel::disabled::par_for_each_in::<&[rustc_span[6994779df6725c3d]::def_id::LocalDefId], ::par_body_owners::{closure#0}> 37: 0x7bd30e1760 - ::time::<(), rustc_interface[e73d2341e1cff0ed]::passes::analysis::{closure#1}> 38: 0x7bd30c7704 - rustc_interface[e73d2341e1cff0ed]::passes::analysis 39: 0x7bd6e15ca0 - rustc_query_impl[d9f355b74a2388ce]::plumbing::__rust_begin_short_backtrace::> 40: 0x7bd6fb5f24 - >::call_once 41: 0x7bd6ffe29c - rustc_query_system[25eac70257f58599]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[d9f355b74a2388ce]::plumbing::QueryCtxt, true> 42: 0x7bd6e624a4 - rustc_query_impl[d9f355b74a2388ce]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace 43: 0x7bd2f46470 - ::enter::> 44: 0x7bd2f5d1d4 - ::enter::, rustc_span[6994779df6725c3d]::ErrorGuaranteed>> 45: 0x7bd2f4ce20 - rustc_span[6994779df6725c3d]::create_session_globals_then::, rustc_interface[e73d2341e1cff0ed]::interface::run_compiler, rustc_driver_impl[a38c2ed279593b55]::run_compiler::{closure#0}>::{closure#0}> 46: 0x7bd2f791d0 - std[b7bdf322e3c58453]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[a38c2ed279593b55]::run_compiler::{closure#0}>::{closure#0}, core[7817230e571a6e0a]::result::Result<(), rustc_span[6994779df6725c3d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7817230e571a6e0a]::result::Result<(), rustc_span[6994779df6725c3d]::ErrorGuaranteed>> 47: 0x7bd2f56c70 - <::spawn_unchecked_, rustc_driver_impl[a38c2ed279593b55]::run_compiler::{closure#0}>::{closure#0}, core[7817230e571a6e0a]::result::Result<(), rustc_span[6994779df6725c3d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7817230e571a6e0a]::result::Result<(), rustc_span[6994779df6725c3d]::ErrorGuaranteed>>::{closure#1} as core[7817230e571a6e0a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 48: 0x7bd23e62c0 - as core::ops::function::FnOnce>::call_once::he98dd9388c7047c2 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9 49: 0x7bd23e62c0 - as core::ops::function::FnOnce>::call_once::h103af4b9c154ce59 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9 50: 0x7bd23e62c0 - std::sys::unix::thread::Thread::new::thread_start::hc59882c1f8885c71 at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys/unix/thread.rs:108:17 51: 0x7bd2192648 - start_thread 52: 0x7bd22c5fdc - 53: 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: rustc 1.76.0 (07dca489a 2024-02-04) running on aarch64-unknown-linux-gnu note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [mir_borrowck] borrow-checking `::g` #1 [analysis] running analysis passes on this crate end of query stack error: could not compile `sound` (lib) ```

matthiaskrgr commented 7 months ago

Regression in nightly-2022-06-08

fetching (via remote github) commits from max(50b00252aeb77b10db04d65dc9e12ce758def4b5, 2022-06-05) to 5435ed6916a59e8d5acba2149316a841c3905cbd ending github query because we found starting sha: 50b00252aeb77b10db04d65dc9e12ce758def4b5 get_commits_between returning commits, len: 7 commit[0] 2022-06-06: Auto merge of #97730 - flip1995:clippyup, r=Manishearth commit[1] 2022-06-06: Auto merge of #97809 - matthiaskrgr:rollup-ajyvjd3, r=matthiaskrgr commit[2] 2022-06-07: Auto merge of #97801 - RalfJung:miri, r=RalfJung commit[3] 2022-06-07: Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis commit[4] 2022-06-07: Auto merge of #97512 - scottmcm:add-coldcc, r=nagisa,lcnr commit[5] 2022-06-07: Auto merge of #97825 - Dylan-DPC:rollup-ya51k1k, r=Dylan-DPC commit[6] 2022-06-07: Auto merge of #97835 - Dylan-DPC:rollup-0ae3pwp, r=Dylan-DPC

fmease commented 7 months ago

Likely #95565.