Skip to content

ICE with assoc const equality & closure: Type system constant with non valtree'able type evaluated but no error emitted #119783

Open
@fmease

Description

@fmease
Member

We don't employ any checks à la check_param_wf for assoc const equality constraints / we don't ensure that the type impls std::marker::ConstParamTy.

#![feature(associated_const_equality)]

trait Trait { const F: fn(); }

fn take(_: impl Trait<F = { || {} }>) {}

fn main() {}
error: internal compiler error: no errors encountered even though `span_delayed_bug` issued

error: internal compiler error: `ty::Const::eval` called on a non-valtree-compatible type
  |
  = note: delayed at /rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/compiler/rustc_middle/src/ty/consts.rs:325:39 - disabled backtrace
full stderr & backtrace
warning: function `take` is never used
 --> cl.rs:5:4
  |
5 | fn take(_: impl Trait<F = { || {} }>) {}
  |    ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

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

error: internal compiler error: `ty::Const::eval` called on a non-valtree-compatible type
  |
  = note: delayed at /rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/compiler/rustc_middle/src/ty/consts.rs:325:39
             0: <rustc_errors::DiagCtxtInner>::emit_diagnostic_without_consuming
             1: <rustc_errors::DiagCtxt>::emit_diagnostic_without_consuming
             2: <rustc_errors::DiagCtxt>::emit_diagnostic
             3: <rustc_errors::DiagCtxt>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
             4: <rustc_middle::ty::consts::Const>::eval.cold.0
             5: <rustc_trait_selection::traits::normalize_param_env_or_error::{closure#0}::ConstNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
             6: rustc_trait_selection::traits::normalize_param_env_or_error
             7: rustc_ty_utils::ty::param_env
             8: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::param_env::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
             9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            10: rustc_query_impl::query_impl::param_env::get_query_non_incr::__rust_end_short_backtrace
            11: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
            12: rustc_hir_analysis::check::wfcheck::check_item_fn
            13: rustc_hir_analysis::check::wfcheck::check_well_formed
            14: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            16: rustc_query_impl::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
            17: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
            18: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            19: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            20: rustc_query_impl::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
            21: <rustc_middle::hir::map::Map>::try_par_for_each_module::<rustc_hir_analysis::check_crate::{closure#4}::{closure#0}>::{closure#0}
            22: rustc_hir_analysis::check_crate
            23: rustc_interface::passes::analysis
            24: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            25: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            26: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
            27: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
            28: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            29: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            30: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/library/alloc/src/boxed.rs:2015:9
            31: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/library/alloc/src/boxed.rs:2015:9
            32: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/library/std/src/sys/unix/thread.rs:108:17
            33: <unknown>
            34: <unknown>


error: internal compiler error: `ty::Const::eval` called on a non-valtree-compatible type
  |
  = note: delayed at /rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/compiler/rustc_middle/src/ty/consts.rs:325:39
             0: <rustc_errors::DiagCtxtInner>::emit_diagnostic_without_consuming
             1: <rustc_errors::DiagCtxt>::emit_diagnostic_without_consuming
             2: <rustc_errors::DiagCtxt>::emit_diagnostic
             3: <rustc_errors::DiagCtxt>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
             4: <rustc_middle::ty::consts::Const>::eval.cold.0
             5: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
             6: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_type_ir::fold::FallibleTypeFolder<rustc_middle::ty::context::TyCtxt>>::try_fold_predicate.cold.0
             7: rustc_hir_analysis::check::wfcheck::check_where_clauses
             8: rustc_hir_analysis::check::wfcheck::check_fn_or_method
             9: rustc_hir_analysis::check::wfcheck::check_item_fn
            10: rustc_hir_analysis::check::wfcheck::check_well_formed
            11: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            13: rustc_query_impl::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
            14: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
            15: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            16: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            17: rustc_query_impl::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
            18: <rustc_middle::hir::map::Map>::try_par_for_each_module::<rustc_hir_analysis::check_crate::{closure#4}::{closure#0}>::{closure#0}
            19: rustc_hir_analysis::check_crate
            20: rustc_interface::passes::analysis
            21: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            22: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            23: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
            24: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
            25: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            26: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            27: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/library/alloc/src/boxed.rs:2015:9
            28: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/library/alloc/src/boxed.rs:2015:9
            29: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/library/std/src/sys/unix/thread.rs:108:17
            30: <unknown>
            31: <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 attach the file at `/home/fmease/programming/rust/rustc-ice-2024-01-09T21_08_54-23408.txt` to your bug report

query stack during panic:
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

rustc -Vv (old nightly but whatever):

rustc 1.77.0-nightly (3cdd004e5 2023-12-29)
binary: rustc
commit-hash: 3cdd004e55c869faa2b7b25efd3becf50346e7d6
commit-date: 2023-12-29
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Activity

added
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
on Jan 9, 2024
self-assigned this
on Jan 9, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 9, 2024
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 9, 2024
fmease

fmease commented on Jan 9, 2024

@fmease
MemberAuthor

I'm probably going to add a fix for this to my pre-existing PR #119385.

matthiaskrgr

matthiaskrgr commented on Jan 9, 2024

@matthiaskrgr
Member

Stacktrace looks similar to #119299

fmease

fmease commented on Jan 9, 2024

@fmease
MemberAuthor

Right, the symptom is identical (a non-valtree-compatible type was encountered during const eval while it should've been rejected earlier in the “pipeline”) but for F-associated_const_equality `#![feature(associated_const_equality)]` we likely need to reject this elsewhere compared to const generics.

Edit: However, since I will probably try to re-use the existing check_param_wf, we will still ICE for the assoc const eq analog of #119299. Time to look into #119299 then (or not ^^).

added
S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
on Apr 15, 2024
matthiaskrgr

matthiaskrgr commented on Nov 14, 2024

@matthiaskrgr
Member

auto-reduced (treereduce-rust):

#![feature(associated_const_equality)]

trait Trait {
    const F: fn();
}

fn take(_: impl Trait<F = { || {} }>) {}

fn main() {}

original:

#![feature(associated_const_equality)]

trait Trait { const F: fn(); }

fn take(_: impl Trait<F = { || {} }>) {}

fn main() {}

Version information

rustc 1.84.0-nightly (22bcb81c6 2024-11-14)
binary: rustc
commit-hash: 22bcb81c6636f8ccc24478f92b30bf9266f116ef
commit-date: 2024-11-14
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

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

Program output

warning: trait `Trait` is never used
 --> /tmp/icemaker_global_tempdir.TRjkuILpzvg9/rustc_testrunner_tmpdir_reporting.VqUqgtQAaZ9F/mvce.rs:3:7
  |
3 | trait Trait {
  |       ^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: function `take` is never used
 --> /tmp/icemaker_global_tempdir.TRjkuILpzvg9/rustc_testrunner_tmpdir_reporting.VqUqgtQAaZ9F/mvce.rs:7:4
  |
7 | fn take(_: impl Trait<F = { || {} }>) {}
  |    ^^^^

warning: 2 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: Type system constant with non valtree'able type evaluated but no error emitted
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/mod.rs:613:39 - disabled backtrace

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 (22bcb81c6 2024-11-14) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

@rustbot label +F-associated_const_equality

changed the title [-]ICE with assoc const equality & closure: `ty::Const::eval` called on a non-valtree-compatible type[/-] [+]ICE with assoc const equality & closure: `Type system constant with non valtree'able type evaluated but no error emitted`[/+] on Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-associated_const_equality`#![feature(associated_const_equality)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

To Do

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @matthiaskrgr@fmease@rustbot

      Issue actions

        ICE with assoc const equality & closure: `Type system constant with non valtree'able type evaluated but no error emitted` · Issue #119783 · rust-lang/rust