Skip to content

const adt params and const mut refs ICE #100313

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

Closed
DutchGhost opened this issue Aug 9, 2022 · 2 comments · Fixed by #100359
Closed

const adt params and const mut refs ICE #100313

DutchGhost opened this issue Aug 9, 2022 · 2 comments · Fixed by #100359
Assignees
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

@DutchGhost
Copy link
Contributor

DutchGhost commented Aug 9, 2022

I know the code below is wrong, but I expect a normal compiler error rather than an ICE.

Code

#![feature(const_mut_refs)]
#![feature(adt_const_params)]

struct T<const B: &'static bool>;

impl <const B: &'static bool> T<B> {
    const fn set_false(&self) {
        unsafe {
            *(B as *const bool as *mut bool) = false;
        }
    }
}

const _: () = {
    let x = T::<{&true}>;
    x.set_false();
};

fn main() {
    
}

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (f03ce3096 2022-08-08)

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/consts/int.rs:220:13: expected int of size 8, but got size 1
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/compiler/rustc_errors/src/lib.rs:1392:9
stack backtrace:
   0:     0x7f3fe7e5ec60 - std::backtrace_rs::backtrace::libunwind::trace::he73bf82d737d304d
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f3fe7e5ec60 - std::backtrace_rs::backtrace::trace_unsynchronized::h07fc55aea59a0f98
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f3fe7e5ec60 - std::sys_common::backtrace::_print_fmt::h8a2fa659aab33962
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f3fe7e5ec60 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8d53bccf60c06da7
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f3fe7eba62c - core::fmt::write::hc4adad996c06bcaa
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/core/src/fmt/mod.rs:1198:17
   5:     0x7f3fe7e4fca5 - std::io::Write::write_fmt::h46dfa8a98fb93088
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/io/mod.rs:1672:15
   6:     0x7f3fe7e61941 - std::sys_common::backtrace::_print::h42e4c3a53bdb0e01
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f3fe7e61941 - std::sys_common::backtrace::print::h49df31fe119a7172
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f3fe7e61941 - std::panicking::default_hook::{{closure}}::h915c48a155020ec1
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/panicking.rs:295:22
   9:     0x7f3fe7e6160e - std::panicking::default_hook::hc62fd81d406d34d4
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/panicking.rs:314:9
  10:     0x7f3fea6d9024 - <rustc_driver[f63e02b65247c824]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[bdb6c2c9b92b14cf]::ops::function::FnOnce<(&core[bdb6c2c9b92b14cf]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f3fe7e62176 - std::panicking::rust_panic_with_hook::hc8104bd1930d34de
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/panicking.rs:702:17
  12:     0x7f3feb6768b1 - std[d287d5bb05f95ef6]::panicking::begin_panic::<rustc_errors[cc7e50c8484f644f]::ExplicitBug>::{closure#0}
  13:     0x7f3feb676236 - std[d287d5bb05f95ef6]::sys_common::backtrace::__rust_end_short_backtrace::<std[d287d5bb05f95ef6]::panicking::begin_panic<rustc_errors[cc7e50c8484f644f]::ExplicitBug>::{closure#0}, !>
  14:     0x7f3feb658906 - std[d287d5bb05f95ef6]::panicking::begin_panic::<rustc_errors[cc7e50c8484f644f]::ExplicitBug>
  15:     0x7f3feb69c376 - std[d287d5bb05f95ef6]::panic::panic_any::<rustc_errors[cc7e50c8484f644f]::ExplicitBug>
  16:     0x7f3feb69ba35 - <rustc_errors[cc7e50c8484f644f]::HandlerInner>::bug::<&alloc[b42d50d8077e1268]::string::String>
  17:     0x7f3feb69b790 - <rustc_errors[cc7e50c8484f644f]::Handler>::bug::<&alloc[b42d50d8077e1268]::string::String>
  18:     0x7f3feb6c09fd - rustc_middle[b803c3f789f93a69]::ty::context::tls::with_context_opt::<rustc_middle[b803c3f789f93a69]::ty::context::tls::with_opt<rustc_middle[b803c3f789f93a69]::util::bug::opt_span_bug_fmt<rustc_span[b2129a79ff31bdef]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  19:     0x7f3feb6c3ab6 - rustc_middle[b803c3f789f93a69]::util::bug::opt_span_bug_fmt::<rustc_span[b2129a79ff31bdef]::span_encoding::Span>
  20:     0x7f3fe9132783 - rustc_middle[b803c3f789f93a69]::util::bug::bug_fmt
  21:     0x7f3feb664d72 - <rustc_middle[b803c3f789f93a69]::ty::print::pretty::FmtPrinter as rustc_middle[b803c3f789f93a69]::ty::print::pretty::PrettyPrinter>::pretty_print_const_scalar_int
  22:     0x7f3feb665c33 - <rustc_middle[b803c3f789f93a69]::ty::print::pretty::FmtPrinter as rustc_middle[b803c3f789f93a69]::ty::print::pretty::PrettyPrinter>::pretty_print_const_valtree
  23:     0x7f3feb66336a - <rustc_middle[b803c3f789f93a69]::ty::print::pretty::FmtPrinter as rustc_middle[b803c3f789f93a69]::ty::print::pretty::PrettyPrinter>::pretty_print_const
  24:     0x7f3fea451a74 - <rustc_middle[b803c3f789f93a69]::ty::print::pretty::FmtPrinter as rustc_middle[b803c3f789f93a69]::ty::print::Printer>::print_def_path
  25:     0x7f3fea44e07d - <rustc_middle[b803c3f789f93a69]::ty::print::pretty::FmtPrinter as rustc_middle[b803c3f789f93a69]::ty::print::pretty::PrettyPrinter>::pretty_print_type
  26:     0x7f3fea453691 - <rustc_middle[b803c3f789f93a69]::ty::print::pretty::FmtPrinter as rustc_middle[b803c3f789f93a69]::ty::print::Printer>::path_qualified
  27:     0x7f3fea45118f - <rustc_middle[b803c3f789f93a69]::ty::print::pretty::FmtPrinter as rustc_middle[b803c3f789f93a69]::ty::print::Printer>::print_def_path
  28:     0x7f3fea450934 - <rustc_middle[b803c3f789f93a69]::ty::print::pretty::FmtPrinter as rustc_middle[b803c3f789f93a69]::ty::print::Printer>::print_def_path
  29:     0x7f3fe97a286b - <rustc_middle[b803c3f789f93a69]::ty::instance::Instance as core[bdb6c2c9b92b14cf]::fmt::Display>::fmt
  30:     0x7f3fe7eba62c - core::fmt::write::hc4adad996c06bcaa
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/core/src/fmt/mod.rs:1198:17
  31:     0x7f3fe7ebb534 - core::fmt::Formatter::write_fmt::hd4f816e5f30408b7
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/core/src/fmt/mod.rs:1652:9
  32:     0x7f3feae62390 - <rustc_const_eval[201bffe6500e0095]::interpret::eval_context::FrameInfo as core[bdb6c2c9b92b14cf]::fmt::Display>::fmt
  33:     0x7f3feae863b7 - <rustc_const_eval[201bffe6500e0095]::const_eval::error::ConstEvalErr>::struct_generic::<<rustc_const_eval[201bffe6500e0095]::const_eval::error::ConstEvalErr>::report_as_error::{closure#0}>::{closure#0}
  34:     0x7f3fe97a2c4b - <rustc_const_eval[201bffe6500e0095]::const_eval::error::ConstEvalErr>::report_as_error
  35:     0x7f3fe970d5dd - rustc_const_eval[201bffe6500e0095]::const_eval::eval_queries::eval_to_allocation_raw_provider
  36:     0x7f3fe9fcc4bf - rustc_query_system[bac2197a4722c86]::query::plumbing::get_query::<rustc_query_impl[6734c5934d4739f0]::queries::eval_to_allocation_raw, rustc_query_impl[6734c5934d4739f0]::plumbing::QueryCtxt>
  37:     0x7f3fe9fcc085 - <rustc_query_impl[6734c5934d4739f0]::Queries as rustc_middle[b803c3f789f93a69]::ty::query::QueryEngine>::eval_to_allocation_raw
  38:     0x7f3fea0fe88b - rustc_const_eval[201bffe6500e0095]::const_eval::eval_queries::eval_to_const_value_raw_provider
  39:     0x7f3fe9c746c0 - rustc_query_system[bac2197a4722c86]::query::plumbing::get_query::<rustc_query_impl[6734c5934d4739f0]::queries::eval_to_const_value_raw, rustc_query_impl[6734c5934d4739f0]::plumbing::QueryCtxt>
  40:     0x7f3fe9c74285 - <rustc_query_impl[6734c5934d4739f0]::Queries as rustc_middle[b803c3f789f93a69]::ty::query::QueryEngine>::eval_to_const_value_raw
  41:     0x7f3fea0fe736 - rustc_const_eval[201bffe6500e0095]::const_eval::eval_queries::eval_to_const_value_raw_provider
  42:     0x7f3fe9c746c0 - rustc_query_system[bac2197a4722c86]::query::plumbing::get_query::<rustc_query_impl[6734c5934d4739f0]::queries::eval_to_const_value_raw, rustc_query_impl[6734c5934d4739f0]::plumbing::QueryCtxt>
  43:     0x7f3fe9c74285 - <rustc_query_impl[6734c5934d4739f0]::Queries as rustc_middle[b803c3f789f93a69]::ty::query::QueryEngine>::eval_to_const_value_raw
  44:     0x7f3fe9b116a1 - <rustc_middle[b803c3f789f93a69]::ty::query::TyCtxtEnsure>::const_eval_poly
  45:     0x7f3fe9b0dc9b - <rustc_lint[3fc1eb8939f490e7]::BuiltinCombinedModuleLateLintPass as rustc_lint[3fc1eb8939f490e7]::passes::LateLintPass>::check_item
  46:     0x7f3fe9b09d24 - rustc_hir[7de338cdf5457711]::intravisit::walk_mod::<rustc_lint[3fc1eb8939f490e7]::late::LateContextAndPass<rustc_lint[3fc1eb8939f490e7]::BuiltinCombinedModuleLateLintPass>>
  47:     0x7f3fe9b0903f - rustc_lint[3fc1eb8939f490e7]::late::late_lint_mod::<rustc_lint[3fc1eb8939f490e7]::BuiltinCombinedModuleLateLintPass>
  48:     0x7f3fe9b08e7a - rustc_lint[3fc1eb8939f490e7]::lint_mod
  49:     0x7f3fe993c08b - rustc_query_system[bac2197a4722c86]::query::plumbing::try_execute_query::<rustc_query_impl[6734c5934d4739f0]::plumbing::QueryCtxt, rustc_query_system[bac2197a4722c86]::query::caches::DefaultCache<rustc_span[b2129a79ff31bdef]::def_id::LocalDefId, ()>>
  50:     0x7f3fea130b47 - rustc_query_system[bac2197a4722c86]::query::plumbing::get_query::<rustc_query_impl[6734c5934d4739f0]::queries::lint_mod, rustc_query_impl[6734c5934d4739f0]::plumbing::QueryCtxt>
  51:     0x7f3fea335c20 - <rustc_middle[b803c3f789f93a69]::hir::map::Map>::for_each_module::<rustc_lint[3fc1eb8939f490e7]::late::check_crate<rustc_lint[3fc1eb8939f490e7]::BuiltinCombinedLateLintPass, rustc_interface[e7882ae3c034202e]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}::{closure#0}>
  52:     0x7f3fea335893 - <rustc_session[80c748b3cc6f0c9d]::session::Session>::time::<(), rustc_lint[3fc1eb8939f490e7]::late::check_crate<rustc_lint[3fc1eb8939f490e7]::BuiltinCombinedLateLintPass, rustc_interface[e7882ae3c034202e]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}>
  53:     0x7f3fea0b8134 - <rustc_session[80c748b3cc6f0c9d]::session::Session>::time::<(), rustc_interface[e7882ae3c034202e]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}>
  54:     0x7f3fea0b7f31 - <core[bdb6c2c9b92b14cf]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[e7882ae3c034202e]::passes::analysis::{closure#5}::{closure#1}> as core[bdb6c2c9b92b14cf]::ops::function::FnOnce<()>>::call_once
  55:     0x7f3fea0b7a5a - <rustc_session[80c748b3cc6f0c9d]::session::Session>::time::<(), rustc_interface[e7882ae3c034202e]::passes::analysis::{closure#5}>
  56:     0x7f3fea0b53ec - rustc_interface[e7882ae3c034202e]::passes::analysis
  57:     0x7f3fea473555 - rustc_query_system[bac2197a4722c86]::query::plumbing::try_execute_query::<rustc_query_impl[6734c5934d4739f0]::plumbing::QueryCtxt, rustc_query_system[bac2197a4722c86]::query::caches::DefaultCache<(), core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>>>
  58:     0x7f3fea4732de - rustc_query_system[bac2197a4722c86]::query::plumbing::get_query::<rustc_query_impl[6734c5934d4739f0]::queries::analysis, rustc_query_impl[6734c5934d4739f0]::plumbing::QueryCtxt>
  59:     0x7f3fe9eba4da - <rustc_interface[e7882ae3c034202e]::interface::Compiler>::enter::<rustc_driver[f63e02b65247c824]::run_compiler::{closure#1}::{closure#2}, core[bdb6c2c9b92b14cf]::result::Result<core[bdb6c2c9b92b14cf]::option::Option<rustc_interface[e7882ae3c034202e]::queries::Linker>, rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>>
  60:     0x7f3fe9eadeea - rustc_span[b2129a79ff31bdef]::with_source_map::<core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>, rustc_interface[e7882ae3c034202e]::interface::create_compiler_and_run<core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>, rustc_driver[f63e02b65247c824]::run_compiler::{closure#1}>::{closure#1}>
  61:     0x7f3fe9ead8c0 - rustc_interface[e7882ae3c034202e]::interface::create_compiler_and_run::<core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>, rustc_driver[f63e02b65247c824]::run_compiler::{closure#1}>
  62:     0x7f3fe9eabc31 - <scoped_tls[422d342b8ce384f1]::ScopedKey<rustc_span[b2129a79ff31bdef]::SessionGlobals>>::set::<rustc_interface[e7882ae3c034202e]::interface::run_compiler<core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>, rustc_driver[f63e02b65247c824]::run_compiler::{closure#1}>::{closure#0}, core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>>
  63:     0x7f3fe9eab91f - std[d287d5bb05f95ef6]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[e7882ae3c034202e]::util::run_in_thread_pool_with_globals<rustc_interface[e7882ae3c034202e]::interface::run_compiler<core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>, rustc_driver[f63e02b65247c824]::run_compiler::{closure#1}>::{closure#0}, core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>>::{closure#0}, core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>>
  64:     0x7f3fea502389 - <<std[d287d5bb05f95ef6]::thread::Builder>::spawn_unchecked_<rustc_interface[e7882ae3c034202e]::util::run_in_thread_pool_with_globals<rustc_interface[e7882ae3c034202e]::interface::run_compiler<core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>, rustc_driver[f63e02b65247c824]::run_compiler::{closure#1}>::{closure#0}, core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>>::{closure#0}, core[bdb6c2c9b92b14cf]::result::Result<(), rustc_errors[cc7e50c8484f644f]::ErrorGuaranteed>>::{closure#1} as core[bdb6c2c9b92b14cf]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  65:     0x7f3fe7e6c143 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc6c6702d9d7f8ac5
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/alloc/src/boxed.rs:1935:9
  66:     0x7f3fe7e6c143 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6ca0aa1af63cbeae
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/alloc/src/boxed.rs:1935:9
  67:     0x7f3fe7e6c143 - std::sys::unix::thread::Thread::new::thread_start::h79459e84af59d3fc
                               at /rustc/f03ce30962cf1b2a5158667eabae8bf6e8d1cb03/library/std/src/sys/unix/thread.rs:108:17
  68:     0x7f3fe7d3e609 - start_thread
  69:     0x7f3fe7c61133 - clone
  70:                0x0 - <unknown>

@DutchGhost DutchGhost 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 Aug 9, 2022
@DutchGhost DutchGhost changed the title const adt params and mut refs ICE const adt params and const mut refs ICE Aug 9, 2022
@DutchGhost
Copy link
Contributor Author

It's funny, if I replace the bool with an integral type of size 8, I get a normal error:

#![feature(const_mut_refs)]
#![feature(adt_const_params)]

struct T<const B: &'static u64>;

impl <const B: &'static u64> T<B> {
    const fn set_false(&self) {
        unsafe {
            *(B as *const u64 as *mut u64) -= 1;
        }
    }
}

const _: () = {
    let x = T::<{&1}>;
    x.set_false();
};

fn main() {
    
}
error[[E0080]](https://doc.rust-lang.org/nightly/error-index.html#E0080): evaluation of constant value failed
  --> src/main.rs:9:13
   |
9  |             *(B as *const u64 as *mut u64) -= 1;
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |             |
   |             writing to alloc7 which is read-only
   |             inside `T::<{0x1 as &u64}>::set_false` at src/main.rs:9:13
...
16 |     x.set_false();
   |     ------------- inside `_` at src/main.rs:16:5

@b-naber
Copy link
Contributor

b-naber commented Aug 9, 2022

@rustbot claim

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.

2 participants