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. try_from_lit: received const param which shouldn't be possible #127972

Open
matthiaskrgr opened this issue Jul 19, 2024 · 4 comments
Open

ICE. try_from_lit: received const param which shouldn't be possible #127972

matthiaskrgr opened this issue Jul 19, 2024 · 4 comments
Assignees
Labels
C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jul 19, 2024

auto-reduced (treereduce-rust):

#![feature(generic_const_exprs)]

fn zero_init<const usize: usize>() -> Substs1<{ (N) }> {
    Substs1([0; { (usize) }])
}

original:

// run-pass
#![feature(generic_const_exprs)]
#![allow(incomplete_features, unused_parens, unused_braces)]

fn zero_init<const usize: usize>() -> Substs1<{ (N) }>
where
    [u8; { (usize) }]: ,
{
    Substs1([0; { (usize) }])
}

struct Substs1<const usize: usize>([u8; { (N) }])
where
    [(); { (usize) }]: ;

fn substs2<const M: usize>() -> Substs1<{ (M) }> {
    zero_init::<{ (M) }>()
}

fn substs3<const L: usize>() -> Substs1<{ (L) }> {
    substs2::<{ (L) }>()
}

fn main() {
    assert_eq!(substs3::<2>().0, [0; 2]);
}

// Test that the implicit ``{ (L) }`` bound on ``substs3`` satisfies the
// ``{ (N) }`` bound on ``Substs1``

Version information

rustc 1.81.0-nightly (11e57241f 2024-07-19)
binary: rustc
commit-hash: 11e57241f166194a328438d9264b68c98a18d51f
commit-date: 2024-07-19
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

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

Program output

error[E0412]: cannot find type `Substs1` in this scope
 --> /tmp/icemaker_global_tempdir.eb7oiLkfZ922/rustc_testrunner_tmpdir_reporting.s4RjyJctpWhy/mvce.rs:3:39
  |
3 | fn zero_init<const usize: usize>() -> Substs1<{ (N) }> {
  |                                       ^^^^^^^ not found in this scope

error[E0425]: cannot find value `N` in this scope
 --> /tmp/icemaker_global_tempdir.eb7oiLkfZ922/rustc_testrunner_tmpdir_reporting.s4RjyJctpWhy/mvce.rs:3:50
  |
3 | fn zero_init<const usize: usize>() -> Substs1<{ (N) }> {
  |                                                  ^ not found in this scope
  |
help: you might be missing a const parameter
  |
3 | fn zero_init<const usize: usize, const N: /* Type */>() -> Substs1<{ (N) }> {
  |                                +++++++++++++++++++++

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.eb7oiLkfZ922/rustc_testrunner_tmpdir_reporting.s4RjyJctpWhy/mvce.rs:1:12
  |
1 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: unnecessary parentheses around block return value
 --> /tmp/icemaker_global_tempdir.eb7oiLkfZ922/rustc_testrunner_tmpdir_reporting.s4RjyJctpWhy/mvce.rs:3:49
  |
3 | fn zero_init<const usize: usize>() -> Substs1<{ (N) }> {
  |                                                 ^ ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
3 - fn zero_init<const usize: usize>() -> Substs1<{ (N) }> {
3 + fn zero_init<const usize: usize>() -> Substs1<{ N }> {
  |

warning: unnecessary parentheses around block return value
 --> /tmp/icemaker_global_tempdir.eb7oiLkfZ922/rustc_testrunner_tmpdir_reporting.s4RjyJctpWhy/mvce.rs:4:19
  |
4 |     Substs1([0; { (usize) }])
  |                   ^     ^
  |
help: remove these parentheses
  |
4 -     Substs1([0; { (usize) }])
4 +     Substs1([0; { usize }])
  |

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

error: internal compiler error: compiler/rustc_middle/src/ty/consts.rs:322:13: try_from_lit: received const param which shouldn't be possible
 --> /tmp/icemaker_global_tempdir.eb7oiLkfZ922/rustc_testrunner_tmpdir_reporting.s4RjyJctpWhy/mvce.rs:4:19
  |
4 |     Substs1([0; { (usize) }])
  |                   ^^^^^^^

thread 'rustc' panicked at compiler/rustc_middle/src/ty/consts.rs:322:13:
Box<dyn Any>
stack backtrace:
   0:     0x712459dba125 - std::backtrace_rs::backtrace::libunwind::trace::hf98a5915ebb35e48
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x712459dba125 - std::backtrace_rs::backtrace::trace_unsynchronized::hd655af97e2fd6730
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x712459dba125 - std::sys::backtrace::_print_fmt::h621db2f84bb6c977
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/std/src/sys/backtrace.rs:65:5
   3:     0x712459dba125 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h15411039d8520454
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/std/src/sys/backtrace.rs:40:26
   4:     0x712459e09c2b - core::fmt::rt::Argument::fmt::h67bd01cd3519872c
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/core/src/fmt/rt.rs:173:76
   5:     0x712459e09c2b - core::fmt::write::hadd1ce33df102529
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/core/src/fmt/mod.rs:1182:21
   6:     0x712459daebff - std::io::Write::write_fmt::h2f869538ed52830c
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/std/src/io/mod.rs:1827:15
   7:     0x712459dbc911 - std::sys::backtrace::BacktraceLock::print::hbc3230efeae1e486
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/std/src/sys/backtrace.rs:43:9
   8:     0x712459dbc911 - std::panicking::default_hook::{{closure}}::h218c8d9fd7d09778
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/std/src/panicking.rs:269:22
   9:     0x712459dbc5ec - std::panicking::default_hook::hb07cda98c1c69610
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/std/src/panicking.rs:296:9
  10:     0x71245622d86a - std[6b173760e3c5fb6]::panicking::update_hook::<alloc[90d8a7b433d20df0]::boxed::Box<rustc_driver_impl[25cb91e50f1896ac]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x712459dbd2df - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h47aca6625104f576
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/alloc/src/boxed.rs:2084:9
  12:     0x712459dbd2df - std::panicking::rust_panic_with_hook::h4eb1d6a88426bb57
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/std/src/panicking.rs:808:13
  13:     0x712456268121 - std[6b173760e3c5fb6]::panicking::begin_panic::<rustc_errors[8a52d81e420a7663]::ExplicitBug>::{closure#0}
  14:     0x71245625af26 - std[6b173760e3c5fb6]::sys::backtrace::__rust_end_short_backtrace::<std[6b173760e3c5fb6]::panicking::begin_panic<rustc_errors[8a52d81e420a7663]::ExplicitBug>::{closure#0}, !>
  15:     0x71245625aed6 - std[6b173760e3c5fb6]::panicking::begin_panic::<rustc_errors[8a52d81e420a7663]::ExplicitBug>
  16:     0x7124562715a1 - <rustc_errors[8a52d81e420a7663]::diagnostic::BugAbort as rustc_errors[8a52d81e420a7663]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  17:     0x7124567e920d - <rustc_errors[8a52d81e420a7663]::DiagCtxtHandle>::span_bug::<rustc_span[bca8f273264d3c53]::span_encoding::Span, alloc[90d8a7b433d20df0]::string::String>
  18:     0x7124568879b8 - rustc_middle[d4947050f46ff72a]::util::bug::opt_span_bug_fmt::<rustc_span[bca8f273264d3c53]::span_encoding::Span>::{closure#0}
  19:     0x71245686db7a - rustc_middle[d4947050f46ff72a]::ty::context::tls::with_opt::<rustc_middle[d4947050f46ff72a]::util::bug::opt_span_bug_fmt<rustc_span[bca8f273264d3c53]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x71245686d9fb - rustc_middle[d4947050f46ff72a]::ty::context::tls::with_context_opt::<rustc_middle[d4947050f46ff72a]::ty::context::tls::with_opt<rustc_middle[d4947050f46ff72a]::util::bug::opt_span_bug_fmt<rustc_span[bca8f273264d3c53]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7124568878e7 - rustc_middle[d4947050f46ff72a]::util::bug::span_bug_fmt::<rustc_span[bca8f273264d3c53]::span_encoding::Span>
  22:     0x712458fb50bf - <rustc_middle[d4947050f46ff72a]::ty::consts::Const>::from_anon_const.cold
  23:     0x71245838f4ad - <rustc_hir_typeck[3d0bcd2c694d45c9]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  24:     0x712454440cad - <rustc_hir_typeck[3d0bcd2c694d45c9]::fn_ctxt::FnCtxt>::confirm_builtin_call
  25:     0x7124583888e8 - <rustc_hir_typeck[3d0bcd2c694d45c9]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7124583836e5 - <rustc_hir_typeck[3d0bcd2c694d45c9]::fn_ctxt::FnCtxt>::check_block_with_expected
  27:     0x71245838951d - <rustc_hir_typeck[3d0bcd2c694d45c9]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x712457bb74cf - rustc_hir_typeck[3d0bcd2c694d45c9]::check::check_fn
  29:     0x712458207381 - rustc_hir_typeck[3d0bcd2c694d45c9]::typeck
  30:     0x712458206d1d - rustc_query_impl[dfa85d359d8bf55f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[dfa85d359d8bf55f]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d4947050f46ff72a]::query::erase::Erased<[u8; 8usize]>>
  31:     0x712457bd8ab3 - rustc_query_system[5fd7963a6e62591]::query::plumbing::try_execute_query::<rustc_query_impl[dfa85d359d8bf55f]::DynamicConfig<rustc_query_system[5fd7963a6e62591]::query::caches::VecCache<rustc_span[bca8f273264d3c53]::def_id::LocalDefId, rustc_middle[d4947050f46ff72a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[dfa85d359d8bf55f]::plumbing::QueryCtxt, false>
  32:     0x712457bd7c8d - rustc_query_impl[dfa85d359d8bf55f]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  33:     0x712457bd788e - <rustc_middle[d4947050f46ff72a]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[67f94dc96106c366]::check_crate::{closure#4}>::{closure#0}
  34:     0x712457bd56ce - rustc_hir_analysis[67f94dc96106c366]::check_crate
  35:     0x712457bcbd95 - rustc_interface[e83b188aca6a6213]::passes::analysis
  36:     0x712457bcb947 - rustc_query_impl[dfa85d359d8bf55f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[dfa85d359d8bf55f]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d4947050f46ff72a]::query::erase::Erased<[u8; 1usize]>>
  37:     0x7124586c3965 - rustc_query_system[5fd7963a6e62591]::query::plumbing::try_execute_query::<rustc_query_impl[dfa85d359d8bf55f]::DynamicConfig<rustc_query_system[5fd7963a6e62591]::query::caches::SingleCache<rustc_middle[d4947050f46ff72a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[dfa85d359d8bf55f]::plumbing::QueryCtxt, false>
  38:     0x7124586c36cf - rustc_query_impl[dfa85d359d8bf55f]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7124585e8a05 - rustc_interface[e83b188aca6a6213]::interface::run_compiler::<core[9625cf1cb95ebe7c]::result::Result<(), rustc_span[bca8f273264d3c53]::ErrorGuaranteed>, rustc_driver_impl[25cb91e50f1896ac]::run_compiler::{closure#0}>::{closure#1}
  40:     0x7124585a1749 - std[6b173760e3c5fb6]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[e83b188aca6a6213]::util::run_in_thread_with_globals<rustc_interface[e83b188aca6a6213]::util::run_in_thread_pool_with_globals<rustc_interface[e83b188aca6a6213]::interface::run_compiler<core[9625cf1cb95ebe7c]::result::Result<(), rustc_span[bca8f273264d3c53]::ErrorGuaranteed>, rustc_driver_impl[25cb91e50f1896ac]::run_compiler::{closure#0}>::{closure#1}, core[9625cf1cb95ebe7c]::result::Result<(), rustc_span[bca8f273264d3c53]::ErrorGuaranteed>>::{closure#0}, core[9625cf1cb95ebe7c]::result::Result<(), rustc_span[bca8f273264d3c53]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9625cf1cb95ebe7c]::result::Result<(), rustc_span[bca8f273264d3c53]::ErrorGuaranteed>>
  41:     0x7124585a14fa - <<std[6b173760e3c5fb6]::thread::Builder>::spawn_unchecked_<rustc_interface[e83b188aca6a6213]::util::run_in_thread_with_globals<rustc_interface[e83b188aca6a6213]::util::run_in_thread_pool_with_globals<rustc_interface[e83b188aca6a6213]::interface::run_compiler<core[9625cf1cb95ebe7c]::result::Result<(), rustc_span[bca8f273264d3c53]::ErrorGuaranteed>, rustc_driver_impl[25cb91e50f1896ac]::run_compiler::{closure#0}>::{closure#1}, core[9625cf1cb95ebe7c]::result::Result<(), rustc_span[bca8f273264d3c53]::ErrorGuaranteed>>::{closure#0}, core[9625cf1cb95ebe7c]::result::Result<(), rustc_span[bca8f273264d3c53]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9625cf1cb95ebe7c]::result::Result<(), rustc_span[bca8f273264d3c53]::ErrorGuaranteed>>::{closure#2} as core[9625cf1cb95ebe7c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x712459dc733b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd3e0782f209a59bb
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/alloc/src/boxed.rs:2070:9
  43:     0x712459dc733b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2ffe75b9a73fa277
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/alloc/src/boxed.rs:2070:9
  44:     0x712459dc733b - std::sys::pal::unix::thread::Thread::new::thread_start::he38da8e39f41a015
                               at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/std/src/sys/pal/unix/thread.rs:108:17
  45:     0x712452ca6ded - <unknown>
  46:     0x712452d2a0dc - <unknown>
  47:                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.81.0-nightly (11e57241f 2024-07-19) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `zero_init`
#1 [analysis] running analysis passes on this crate
end of query stack
error[E0425]: cannot find function, tuple struct or tuple variant `Substs1` in this scope
 --> /tmp/icemaker_global_tempdir.eb7oiLkfZ922/rustc_testrunner_tmpdir_reporting.s4RjyJctpWhy/mvce.rs:4:5
  |
4 |     Substs1([0; { (usize) }])
  |     ^^^^^^^ not found in this scope

error: aborting due to 5 previous errors; 3 warnings emitted

Some errors have detailed explanations: E0412, E0425, E0601.
For more information about an error, try `rustc --explain E0412`.

@rustbot label +F-generic_const_exprs

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Jul 19, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Jul 19, 2024
@camelid
Copy link
Member

camelid commented Jul 19, 2024

This is probably due to my recent PR #125915. I'll look into what's going on. @rustbot claim

@camelid
Copy link
Member

camelid commented Jul 19, 2024

Ok Boxy and I discussed this. It seems like we just need to decide whether (N) is considered the same as N for the purpose of deciding between ConstArgKind::Path and ::Anon. Likely parts of rustc are thinking it's a path while others think it's an anon, causing the ICE.

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 20, 2024
@GrigorenkoPV
Copy link
Contributor

This is probably due to my recent PR #125915.

Yep, regresses to it. (And so does #127970)

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jul 23, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Jan 23, 2025

Less noisy repro (no separate errors)

struct Foo<const A: u32>;

fn foo<const X: u32>(_: Foo<{X::<()>}>) {}

@camelid camelid added the requires-nightly This issue requires a nightly compiler in some way. label Jan 25, 2025
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. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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

6 participants