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: did not expect inference variables here #132955

Closed
matthiaskrgr opened this issue Nov 12, 2024 · 2 comments · Fixed by #132971
Closed

ICE: did not expect inference variables here #132955

matthiaskrgr opened this issue Nov 12, 2024 · 2 comments · Fixed by #132971
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

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

use std::mem;

pub trait HardcodedPayload {
    type ArrayType: AsRef<[u8]> + AsMut<[u8]> + Default + PartialEq;
    const PAYLOAD: Self::ArrayType;

    fn test() {
        let mut buf = [0u8; mem::size_of::<Self::ArrayType>()];

        if buf == Self::PAYLOAD {}
    }
}

original:

#![allow(incomplete_features)]
#![feature(const_generics, const_evaluatable_checked)]

use std::mem;

pub trait HardcodedPayload {
    type ArrayType: AsRef<[u8]> + AsMut<[u8]> + Default + PartialEq;
    const PAYLOAD: Self::ArrayType;

    fn test() where [u8; mem::size_of::<Self::ArrayType>()]: Sized + PartialEq { //workaround for `[u8; N]`
        let mut buf = [0u8; mem::size_of::<Self::ArrayType>()];
        //*insert read here*
        if buf == Self::PAYLOAD {} //crashed here
    }
}

pub struct UserStruct {
    _a: i32,
}

impl HardcodedPayload for UserStruct {
    type ArrayType = [u8; 2];
    const PAYLOAD: Self::ArrayType = [0xff, 0xff];
}

fn main() {}

Version information

rustc 1.84.0-nightly (583b25d8d 2024-11-12)
binary: rustc
commit-hash: 583b25d8d1bf934f593d9d9811f88305888032b5
commit-date: 2024-11-12
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Possibly related line of code:

// variables. We reject those here since `resolve`
// would fail otherwise.
//
// When trying to evaluate constants containing inference variables,
// use `Infcx::const_eval_resolve` instead.
if ct.args.has_non_region_infer() {
bug!("did not expect inference variables here");
}
match ty::Instance::try_resolve(self, param_env, ct.def, ct.args) {
Ok(Some(instance)) => {
let cid = GlobalId { instance, promoted: None };
self.const_eval_global_id_for_typeck(param_env, cid, span).inspect(|_| {

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

Program output

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

error: constant expression depends on a generic parameter
 --> /tmp/icemaker_global_tempdir.Rm5p7wMtuTgP/rustc_testrunner_tmpdir_reporting.KnRv1MI2yL1X/mvce.rs:8:29
  |
8 |         let mut buf = [0u8; mem::size_of::<Self::ArrayType>()];
  |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
  --> /tmp/icemaker_global_tempdir.Rm5p7wMtuTgP/rustc_testrunner_tmpdir_reporting.KnRv1MI2yL1X/mvce.rs:10:16
   |
10 |         if buf == Self::PAYLOAD {}
   |                ^^
   |
   = note: this may fail depending on what value the parameter takes

error: internal compiler error: compiler/rustc_middle/src/mir/interpret/queries.rs:105:13: did not expect inference variables here

thread 'rustc' panicked at compiler/rustc_middle/src/mir/interpret/queries.rs:105:13:
Box<dyn Any>
stack backtrace:
   0:     0x772aabc3edfa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1be162dc2503466c
   1:     0x772aac404126 - core::fmt::write::h280382204c276f4c
   2:     0x772aad8d34d1 - std::io::Write::write_fmt::h04f2b42af7342ff5
   3:     0x772aabc3ec52 - std::sys::backtrace::BacktraceLock::print::h7c048bae86e9ad26
   4:     0x772aabc41156 - std::panicking::default_hook::{{closure}}::hc244b26161cd3277
   5:     0x772aabc40fa0 - std::panicking::default_hook::h24f5ce4ffd208338
   6:     0x772aaacd1271 - std[d1ae3bd9e9976c39]::panicking::update_hook::<alloc[4c76250b199c2804]::boxed::Box<rustc_driver_impl[a2c21c8cc38ba0fe]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x772aabc41868 - std::panicking::rust_panic_with_hook::he0ab4d877fd6a339
   8:     0x772aaad0af71 - std[d1ae3bd9e9976c39]::panicking::begin_panic::<rustc_errors[e1f0737afb2aef5d]::ExplicitBug>::{closure#0}
   9:     0x772aaacfdf46 - std[d1ae3bd9e9976c39]::sys::backtrace::__rust_end_short_backtrace::<std[d1ae3bd9e9976c39]::panicking::begin_panic<rustc_errors[e1f0737afb2aef5d]::ExplicitBug>::{closure#0}, !>
  10:     0x772aaacfdf0d - std[d1ae3bd9e9976c39]::panicking::begin_panic::<rustc_errors[e1f0737afb2aef5d]::ExplicitBug>
  11:     0x772aaad14c91 - <rustc_errors[e1f0737afb2aef5d]::diagnostic::BugAbort as rustc_errors[e1f0737afb2aef5d]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x772aab391e03 - rustc_middle[805d92c067a49ea3]::util::bug::opt_span_bug_fmt::<rustc_span[1918eb9e81a65bcc]::span_encoding::Span>::{closure#0}
  13:     0x772aab3786da - rustc_middle[805d92c067a49ea3]::ty::context::tls::with_opt::<rustc_middle[805d92c067a49ea3]::util::bug::opt_span_bug_fmt<rustc_span[1918eb9e81a65bcc]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x772aab37856b - rustc_middle[805d92c067a49ea3]::ty::context::tls::with_context_opt::<rustc_middle[805d92c067a49ea3]::ty::context::tls::with_opt<rustc_middle[805d92c067a49ea3]::util::bug::opt_span_bug_fmt<rustc_span[1918eb9e81a65bcc]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x772aa932b600 - rustc_middle[805d92c067a49ea3]::util::bug::bug_fmt
  16:     0x772aadec6703 - <rustc_middle[805d92c067a49ea3]::ty::context::TyCtxt>::const_eval_resolve_for_typeck.cold
  17:     0x772aace8f68d - rustc_trait_selection[6ddd4e54a994aae0]::traits::try_evaluate_const
  18:     0x772aacdef60d - <rustc_trait_selection[6ddd4e54a994aae0]::traits::normalize::AssocTypeNormalizer as rustc_type_ir[3fa720567fea6e5f]::fold::TypeFolder<rustc_middle[805d92c067a49ea3]::ty::context::TyCtxt>>::fold_const
  19:     0x772aacdf46ec - <rustc_middle[805d92c067a49ea3]::ty::Ty as rustc_type_ir[3fa720567fea6e5f]::fold::TypeSuperFoldable<rustc_middle[805d92c067a49ea3]::ty::context::TyCtxt>>::try_super_fold_with::<rustc_trait_selection[6ddd4e54a994aae0]::traits::normalize::AssocTypeNormalizer>
  20:     0x772aacdf2653 - <&rustc_middle[805d92c067a49ea3]::ty::list::RawList<(), rustc_middle[805d92c067a49ea3]::ty::generic_args::GenericArg> as rustc_type_ir[3fa720567fea6e5f]::fold::TypeFoldable<rustc_middle[805d92c067a49ea3]::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection[6ddd4e54a994aae0]::traits::normalize::AssocTypeNormalizer>
  21:     0x772aad77fa89 - <rustc_trait_selection[6ddd4e54a994aae0]::traits::normalize::AssocTypeNormalizer>::fold::<rustc_type_ir[3fa720567fea6e5f]::binder::Binder<rustc_middle[805d92c067a49ea3]::ty::context::TyCtxt, rustc_type_ir[3fa720567fea6e5f]::predicate::TraitPredicate<rustc_middle[805d92c067a49ea3]::ty::context::TyCtxt>>>
  22:     0x772aad77f5c4 - rustc_trait_selection[6ddd4e54a994aae0]::traits::normalize::normalize_with_depth_to::<rustc_type_ir[3fa720567fea6e5f]::binder::Binder<rustc_middle[805d92c067a49ea3]::ty::context::TyCtxt, rustc_type_ir[3fa720567fea6e5f]::predicate::TraitPredicate<rustc_middle[805d92c067a49ea3]::ty::context::TyCtxt>>>
  23:     0x772aaba89b72 - <rustc_trait_selection[6ddd4e54a994aae0]::error_reporting::TypeErrCtxt>::try_to_add_help_message
  24:     0x772aaba7867f - <rustc_trait_selection[6ddd4e54a994aae0]::error_reporting::TypeErrCtxt>::report_selection_error
  25:     0x772aabaf3448 - <rustc_trait_selection[6ddd4e54a994aae0]::error_reporting::TypeErrCtxt>::report_fulfillment_error
  26:     0x772aabac14fd - <rustc_trait_selection[6ddd4e54a994aae0]::error_reporting::TypeErrCtxt>::report_fulfillment_errors
  27:     0x772aacdebf51 - <rustc_hir_typeck[a15215e6f6be142b]::fn_ctxt::FnCtxt>::type_inference_fallback
  28:     0x772aac617282 - rustc_hir_typeck[a15215e6f6be142b]::typeck
  29:     0x772aac616c13 - rustc_query_impl[108f2a4105e551cb]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[108f2a4105e551cb]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[805d92c067a49ea3]::query::erase::Erased<[u8; 8usize]>>
  30:     0x772aaca70401 - rustc_query_system[2e0a7198de1e86af]::query::plumbing::try_execute_query::<rustc_query_impl[108f2a4105e551cb]::DynamicConfig<rustc_query_system[2e0a7198de1e86af]::query::caches::VecCache<rustc_span[1918eb9e81a65bcc]::def_id::LocalDefId, rustc_middle[805d92c067a49ea3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[108f2a4105e551cb]::plumbing::QueryCtxt, false>
  31:     0x772aaca6eacd - rustc_query_impl[108f2a4105e551cb]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  32:     0x772aaca6e747 - <rustc_middle[805d92c067a49ea3]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[c524f426caea01c1]::check_crate::{closure#4}>::{closure#0}
  33:     0x772aaca6c719 - rustc_hir_analysis[c524f426caea01c1]::check_crate
  34:     0x772aaca5cfca - rustc_interface[a611b3338a51bb01]::passes::run_required_analyses
  35:     0x772aad2647de - rustc_interface[a611b3338a51bb01]::passes::analysis
  36:     0x772aad2647af - rustc_query_impl[108f2a4105e551cb]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[108f2a4105e551cb]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[805d92c067a49ea3]::query::erase::Erased<[u8; 1usize]>>
  37:     0x772aad3e47ae - rustc_query_system[2e0a7198de1e86af]::query::plumbing::try_execute_query::<rustc_query_impl[108f2a4105e551cb]::DynamicConfig<rustc_query_system[2e0a7198de1e86af]::query::caches::SingleCache<rustc_middle[805d92c067a49ea3]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[108f2a4105e551cb]::plumbing::QueryCtxt, false>
  38:     0x772aad3e448e - rustc_query_impl[108f2a4105e551cb]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  39:     0x772aad2d9afa - rustc_interface[a611b3338a51bb01]::interface::run_compiler::<core[47714ff89ab7fdfe]::result::Result<(), rustc_span[1918eb9e81a65bcc]::ErrorGuaranteed>, rustc_driver_impl[a2c21c8cc38ba0fe]::run_compiler::{closure#0}>::{closure#1}
  40:     0x772aad327950 - std[d1ae3bd9e9976c39]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a611b3338a51bb01]::util::run_in_thread_with_globals<rustc_interface[a611b3338a51bb01]::util::run_in_thread_pool_with_globals<rustc_interface[a611b3338a51bb01]::interface::run_compiler<core[47714ff89ab7fdfe]::result::Result<(), rustc_span[1918eb9e81a65bcc]::ErrorGuaranteed>, rustc_driver_impl[a2c21c8cc38ba0fe]::run_compiler::{closure#0}>::{closure#1}, core[47714ff89ab7fdfe]::result::Result<(), rustc_span[1918eb9e81a65bcc]::ErrorGuaranteed>>::{closure#0}, core[47714ff89ab7fdfe]::result::Result<(), rustc_span[1918eb9e81a65bcc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[47714ff89ab7fdfe]::result::Result<(), rustc_span[1918eb9e81a65bcc]::ErrorGuaranteed>>
  41:     0x772aad327d6b - <<std[d1ae3bd9e9976c39]::thread::Builder>::spawn_unchecked_<rustc_interface[a611b3338a51bb01]::util::run_in_thread_with_globals<rustc_interface[a611b3338a51bb01]::util::run_in_thread_pool_with_globals<rustc_interface[a611b3338a51bb01]::interface::run_compiler<core[47714ff89ab7fdfe]::result::Result<(), rustc_span[1918eb9e81a65bcc]::ErrorGuaranteed>, rustc_driver_impl[a2c21c8cc38ba0fe]::run_compiler::{closure#0}>::{closure#1}, core[47714ff89ab7fdfe]::result::Result<(), rustc_span[1918eb9e81a65bcc]::ErrorGuaranteed>>::{closure#0}, core[47714ff89ab7fdfe]::result::Result<(), rustc_span[1918eb9e81a65bcc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[47714ff89ab7fdfe]::result::Result<(), rustc_span[1918eb9e81a65bcc]::ErrorGuaranteed>>::{closure#1} as core[47714ff89ab7fdfe]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x772aad328839 - std::sys::pal::unix::thread::Thread::new::thread_start::hde7850bcdc5229ae
  43:     0x772aaec3939d - <unknown>
  44:     0x772aaecbe49c - <unknown>
  45:                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: please make sure that you have updated to the latest nightly

note: rustc 1.84.0-nightly (583b25d8d 2024-11-12) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `HardcodedPayload::test`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0601`.

@matthiaskrgr matthiaskrgr 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 Nov 12, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 12, 2024
@matthiaskrgr
Copy link
Member Author

#132927 cc @BoxyUwU

@matthiaskrgr
Copy link
Member Author

smaller

pub trait T {
    type A;
    const P: Self::A;

    fn a() {
        [0u8; std::mem::size_of::<Self::A>()] == Self::P;
    }
}

@BoxyUwU BoxyUwU self-assigned this Nov 12, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 13, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 13, 2024
…ts, r=compiler-errors

Handle infer vars in anon consts on stable

Fixes rust-lang#132955

Diagnostics will sometimes try to replace generic parameters with inference variables in failing goals. This means that if we have some failing goal with an array repeat expr count anon const in it, we will wind up with some `ty::ConstKind::Unevaluated(anon_const_def, [?x])` during diagnostics which will then ICE if we do not handle inference variables correctly on stable when normalizing type system consts.

r? `@compiler-errors`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 13, 2024
…ts, r=compiler-errors

Handle infer vars in anon consts on stable

Fixes rust-lang#132955

Diagnostics will sometimes try to replace generic parameters with inference variables in failing goals. This means that if we have some failing goal with an array repeat expr count anon const in it, we will wind up with some `ty::ConstKind::Unevaluated(anon_const_def, [?x])` during diagnostics which will then ICE if we do not handle inference variables correctly on stable when normalizing type system consts.

r? ``@compiler-errors``
@bors bors closed this as completed in aa18946 Nov 14, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 14, 2024
Rollup merge of rust-lang#132971 - BoxyUwU:handle_infers_in_anon_consts, r=compiler-errors

Handle infer vars in anon consts on stable

Fixes rust-lang#132955

Diagnostics will sometimes try to replace generic parameters with inference variables in failing goals. This means that if we have some failing goal with an array repeat expr count anon const in it, we will wind up with some `ty::ConstKind::Unevaluated(anon_const_def, [?x])` during diagnostics which will then ICE if we do not handle inference variables correctly on stable when normalizing type system consts.

r? ```@compiler-errors```
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.

4 participants