Skip to content

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

Closed

Description

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 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::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 - <alloc[62da33d4e78b0495]::boxed::Box<rustc_driver_impl[a38c2ed279593b55]::install_ice_hook::{closure#0}> 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 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::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::<rustc_errors[5287fd651099e84d]::ExplicitBug>::{closure#0}
  15:       0x7bd7ea31a0 - std[b7bdf322e3c58453]::sys_common::backtrace::__rust_end_short_backtrace::<std[b7bdf322e3c58453]::panicking::begin_panic<rustc_errors[5287fd651099e84d]::ExplicitBug>::{closure#0}, !>
  16:       0x7bd2e66a64 - std[b7bdf322e3c58453]::panicking::begin_panic::<rustc_errors[5287fd651099e84d]::ExplicitBug>
  17:       0x7bd7e97b50 - <rustc_errors[5287fd651099e84d]::diagnostic_builder::Bug as rustc_errors[5287fd651099e84d]::diagnostic_builder::EmissionGuarantee>::diagnostic_builder_emit_producing_guarantee
  18:       0x7bd7d19744 - <rustc_errors[5287fd651099e84d]::DiagCtxt>::bug::<alloc[62da33d4e78b0495]::string::String>
  19:       0x7bd7d32f68 - rustc_middle[eb966daf5a04f996]::util::bug::opt_span_bug_fmt::<rustc_span[6994779df6725c3d]::span_encoding::Span>::{closure#0}
  20:       0x7bd7d29210 - rustc_middle[eb966daf5a04f996]::ty::context::tls::with_opt::<rustc_middle[eb966daf5a04f996]::util::bug::opt_span_bug_fmt<rustc_span[6994779df6725c3d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:       0x7bd7d291e0 - rustc_middle[eb966daf5a04f996]::ty::context::tls::with_context_opt::<rustc_middle[eb966daf5a04f996]::ty::context::tls::with_opt<rustc_middle[eb966daf5a04f996]::util::bug::opt_span_bug_fmt<rustc_span[6994779df6725c3d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:       0x7bd2e3f9c4 - rustc_middle[eb966daf5a04f996]::util::bug::bug_fmt
  23:       0x7bd6b2a140 - <rustc_borrowck[356365c0c94964c2]::MirBorrowckCtxt>::annotate_fn_sig
  24:       0x7bd6b14854 - <core[7817230e571a6e0a]::option::Option<rustc_borrowck[356365c0c94964c2]::diagnostics::conflict_errors::AnnotatedBorrowFnSignature>>::or_else::<<rustc_borrowck[356365c0c94964c2]::MirBorrowckCtxt>::annotate_argument_and_return_for_borrow::{closure#0}>
  25:       0x7bd6b3f060 - <rustc_borrowck[356365c0c94964c2]::MirBorrowckCtxt>::report_borrowed_value_does_not_live_long_enough
  26:       0x7bd6b46684 - <rustc_borrowck[356365c0c94964c2]::MirBorrowckCtxt>::check_for_invalidation_at_exit
  27:       0x7bd6b39f5c - <rustc_borrowck[356365c0c94964c2]::MirBorrowckCtxt as rustc_mir_dataflow[fff4b8d1cfe00ad]::framework::visitor::ResultsVisitor<rustc_borrowck[356365c0c94964c2]::dataflow::BorrowckResults>>::visit_terminator_after_primary_effect
  28:       0x7bd6b5e524 - rustc_mir_dataflow[fff4b8d1cfe00ad]::framework::visitor::visit_results::<rustc_borrowck[356365c0c94964c2]::dataflow::BorrowckFlowState, rustc_borrowck[356365c0c94964c2]::dataflow::BorrowckResults, core[7817230e571a6e0a]::iter::adapters::map::Map<core[7817230e571a6e0a]::iter::adapters::map::Map<core[7817230e571a6e0a]::slice::iter::Iter<rustc_middle[eb966daf5a04f996]::mir::BasicBlock>, 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::<rustc_query_impl[d9f355b74a2388ce]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[eb966daf5a04f996]::query::erase::Erased<[u8; 8usize]>>
  32:       0x7bd6fa6940 - <rustc_query_impl[d9f355b74a2388ce]::query_impl::mir_borrowck::dynamic_query::{closure#2} as core[7817230e571a6e0a]::ops::function::FnOnce<(rustc_middle[eb966daf5a04f996]::ty::context::TyCtxt, rustc_span[6994779df6725c3d]::def_id::LocalDefId)>>::call_once
  33:       0x7bd705860c - rustc_query_system[25eac70257f58599]::query::plumbing::try_execute_query::<rustc_query_impl[d9f355b74a2388ce]::DynamicConfig<rustc_query_system[25eac70257f58599]::query::caches::VecCache<rustc_span[6994779df6725c3d]::def_id::LocalDefId, rustc_middle[eb966daf5a04f996]::query::erase::Erased<[u8; 8usize]>>, 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<rustc_data_structures[a56d6f77dfab58ce]::sync::parallel::disabled::par_for_each_in<&[rustc_span[6994779df6725c3d]::def_id::LocalDefId], <rustc_middle[eb966daf5a04f996]::hir::map::Map>::par_body_owners<rustc_interface[e73d2341e1cff0ed]::passes::analysis::{closure#1}::{closure#0}>::{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], <rustc_middle[eb966daf5a04f996]::hir::map::Map>::par_body_owners<rustc_interface[e73d2341e1cff0ed]::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>
  37:       0x7bd30e1760 - <rustc_session[bc960a95d572e3a4]::session::Session>::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::<rustc_query_impl[d9f355b74a2388ce]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[eb966daf5a04f996]::query::erase::Erased<[u8; 1usize]>>
  40:       0x7bd6fb5f24 - <rustc_query_impl[d9f355b74a2388ce]::query_impl::analysis::dynamic_query::{closure#2} as core[7817230e571a6e0a]::ops::function::FnOnce<(rustc_middle[eb966daf5a04f996]::ty::context::TyCtxt, ())>>::call_once
  41:       0x7bd6ffe29c - rustc_query_system[25eac70257f58599]::query::plumbing::try_execute_query::<rustc_query_impl[d9f355b74a2388ce]::DynamicConfig<rustc_query_system[25eac70257f58599]::query::caches::SingleCache<rustc_middle[eb966daf5a04f996]::query::erase::Erased<[u8; 1usize]>>, 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 - <rustc_middle[eb966daf5a04f996]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[a38c2ed279593b55]::run_compiler::{closure#0}::{closure#0}::{closure#3}, core[7817230e571a6e0a]::result::Result<(), rustc_span[6994779df6725c3d]::ErrorGuaranteed>>
  44:       0x7bd2f5d1d4 - <rustc_interface[e73d2341e1cff0ed]::interface::Compiler>::enter::<rustc_driver_impl[a38c2ed279593b55]::run_compiler::{closure#0}::{closure#0}, core[7817230e571a6e0a]::result::Result<core[7817230e571a6e0a]::option::Option<rustc_interface[e73d2341e1cff0ed]::queries::Linker>, rustc_span[6994779df6725c3d]::ErrorGuaranteed>>
  45:       0x7bd2f4ce20 - rustc_span[6994779df6725c3d]::create_session_globals_then::<core[7817230e571a6e0a]::result::Result<(), rustc_span[6994779df6725c3d]::ErrorGuaranteed>, rustc_interface[e73d2341e1cff0ed]::interface::run_compiler<core[7817230e571a6e0a]::result::Result<(), rustc_span[6994779df6725c3d]::ErrorGuaranteed>, rustc_driver_impl[a38c2ed279593b55]::run_compiler::{closure#0}>::{closure#0}>
  46:       0x7bd2f791d0 - std[b7bdf322e3c58453]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[e73d2341e1cff0ed]::util::run_in_thread_with_globals<rustc_interface[e73d2341e1cff0ed]::interface::run_compiler<core[7817230e571a6e0a]::result::Result<(), rustc_span[6994779df6725c3d]::ErrorGuaranteed>, 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 - <<std[b7bdf322e3c58453]::thread::Builder>::spawn_unchecked_<rustc_interface[e73d2341e1cff0ed]::util::run_in_thread_with_globals<rustc_interface[e73d2341e1cff0ed]::interface::run_compiler<core[7817230e571a6e0a]::result::Result<(), rustc_span[6994779df6725c3d]::ErrorGuaranteed>, 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 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he98dd9388c7047c2
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9
  49:       0x7bd23e62c0 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::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 - <unknown>
  53:                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: 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 `<impl at src/lib.rs:7:1: 7:31>::g`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `sound` (lib)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions