Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: Attempting to cast non-castable types FnDef(DefId(0:3 ~ mvce[19cf]::redundant), [ReErased]) and *mut u8 #120884

Closed
matthiaskrgr opened this issue Feb 10, 2024 · 1 comment · Fixed by #120895
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

pub fn redundant<'a, 'a: 'a>() -> *const U {}

pub fn roundtrip() -> *const u8 {
    redundant as *mut u8 as *const u8
}

original:

// CHECK-NOT: as
// compile-flags: -Zinline-mir
// CHECK-LABEL: fn redundant(![crate_type = "lib"]

#[inline(always)]
fn b<'a, 'b: 'a>(x: *const T) -> *const T {
    // CHECK-LABEL: fn redundant(
    // CHECK: inlined generic_cast
    // CHECK-NOT: as
    generic_cast::<&'a u8, &'b u8>(x) as *const &'a u8
}

// EMIT_MIR casts.redundant.InstSimplify.diff
pub fn redundant<'a, 'a: 'a>(x: *mut u8) -> *const U {
    // CHECK-LABEL: fn redundant(
    // CHECK: inlined generic_cast
    // CHECK-NOT: as
    inline::<&'roundtrip u8, &'a u8>(x) as *const &'b u8
}

// EMIT_MIR casts.roundtrip.InstSimplify.diff
pub fn roundtrip(x: *const u8) -> *const u8 {
    // CHECK-LABEL: fn roundtrip(
    // CHECK: _4 = _1;
    // CHECK: _3 = move _4 as *mut u8 (PtrToPtr);
    // CHECK: _2 = move _3 as *const u8 (PointerCoercion(MutToConstPointer));
    redundant as *mut u8 as *const u8
}

Version information

rustc 1.78.0-nightly (232919c33 2024-02-10)
binary: rustc
commit-hash: 232919c33a5ba8ce8b4171b03cc898c77da136cc
commit-date: 2024-02-10
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

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

Program output

error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
 --> /tmp/icemaker_global_tempdir.OvCUtKlWIeTl/rustc_testrunner_tmpdir_reporting.FVwUTD9w2cWx/mvce.rs:1:22
  |
1 | pub fn redundant<'a, 'a: 'a>() -> *const U {}
  |                  --  ^^ already used
  |                  |
  |                  first use of `'a`

error[E0412]: cannot find type `U` in this scope
 --> /tmp/icemaker_global_tempdir.OvCUtKlWIeTl/rustc_testrunner_tmpdir_reporting.FVwUTD9w2cWx/mvce.rs:1:42
  |
1 | pub fn redundant<'a, 'a: 'a>() -> *const U {}
  |                                          ^ not found in this scope
  |
help: you might be missing a type parameter
  |
1 | pub fn redundant<'a, 'a: 'a, U>() -> *const U {}
  |                            +++

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

error: internal compiler error: compiler/rustc_middle/src/ty/cast.rs:99:13: Attempting to cast non-castable types FnDef(DefId(0:3 ~ mvce[19cf]::redundant), [ReErased]) and *mut u8

thread 'rustc' panicked at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/compiler/rustc_errors/src/lib.rs:929:30:
Box<dyn Any>
stack backtrace:
   0:     0x7f2f56d8b936 - std::backtrace_rs::backtrace::libunwind::trace::h204b59c4b7a956e8
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f2f56d8b936 - std::backtrace_rs::backtrace::trace_unsynchronized::hedb3fd0d3233331c
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f2f56d8b936 - std::sys_common::backtrace::_print_fmt::he34d0370733de883
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f2f56d8b936 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf7ad119d240fbf03
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f2f56dde380 - core::fmt::rt::Argument::fmt::h92da3927936c4633
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/core/src/fmt/rt.rs:142:9
   5:     0x7f2f56dde380 - core::fmt::write::h0e5e470bd0ce2176
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f2f56d7f17f - std::io::Write::write_fmt::heb2b1fda23254c33
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/std/src/io/mod.rs:1854:15
   7:     0x7f2f56d8b714 - std::sys_common::backtrace::_print::h263853e0ea367314
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f2f56d8b714 - std::sys_common::backtrace::print::h00f9d494ba8e0e79
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f2f56d8e4d7 - std::panicking::default_hook::{{closure}}::hacb2803bd6938000
  10:     0x7f2f56d8e239 - std::panicking::default_hook::hb716af7cb4653a24
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/std/src/panicking.rs:292:9
  11:     0x7f2f59b29d8c - std[7f0fb7d071667f83]::panicking::update_hook::<alloc[ec204197b905d5dc]::boxed::Box<rustc_driver_impl[4971e3aefab291b7]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f2f56d8ec26 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h1f9f88256f710aa3
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/alloc/src/boxed.rs:2030:9
  13:     0x7f2f56d8ec26 - std::panicking::rust_panic_with_hook::h28bab546a3573577
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/std/src/panicking.rs:785:13
  14:     0x7f2f59b5b294 - std[7f0fb7d071667f83]::panicking::begin_panic::<rustc_errors[4ebaeed1ac72940a]::ExplicitBug>::{closure#0}
  15:     0x7f2f59b57986 - std[7f0fb7d071667f83]::sys_common::backtrace::__rust_end_short_backtrace::<std[7f0fb7d071667f83]::panicking::begin_panic<rustc_errors[4ebaeed1ac72940a]::ExplicitBug>::{closure#0}, !>
  16:     0x7f2f59b530b6 - std[7f0fb7d071667f83]::panicking::begin_panic::<rustc_errors[4ebaeed1ac72940a]::ExplicitBug>
  17:     0x7f2f59b664d1 - <rustc_errors[4ebaeed1ac72940a]::diagnostic_builder::BugAbort as rustc_errors[4ebaeed1ac72940a]::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7f2f59f1c61e - <rustc_errors[4ebaeed1ac72940a]::DiagCtxt>::bug::<alloc[ec204197b905d5dc]::string::String>
  19:     0x7f2f59fb741b - rustc_middle[633bf8955aaf4eba]::util::bug::opt_span_bug_fmt::<rustc_span[6c817caf5980a8f7]::span_encoding::Span>::{closure#0}
  20:     0x7f2f59f9e85a - rustc_middle[633bf8955aaf4eba]::ty::context::tls::with_opt::<rustc_middle[633bf8955aaf4eba]::util::bug::opt_span_bug_fmt<rustc_span[6c817caf5980a8f7]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f2f59f9e6d8 - rustc_middle[633bf8955aaf4eba]::ty::context::tls::with_context_opt::<rustc_middle[633bf8955aaf4eba]::ty::context::tls::with_opt<rustc_middle[633bf8955aaf4eba]::util::bug::opt_span_bug_fmt<rustc_span[6c817caf5980a8f7]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f2f57f80b30 - rustc_middle[633bf8955aaf4eba]::util::bug::bug_fmt
  23:     0x7f2f5c1055ce - rustc_middle[633bf8955aaf4eba]::ty::cast::mir_cast_kind.cold.0
  24:     0x7f2f5b25d9e1 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::as_rvalue
  25:     0x7f2f5b57b335 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::expr_into_dest
  26:     0x7f2f5aeb1296 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::as_temp::{closure#0}
  27:     0x7f2f5ae598c4 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::as_operand
  28:     0x7f2f5b25c0c7 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::as_rvalue
  29:     0x7f2f5b57b335 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::expr_into_dest
  30:     0x7f2f5aeb1296 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::as_temp::{closure#0}
  31:     0x7f2f5ae598c4 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::as_operand
  32:     0x7f2f5ae5958f - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::as_operand
  33:     0x7f2f5b25d98b - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::as_rvalue
  34:     0x7f2f5b57b335 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::expr_into_dest
  35:     0x7f2f5b57d4c5 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::expr_into_dest
  36:     0x7f2f5813e75d - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::ast_block_stmts
  37:     0x7f2f5b57c198 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::expr_into_dest
  38:     0x7f2f5b57d4c5 - <rustc_mir_build[9635c1b0f9da976d]::build::Builder>::expr_into_dest
  39:     0x7f2f5b265ae9 - rustc_mir_build[9635c1b0f9da976d]::build::mir_build::{closure#0}
  40:     0x7f2f5b261e6b - rustc_mir_build[9635c1b0f9da976d]::build::mir_built
  41:     0x7f2f5b261b55 - rustc_query_impl[d07a5c1abde99c62]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d07a5c1abde99c62]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[633bf8955aaf4eba]::query::erase::Erased<[u8; 8usize]>>
  42:     0x7f2f5af7b33a - rustc_query_system[41c20884e3c50d50]::query::plumbing::try_execute_query::<rustc_query_impl[d07a5c1abde99c62]::DynamicConfig<rustc_query_system[41c20884e3c50d50]::query::caches::VecCache<rustc_span[6c817caf5980a8f7]::def_id::LocalDefId, rustc_middle[633bf8955aaf4eba]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d07a5c1abde99c62]::plumbing::QueryCtxt, false>
  43:     0x7f2f5af7af10 - rustc_query_impl[d07a5c1abde99c62]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  44:     0x7f2f5b1c0b21 - rustc_mir_build[9635c1b0f9da976d]::check_unsafety::check_unsafety
  45:     0x7f2f5b1c0949 - rustc_query_impl[d07a5c1abde99c62]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d07a5c1abde99c62]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[633bf8955aaf4eba]::query::erase::Erased<[u8; 0usize]>>
  46:     0x7f2f5b6812cd - rustc_query_system[41c20884e3c50d50]::query::plumbing::try_execute_query::<rustc_query_impl[d07a5c1abde99c62]::DynamicConfig<rustc_query_system[41c20884e3c50d50]::query::caches::VecCache<rustc_span[6c817caf5980a8f7]::def_id::LocalDefId, rustc_middle[633bf8955aaf4eba]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[d07a5c1abde99c62]::plumbing::QueryCtxt, false>
  47:     0x7f2f5b681017 - rustc_query_impl[d07a5c1abde99c62]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  48:     0x7f2f5b895086 - rustc_interface[2314d7060e0f18dd]::passes::analysis
  49:     0x7f2f5b894adf - rustc_query_impl[d07a5c1abde99c62]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d07a5c1abde99c62]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[633bf8955aaf4eba]::query::erase::Erased<[u8; 1usize]>>
  50:     0x7f2f5bb28572 - rustc_query_system[41c20884e3c50d50]::query::plumbing::try_execute_query::<rustc_query_impl[d07a5c1abde99c62]::DynamicConfig<rustc_query_system[41c20884e3c50d50]::query::caches::SingleCache<rustc_middle[633bf8955aaf4eba]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d07a5c1abde99c62]::plumbing::QueryCtxt, false>
  51:     0x7f2f5bb282d5 - rustc_query_impl[d07a5c1abde99c62]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  52:     0x7f2f5bb3e7c2 - rustc_interface[2314d7060e0f18dd]::interface::run_compiler::<core[b966835390a286e1]::result::Result<(), rustc_span[6c817caf5980a8f7]::ErrorGuaranteed>, rustc_driver_impl[4971e3aefab291b7]::run_compiler::{closure#0}>::{closure#0}
  53:     0x7f2f5bbdc806 - std[7f0fb7d071667f83]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2314d7060e0f18dd]::util::run_in_thread_with_globals<rustc_interface[2314d7060e0f18dd]::util::run_in_thread_pool_with_globals<rustc_interface[2314d7060e0f18dd]::interface::run_compiler<core[b966835390a286e1]::result::Result<(), rustc_span[6c817caf5980a8f7]::ErrorGuaranteed>, rustc_driver_impl[4971e3aefab291b7]::run_compiler::{closure#0}>::{closure#0}, core[b966835390a286e1]::result::Result<(), rustc_span[6c817caf5980a8f7]::ErrorGuaranteed>>::{closure#0}, core[b966835390a286e1]::result::Result<(), rustc_span[6c817caf5980a8f7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b966835390a286e1]::result::Result<(), rustc_span[6c817caf5980a8f7]::ErrorGuaranteed>>
  54:     0x7f2f5bbdc633 - <<std[7f0fb7d071667f83]::thread::Builder>::spawn_unchecked_<rustc_interface[2314d7060e0f18dd]::util::run_in_thread_with_globals<rustc_interface[2314d7060e0f18dd]::util::run_in_thread_pool_with_globals<rustc_interface[2314d7060e0f18dd]::interface::run_compiler<core[b966835390a286e1]::result::Result<(), rustc_span[6c817caf5980a8f7]::ErrorGuaranteed>, rustc_driver_impl[4971e3aefab291b7]::run_compiler::{closure#0}>::{closure#0}, core[b966835390a286e1]::result::Result<(), rustc_span[6c817caf5980a8f7]::ErrorGuaranteed>>::{closure#0}, core[b966835390a286e1]::result::Result<(), rustc_span[6c817caf5980a8f7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b966835390a286e1]::result::Result<(), rustc_span[6c817caf5980a8f7]::ErrorGuaranteed>>::{closure#1} as core[b966835390a286e1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x7f2f56d97eb5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha3c43b6c892c82cf
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/alloc/src/boxed.rs:2016:9
  56:     0x7f2f56d97eb5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h39babcbf5760ace1
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/alloc/src/boxed.rs:2016:9
  57:     0x7f2f56d97eb5 - std::sys::pal::unix::thread::Thread::new::thread_start::h35dde8f54f904bd0
                               at /rustc/232919c33a5ba8ce8b4171b03cc898c77da136cc/library/std/src/sys/pal/unix/thread.rs:108:17
  58:     0x7f2f56b4b9eb - <unknown>
  59:     0x7f2f56bcf7cc - <unknown>
  60:                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.78.0-nightly (232919c33 2024-02-10) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_built] building MIR for `roundtrip`
#1 [check_unsafety] unsafety-checking `roundtrip`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

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

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 10, 2024
@matthiaskrgr
Copy link
Member Author

#120550 cc @oli-obk

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Feb 10, 2024
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 10, 2024
@bors bors closed this as completed in 302301b Feb 11, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 11, 2024
Rollup merge of rust-lang#120895 - lukas-code:error-coercions-ice, r=compiler-errors

don't skip coercions for types with errors

fixes rust-lang#120884
RalfJung pushed a commit to RalfJung/miri that referenced this issue Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants