rust-lang / rust

Empowering everyone to build reliable and efficient software.

Home Page:https://www.rust-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ICE "raw ptr comparison should already be caught in the trait system"

jruderman opened this issue · comments

Code

#![feature(raw_ref_op)]

const RCZ: *const i32 = &raw const *&0;

const fn f() {
    if let RCZ = &raw const *&0 { }
}

fn main() {}

Error output

internal compiler error: compiler/rustc_const_eval/src/transform/check_consts/ops.rs:611: raw ptr comparison should already be caught in the trait system

Full output including backtrace

error: internal compiler error: compiler/rustc_const_eval/src/transform/check_consts/ops.rs:611:9: raw ptr comparison should already be caught in the trait system
 --> rps.rs:6:12
  |
6 |     if let RCZ = &raw const *&0 { }
  |            ^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/1eb62b1235fd77200e6bd967d70e83c0f2497233/compiler/rustc_errors/src/lib.rs:972:33
stack backtrace:
   0:        0x10f2f22a6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1901ec5c10c2d477
   1:        0x10f350e2a - core::fmt::write::h453ba3b763f16dfb
   2:        0x10f2e464c - std::io::Write::write_fmt::h35935f9cf41659e0
   3:        0x10f2f208a - std::sys_common::backtrace::print::h48cb2ddd4d16ad05
   4:        0x10f2f53d3 - std::panicking::default_hook::{{closure}}::hf85401495f021b7c
   5:        0x10f2f5128 - std::panicking::default_hook::hcc698ed67aaec0db
   6:        0x11f1035fd - rustc_driver[c6bc39476a4ff69]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x10f2f5bb7 - std::panicking::rust_panic_with_hook::h4686e220b4123e59
   8:        0x122797167 - std[e853a6d0ec043b70]::panicking::begin_panic::<rustc_errors[5974999511236221]::ExplicitBug>::{closure#0}
   9:        0x122795a39 - std[e853a6d0ec043b70]::sys_common::backtrace::__rust_end_short_backtrace::<std[e853a6d0ec043b70]::panicking::begin_panic<rustc_errors[5974999511236221]::ExplicitBug>::{closure#0}, !>
  10:        0x123eb2ff9 - std[e853a6d0ec043b70]::panicking::begin_panic::<rustc_errors[5974999511236221]::ExplicitBug>
  11:        0x12271faf9 - std[e853a6d0ec043b70]::panic::panic_any::<rustc_errors[5974999511236221]::ExplicitBug>
  12:        0x12271e938 - <rustc_errors[5974999511236221]::HandlerInner>::span_bug::<rustc_span[db835ecaf6c42563]::span_encoding::Span, &alloc[374a688e4a400e73]::string::String>
  13:        0x12271e74e - <rustc_errors[5974999511236221]::Handler>::span_bug::<rustc_span[db835ecaf6c42563]::span_encoding::Span, &alloc[374a688e4a400e73]::string::String>
  14:        0x1227eac72 - rustc_middle[d5319f07d231351a]::ty::context::tls::with_context_opt::<rustc_middle[d5319f07d231351a]::ty::context::tls::with_opt<rustc_middle[d5319f07d231351a]::util::bug::opt_span_bug_fmt<rustc_span[db835ecaf6c42563]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  15:        0x1227ea4a1 - rustc_middle[d5319f07d231351a]::util::bug::opt_span_bug_fmt::<rustc_span[db835ecaf6c42563]::span_encoding::Span>
  16:        0x123eb53df - rustc_middle[d5319f07d231351a]::util::bug::span_bug_fmt::<rustc_span[db835ecaf6c42563]::span_encoding::Span>
  17:        0x1227d0ae9 - <rustc_const_eval[c3ddd231fb47b19c]::transform::check_consts::ops::RawPtrComparison as rustc_const_eval[c3ddd231fb47b19c]::transform::check_consts::ops::NonConstOp>::build_error
  18:        0x12279f6b0 - <rustc_const_eval[c3ddd231fb47b19c]::transform::check_consts::check::Checker as rustc_middle[d5319f07d231351a]::mir::visit::Visitor>::visit_rvalue
  19:        0x12279aeb2 - <rustc_const_eval[c3ddd231fb47b19c]::transform::check_consts::check::Checker>::check_body
  20:        0x121dc2b0a - rustc_mir_transform[827416b191d7b3aa]::mir_const_qualif
  21:        0x121db4316 - <rustc_mir_transform[827416b191d7b3aa]::provide::{closure#0} as core[e7c8723dd1d9fd02]::ops::function::FnOnce<(rustc_middle[d5319f07d231351a]::ty::context::TyCtxt, rustc_span[db835ecaf6c42563]::def_id::DefId)>>::call_once
  22:        0x12291437b - rustc_query_system[91c4ad596cfd42fe]::query::plumbing::try_execute_query::<rustc_query_impl[5858643fdf1b29eb]::plumbing::QueryCtxt, rustc_query_system[91c4ad596cfd42fe]::query::caches::DefaultCache<rustc_span[db835ecaf6c42563]::def_id::DefId, rustc_middle[d5319f07d231351a]::mir::query::ConstQualifs>>
  23:        0x122a031ad - rustc_query_system[91c4ad596cfd42fe]::query::plumbing::get_query::<rustc_query_impl[5858643fdf1b29eb]::queries::mir_const_qualif, rustc_query_impl[5858643fdf1b29eb]::plumbing::QueryCtxt>
  24:        0x121dc3f62 - rustc_mir_transform[827416b191d7b3aa]::mir_promoted
  25:        0x1228d7451 - rustc_query_system[91c4ad596cfd42fe]::query::plumbing::try_execute_query::<rustc_query_impl[5858643fdf1b29eb]::plumbing::QueryCtxt, rustc_query_system[91c4ad596cfd42fe]::query::caches::DefaultCache<rustc_middle[d5319f07d231351a]::ty::WithOptConstParam<rustc_span[db835ecaf6c42563]::def_id::LocalDefId>, (&rustc_data_structures[8f5aaa015017f2be]::steal::Steal<rustc_middle[d5319f07d231351a]::mir::Body>, &rustc_data_structures[8f5aaa015017f2be]::steal::Steal<rustc_index[4370e6fc8b417ef]::vec::IndexVec<rustc_middle[d5319f07d231351a]::mir::Promoted, rustc_middle[d5319f07d231351a]::mir::Body>>)>>
  26:        0x1229fe350 - rustc_query_system[91c4ad596cfd42fe]::query::plumbing::get_query::<rustc_query_impl[5858643fdf1b29eb]::queries::mir_promoted, rustc_query_impl[5858643fdf1b29eb]::plumbing::QueryCtxt>
  27:        0x122aa8947 - <rustc_query_impl[5858643fdf1b29eb]::Queries as rustc_middle[d5319f07d231351a]::ty::query::QueryEngine>::mir_promoted
  28:        0x12249d47f - rustc_borrowck[85dfbb963c3a91f9]::mir_borrowck
  29:        0x122478355 - <rustc_borrowck[85dfbb963c3a91f9]::provide::{closure#0} as core[e7c8723dd1d9fd02]::ops::function::FnOnce<(rustc_middle[d5319f07d231351a]::ty::context::TyCtxt, rustc_span[db835ecaf6c42563]::def_id::LocalDefId)>>::call_once
  30:        0x1229895bf - rustc_query_system[91c4ad596cfd42fe]::query::plumbing::try_execute_query::<rustc_query_impl[5858643fdf1b29eb]::plumbing::QueryCtxt, rustc_query_system[91c4ad596cfd42fe]::query::caches::VecCache<rustc_span[db835ecaf6c42563]::def_id::LocalDefId, &rustc_middle[d5319f07d231351a]::mir::query::BorrowCheckResult>>
  31:        0x1229fe0b7 - rustc_query_system[91c4ad596cfd42fe]::query::plumbing::get_query::<rustc_query_impl[5858643fdf1b29eb]::queries::mir_borrowck, rustc_query_impl[5858643fdf1b29eb]::plumbing::QueryCtxt>
  32:        0x11f21804b - rustc_data_structures[8f5aaa015017f2be]::sync::par_for_each_in::<&[rustc_span[db835ecaf6c42563]::def_id::LocalDefId], <rustc_middle[d5319f07d231351a]::hir::map::Map>::par_body_owners<rustc_interface[6b0baa6f0acee236]::passes::analysis::{closure#2}::{closure#0}>::{closure#0}>
  33:        0x11f189100 - <rustc_session[bf9d936332845243]::session::Session>::time::<(), rustc_interface[6b0baa6f0acee236]::passes::analysis::{closure#2}>
  34:        0x11f1cc1c3 - rustc_interface[6b0baa6f0acee236]::passes::analysis
  35:        0x12295878b - rustc_query_system[91c4ad596cfd42fe]::query::plumbing::try_execute_query::<rustc_query_impl[5858643fdf1b29eb]::plumbing::QueryCtxt, rustc_query_system[91c4ad596cfd42fe]::query::caches::DefaultCache<(), core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>>>
  36:        0x122a12e8d - rustc_query_system[91c4ad596cfd42fe]::query::plumbing::get_query::<rustc_query_impl[5858643fdf1b29eb]::queries::analysis, rustc_query_impl[5858643fdf1b29eb]::plumbing::QueryCtxt>
  37:        0x11f0956d7 - <rustc_interface[6b0baa6f0acee236]::passes::QueryContext>::enter::<rustc_driver[c6bc39476a4ff69]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>>
  38:        0x11f0dbb75 - <rustc_interface[6b0baa6f0acee236]::interface::Compiler>::enter::<rustc_driver[c6bc39476a4ff69]::run_compiler::{closure#1}::{closure#2}, core[e7c8723dd1d9fd02]::result::Result<core[e7c8723dd1d9fd02]::option::Option<rustc_interface[6b0baa6f0acee236]::queries::Linker>, rustc_errors[5974999511236221]::ErrorGuaranteed>>
  39:        0x11f077d5d - rustc_span[db835ecaf6c42563]::with_source_map::<core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>, rustc_interface[6b0baa6f0acee236]::interface::run_compiler<core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>, rustc_driver[c6bc39476a4ff69]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  40:        0x11f0cea9d - <scoped_tls[9dceb67bf45baec5]::ScopedKey<rustc_span[db835ecaf6c42563]::SessionGlobals>>::set::<rustc_interface[6b0baa6f0acee236]::interface::run_compiler<core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>, rustc_driver[c6bc39476a4ff69]::run_compiler::{closure#1}>::{closure#0}, core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>>
  41:        0x11f09dffa - std[e853a6d0ec043b70]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6b0baa6f0acee236]::util::run_in_thread_pool_with_globals<rustc_interface[6b0baa6f0acee236]::interface::run_compiler<core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>, rustc_driver[c6bc39476a4ff69]::run_compiler::{closure#1}>::{closure#0}, core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>>
  42:        0x11f07e2a5 - <<std[e853a6d0ec043b70]::thread::Builder>::spawn_unchecked_<rustc_interface[6b0baa6f0acee236]::util::run_in_thread_pool_with_globals<rustc_interface[6b0baa6f0acee236]::interface::run_compiler<core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>, rustc_driver[c6bc39476a4ff69]::run_compiler::{closure#1}>::{closure#0}, core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e7c8723dd1d9fd02]::result::Result<(), rustc_errors[5974999511236221]::ErrorGuaranteed>>::{closure#1} as core[e7c8723dd1d9fd02]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:        0x10f2fee87 - std::sys::unix::thread::Thread::new::thread_start::hb253bfeab5e611e1
  44:     0x7ff807a764e1 - __pthread_start

note: the compiler unexpectedly panicked. this is a bug.

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.67.0-nightly (1eb62b123 2022-11-27) running on x86_64-apple-darwin

query stack during panic:
#0 [mir_const_qualif] const checking `f`
#1 [mir_promoted] processing MIR for `f`
#2 [mir_borrowck] borrow-checking `f`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

Regression

Regression in nightly-2022-07-28, somewhere in rollup 2a22093

Very likely due to #99704, which added this assertion (@fee1-dead, @oli-obk)

Version

rustc 1.67.0-nightly (1eb62b123 2022-11-27)
binary: rustc
commit-hash: 1eb62b1235fd77200e6bd967d70e83c0f2497233
commit-date: 2022-11-27
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4
commented

This also reproduces on stable with function pointers (example adapted from #70861):

fn foo() {}
const FOO: fn() = foo;

fn bar() {}
const BAR: fn() = bar;

const fn hello() {
    match FOO {
        FOO => (),
        BAR => (),
        _ => unreachable!(),
    }
}

Gives the same ICE:

error: internal compiler error: compiler/rustc_const_eval/src/transform/check_consts/ops.rs:616:9: raw ptr comparison should already be caught in the trait system
 --> src/lib.rs:9:9
  |
9 |         FOO => (),
  |         ^^^

Backtrace:

``` thread 'rustc' panicked at 'Box', /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/compiler/rustc_errors/src/lib.rs:995:33 stack backtrace: 0: 0x7fa9c242ebaa - std::backtrace_rs::backtrace::libunwind::trace::h9d4d46a1241d4149 at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7fa9c242ebaa - std::backtrace_rs::backtrace::trace_unsynchronized::h1d977e0ccdc95d1a at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7fa9c242ebaa - std::sys_common::backtrace::_print_fmt::h2f16d6748c69c3cb at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7fa9c242ebaa - ::fmt::h23aff7f8c54e6645 at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7fa9c2492b4f - core::fmt::write::h79726c2a902099f4 at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/core/src/fmt/mod.rs:1254:17 5: 0x7fa9c24217e5 - std::io::Write::write_fmt::h95eedad6917eaf86 at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/io/mod.rs:1698:15 6: 0x7fa9c242e975 - std::sys_common::backtrace::_print::h24fa32acab53acd8 at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/sys_common/backtrace.rs:47:5 7: 0x7fa9c242e975 - std::sys_common::backtrace::print::h94b47d816d0ea14c at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/sys_common/backtrace.rs:34:9 8: 0x7fa9c243161e - std::panicking::default_hook::{{closure}}::h3bfad4b8b9ac0389 at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/panicking.rs:271:22 9: 0x7fa9c24313c5 - std::panicking::default_hook::hd7b308d8bc779cf9 at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/panicking.rs:290:9 10: 0x7fa9c56d6e85 - >::call_once::{shim:vtable#0} 11: 0x7fa9c2431e14 - as core::ops::function::Fn>::call::hca7afd504fdadbfc at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/alloc/src/boxed.rs:2002:9 12: 0x7fa9c2431e14 - std::panicking::rust_panic_with_hook::hcec224f40e508f49 at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/panicking.rs:696:13 13: 0x7fa9c5671641 - std[d743b6fa88cd7a4c]::panicking::begin_panic::::{closure#0} 14: 0x7fa9c566ebf6 - std[d743b6fa88cd7a4c]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 15: 0x7fa9c5686496 - std[d743b6fa88cd7a4c]::panicking::begin_panic:: 16: 0x7fa9c56416e2 - ::span_bug:: 17: 0x7fa9c5641587 - ::span_bug:: 18: 0x7fa9c56474bb - rustc_middle[344b7a5778ebfb41]::util::bug::opt_span_bug_fmt::::{closure#0} 19: 0x7fa9c564750a - rustc_middle[344b7a5778ebfb41]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 20: 0x7fa9c5646c96 - rustc_middle[344b7a5778ebfb41]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 21: 0x7fa9c5646b66 - rustc_middle[344b7a5778ebfb41]::util::bug::opt_span_bug_fmt:: 22: 0x7fa9c3c02894 - rustc_middle[344b7a5778ebfb41]::util::bug::span_bug_fmt:: 23: 0x7fa9c568b29f - ::build_error 24: 0x7fa9c49bc2d7 - ::visit_basic_block_data 25: 0x7fa9c49b91fe - ::check_body 26: 0x7fa9c49b739c - >::call_once 27: 0x7fa9c49b5dc3 - rustc_query_system[131b14eb042ddf12]::query::plumbing::try_execute_query:: 28: 0x7fa9c40bc6c5 - rustc_mir_transform[c5d3163ff4a25b61]::mir_promoted 29: 0x7fa9c40bb03e - rustc_query_system[131b14eb042ddf12]::query::plumbing::try_execute_query:: 30: 0x7fa9c45991f5 - >::call_once 31: 0x7fa9c4597a00 - rustc_query_system[131b14eb042ddf12]::query::plumbing::try_execute_query:: 32: 0x7fa9c4b720f0 - rustc_data_structures[3749598f95b8ed78]::sync::par_for_each_in::<&[rustc_span[d779338a88541528]::def_id::LocalDefId], ::par_body_owners::{closure#0}> 33: 0x7fa9c4b71d26 - ::time::<(), rustc_interface[cc30d76fa8dae5fc]::passes::analysis::{closure#2}> 34: 0x7fa9c4b7154f - rustc_interface[cc30d76fa8dae5fc]::passes::analysis 35: 0x7fa9c4e9a5e2 - rustc_query_system[131b14eb042ddf12]::query::plumbing::try_execute_query:: 36: 0x7fa9c4e9a2f0 - ::analysis 37: 0x7fa9c4d1e089 - ::enter::> 38: 0x7fa9c4846e01 - ::enter::, rustc_span[d779338a88541528]::ErrorGuaranteed>> 39: 0x7fa9c4844fb1 - rustc_span[d779338a88541528]::with_source_map::, rustc_interface[cc30d76fa8dae5fc]::interface::run_compiler, rustc_driver_impl[2b818a379abe8476]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 40: 0x7fa9c484455f - std[d743b6fa88cd7a4c]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[2b818a379abe8476]::run_compiler::{closure#1}>::{closure#0}, core[4ada38e0d5cae8be]::result::Result<(), rustc_span[d779338a88541528]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[4ada38e0d5cae8be]::result::Result<(), rustc_span[d779338a88541528]::ErrorGuaranteed>> 41: 0x7fa9c4f7f52e - <::spawn_unchecked_, rustc_driver_impl[2b818a379abe8476]::run_compiler::{closure#1}>::{closure#0}, core[4ada38e0d5cae8be]::result::Result<(), rustc_span[d779338a88541528]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[4ada38e0d5cae8be]::result::Result<(), rustc_span[d779338a88541528]::ErrorGuaranteed>>::{closure#1} as core[4ada38e0d5cae8be]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 42: 0x7fa9c243bf15 - as core::ops::function::FnOnce>::call_once::h843c8319f93d5fbd at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/alloc/src/boxed.rs:1988:9 43: 0x7fa9c243bf15 - as core::ops::function::FnOnce>::call_once::h9f6cdb354bbcea1a at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/alloc/src/boxed.rs:1988:9 44: 0x7fa9c243bf15 - std::sys::unix::thread::Thread::new::thread_start::h53e32c182a23b75f at /rustc/db0cbc48d4aaa300713a95d9b317a365a474490c/library/std/src/sys/unix/thread.rs:108:17 45: 0x7fa9c2309609 - start_thread 46: 0x7fa9c222c133 - clone 47: 0x0 - ```

Note that there is an allow-by-default forward compat lint against it: pointer_structural_match, added by #70743.

Triage: No longer ICE since today's nightly, @rustbot label: +E-needs-test

No longer ICEs because the ICE was temporarily(?) changed to an explicit error.

This change was made in 147e850 as part of #110393 (thanks @fee1-dead).