rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.85k stars 12.77k forks source link

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

Open matthiaskrgr opened 4 months ago

matthiaskrgr commented 4 months ago

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() -> 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() -> Substs1<{ (N) }> { | ^ not found in this scope | help: you might be missing a const parameter | 3 | fn zero_init() -> 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 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() -> Substs1<{ (N) }> { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 3 - fn zero_init() -> Substs1<{ (N) }> { 3 + fn zero_init() -> 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 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 - ::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::>::{closure#0} 11: 0x712459dbd2df - as core::ops::function::Fn>::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::::{closure#0} 14: 0x71245625af26 - std[6b173760e3c5fb6]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 15: 0x71245625aed6 - std[6b173760e3c5fb6]::panicking::begin_panic:: 16: 0x7124562715a1 - ::emit_producing_guarantee 17: 0x7124567e920d - ::span_bug:: 18: 0x7124568879b8 - rustc_middle[d4947050f46ff72a]::util::bug::opt_span_bug_fmt::::{closure#0} 19: 0x71245686db7a - rustc_middle[d4947050f46ff72a]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 20: 0x71245686d9fb - rustc_middle[d4947050f46ff72a]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 21: 0x7124568878e7 - rustc_middle[d4947050f46ff72a]::util::bug::span_bug_fmt:: 22: 0x712458fb50bf - ::from_anon_const.cold 23: 0x71245838f4ad - ::check_expr_with_expectation_and_args 24: 0x712454440cad - ::confirm_builtin_call 25: 0x7124583888e8 - ::check_expr_with_expectation_and_args 26: 0x7124583836e5 - ::check_block_with_expected 27: 0x71245838951d - ::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::> 31: 0x712457bd8ab3 - rustc_query_system[5fd7963a6e62591]::query::plumbing::try_execute_query::>, 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 - ::par_body_owners::::{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::> 37: 0x7124586c3965 - rustc_query_system[5fd7963a6e62591]::query::plumbing::try_execute_query::>, 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::, rustc_driver_impl[25cb91e50f1896ac]::run_compiler::{closure#0}>::{closure#1} 40: 0x7124585a1749 - std[6b173760e3c5fb6]::sys::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - as core::ops::function::FnOnce>::call_once::hd3e0782f209a59bb at /rustc/11e57241f166194a328438d9264b68c98a18d51f/library/alloc/src/boxed.rs:2070:9 43: 0x712459dc733b - as core::ops::function::FnOnce>::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 - 46: 0x712452d2a0dc - 47: 0x0 - 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

camelid commented 4 months ago

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

camelid commented 4 months ago

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.

GrigorenkoPV commented 4 months ago

This is probably due to my recent PR #125915.

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