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

"internal compiler error: cannot relate constants" from const generic expression using generic associated types #107920

Closed
chc4 opened this issue Feb 11, 2023 · 3 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@chc4
Copy link

chc4 commented Feb 11, 2023

I was writing some code that uses traits with generic associated types and hit an ICE when adding const generic bounds to a function.

Code

Playground link

I couldn't easily minimize it much more than this, unfortunately. The bound in question is Equal<{ core::mem::size_of::<T>() }, { core::mem::size_of::<U>() }>: True, and goes away if you remove the TO and FROM functions and definitions in the Tokenize trait. The ICE goes away if you change the left-hand to core::mem::size_of::<T>() as usize instead.

Meta

rustc --version --verbose:

rustc 1.69.0-nightly (2773383a3 2023-02-10)
binary: rustc
commit-hash: 2773383a314a4b8f481ce2bed12c32de794ffbe9
commit-date: 2023-02-10
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Error output

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: cannot relate constants (Const { ty: fn() -> usize {std::mem::size_of::<_>}, kind: Value(Branch([])) }, Const { ty: fn() -> usize {std::mem::size_of::<_>}, kind: Value(Branch([])) }) of different types: fn() -> usize {std::mem::size_of::<_>} != fn() -> usize {std::mem::size_of::<_>}
  |
  = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
Backtrace

0: <rustc_errors::HandlerInner>::emit_diagnostic
             1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &alloc::string::String>
             2: rustc_middle::ty::relate::super_relate_consts::<rustc_infer::infer::equate::Equate>
             3: <rustc_infer::infer::InferCtxt>::super_combine_consts::<rustc_infer::infer::equate::Equate>
             4: rustc_middle::ty::relate::super_relate_consts::<rustc_infer::infer::equate::Equate>
             5: <rustc_infer::infer::InferCtxt>::super_combine_consts::<rustc_infer::infer::equate::Equate>
             6: <rustc_infer::infer::InferCtxt>::commit_if_ok::<rustc_infer::infer::InferOk<()>, rustc_middle::ty::error::TypeError, <rustc_infer::infer::at::Trace>::eq<rustc_middle::ty::consts::Const>::{closure#0}>
             7: <rustc_infer::infer::at::At>::eq::<rustc_middle::ty::consts::Const>
             8: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
             9: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
            10: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_where_possible
            11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
            12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
            13: rustc_hir_typeck::check::check_fn
            14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_closure
            15: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
            16: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_argument_types
            17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
            18: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_argument_types
            19: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_call
            20: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
            21: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
            22: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
            23: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
            24: rustc_hir_typeck::check::check_fn
            25: rustc_hir_typeck::typeck
            26: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::typeck, rustc_query_impl::plumbing::QueryCtxt>
            27: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_typeck::typeck_item_bodies::{closure#0}>::{closure#0}>
            28: rustc_hir_typeck::typeck_item_bodies
            29: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
            30: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
            31: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#7}>
            32: rustc_hir_analysis::check_crate
            33: rustc_interface::passes::analysis
            34: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
            35: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
            36: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            37: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
            38: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
            39: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            40: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            41: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            42: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/2773383a314a4b8f481ce2bed12c32de794ffbe9/library/alloc/src/boxed.rs:1988:9
            43: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/2773383a314a4b8f481ce2bed12c32de794ffbe9/library/alloc/src/boxed.rs:1988:9
            44: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/2773383a314a4b8f481ce2bed12c32de794ffbe9/library/std/src/sys/unix/thread.rs:108:17
            45: start_thread
                       at ./nptl/./nptl/pthread_create.c:442:8
            46: clone3
                       at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

@chc4 chc4 added 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. labels Feb 11, 2023
@clubby789
Copy link
Contributor

@rustbot label +regression-from-stable-to-nightly

@rustbot rustbot added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 11, 2023
@clubby789
Copy link
Contributor

clubby789 commented Feb 11, 2023

searched nightlies: from nightly-2023-01-20 to nightly-2023-02-11
regressed nightly: nightly-2023-02-06
searched commit range: 50d3ba5...75a0be9
regressed commit: 2a6ff72

bisected with cargo-bisect-rustc v0.6.5

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc 2023-01-20 --regress=ice 

Regressed in #107434, same issue as #107898 I think

@BoxyUwU BoxyUwU closed this as completed Feb 11, 2023
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 11, 2023

Almost certainly a dupe of #107898, dont see any value in having both issues open. Thanks for the issue anyway :)

@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 11, 2023
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) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants