Closed
Description
auto-reduced (treereduce-rust):
const fn concat_strs<const A: &'static str>() -> &'static str {
#[repr(C)]
#[repr(C)]
struct Inner<const A: &'static str>;
Inner::concat_strs::<FOO, BAR>::ABSTR
}
const FOO: &str = "foo";
original code
original:
#![allow(incomplete_features)]
#![feature(adt_const_params, const_ptr_read, generic_const_exprs)]
use std::mem::ManuallyDrop;
const fn concat_strs<const A: &'static str, const B: &'static str>() -> &'static str
where
[(); A.len()]:,
[(); B.len()]:,
[(); A.len() + B.len()]:,
{
#[repr(C)]
struct ConcatJoin<const N: usize, const M: usize> {
left: [u8; N],
right: [u8; M],
}
#[repr(C)]
union ConcatJoiner<const N: usize, const M: usize>
where
[(); N + M]:,
{
whole: ManuallyDrop<[u8; N + M]>,
split: ManuallyDrop<ConcatJoin<N, M>>,
}
const fn concat_arr<const B: &'static str, const N: usize>(a: [u8; M], b: [u8; N]) -> [u8; M + N]
where
[(); M + N]:,
{
unsafe {
let joiner = ConcatJoiner {
split: ManuallyDrop::new(ConcatJoin { left: a, right: b }),
};
let join = joiner.whole;
ManuallyDrop::into_inner(join)
}
}
struct Inner<const A: &'static str, const N: usize>;
impl<const A: &'static str, const B: &'static str> Inner<A, B>
where
[(); A.len()]:,
[(); B.len()]:,
[(); A.len() + B.len()]:,
{
const ABSTR: &'static str = unsafe {
std::str::from_utf8_unchecked(&concat_arr(
A.as_ptr().cast::<[usize; A.len()]>().read(),
B.as_ptr().cast::<[u8; B.len()]>().read(),
))
};
}
Inner::concat_strs::<FOO, BAR>::ABSTR
}
const FOO: &str = "foo";
const BAR: &str = "bar";
const FOOBAR: &str = concat_strs::<FOO, BAR>();
pub fn main() {}
Version information
rustc 1.79.0-nightly (7bdae134c 2024-04-12)
binary: rustc
commit-hash: 7bdae134cba57426d3c56b5de737a351762445e1
commit-date: 2024-04-12
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3
Command:
/home/matthias/.rustup/toolchains/master/bin/rustc
Program output
error[E0412]: cannot find type `BAR` in this scope
--> /tmp/icemaker_global_tempdir.Mekwd6wBTOXJ/rustc_testrunner_tmpdir_reporting.XdJ9wcBFLW2P/mvce.rs:7:31
|
7 | Inner::concat_strs::<FOO, BAR>::ABSTR
| ^^^ not found in this scope
|
help: you might be missing a type parameter
|
1 | const fn concat_strs<const A: &'static str, BAR>() -> &'static str {
| +++++
error[E0601]: `main` function not found in crate `mvce`
--> /tmp/icemaker_global_tempdir.Mekwd6wBTOXJ/rustc_testrunner_tmpdir_reporting.XdJ9wcBFLW2P/mvce.rs:10:25
|
10 | const FOO: &str = "foo";
| ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.Mekwd6wBTOXJ/rustc_testrunner_tmpdir_reporting.XdJ9wcBFLW2P/mvce.rs`
error: `&'static str` is forbidden as the type of a const generic parameter
--> /tmp/icemaker_global_tempdir.Mekwd6wBTOXJ/rustc_testrunner_tmpdir_reporting.XdJ9wcBFLW2P/mvce.rs:1:31
|
1 | const fn concat_strs<const A: &'static str>() -> &'static str {
| ^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
1 + #![feature(adt_const_params)]
|
error: `&'static str` is forbidden as the type of a const generic parameter
--> /tmp/icemaker_global_tempdir.Mekwd6wBTOXJ/rustc_testrunner_tmpdir_reporting.XdJ9wcBFLW2P/mvce.rs:5:27
|
5 | struct Inner<const A: &'static str>;
| ^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
1 + #![feature(adt_const_params)]
|
error[E0223]: ambiguous associated type
--> /tmp/icemaker_global_tempdir.Mekwd6wBTOXJ/rustc_testrunner_tmpdir_reporting.XdJ9wcBFLW2P/mvce.rs:7:5
|
7 | Inner::concat_strs::<FOO, BAR>::ABSTR
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: if there were a trait named `Example` with associated type `concat_strs` implemented for `Inner<_>`, you could use the fully-qualified path
|
7 | <Inner<_> as Example>::concat_strs::ABSTR
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: internal compiler error: compiler/rustc_hir_analysis/src/collect.rs:392:18: unexpected region: 'static
thread 'rustc' panicked at compiler/rustc_hir_analysis/src/collect.rs:392:18:
Box<dyn Any>
stack backtrace:
0: 0x761894811c45 - std::backtrace_rs::backtrace::libunwind::trace::h005ddb14be77e4f8
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
1: 0x761894811c45 - std::backtrace_rs::backtrace::trace_unsynchronized::hf4df49573026e0fa
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x761894811c45 - std::sys_common::backtrace::_print_fmt::hde41dc7cbf552b00
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/std/src/sys_common/backtrace.rs:68:5
3: 0x761894811c45 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h187e644bb90506b4
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/std/src/sys_common/backtrace.rs:44:22
4: 0x7618948610fb - core::fmt::rt::Argument::fmt::h07b913606448168b
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/core/src/fmt/rt.rs:142:9
5: 0x7618948610fb - core::fmt::write::h1fab5822f4720df4
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/core/src/fmt/mod.rs:1153:17
6: 0x7618948067cf - std::io::Write::write_fmt::h5f4793c6abb256e7
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/std/src/io/mod.rs:1832:15
7: 0x761894811a1e - std::sys_common::backtrace::_print::h61948819825f5f86
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/std/src/sys_common/backtrace.rs:47:5
8: 0x761894811a1e - std::sys_common::backtrace::print::h87a388c2a772fccc
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/std/src/sys_common/backtrace.rs:34:9
9: 0x761894814519 - std::panicking::default_hook::{{closure}}::h8033f939805b5bbd
10: 0x76189481425d - std::panicking::default_hook::h6b969458241c99e1
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/std/src/panicking.rs:291:9
11: 0x761891070bfb - std[8f2514a7521e08da]::panicking::update_hook::<alloc[bc31c2e53f1584b]::boxed::Box<rustc_driver_impl[bb71fe06a8a7412f]::install_ice_hook::{closure#0}>>::{closure#0}
12: 0x761894814c1c - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h8a4c355bfba7f202
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/alloc/src/boxed.rs:2032:9
13: 0x761894814c1c - std::panicking::rust_panic_with_hook::h32ca1249054fbee2
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/std/src/panicking.rs:792:13
14: 0x7618910a03b4 - std[8f2514a7521e08da]::panicking::begin_panic::<rustc_errors[6317d7b3566379c9]::ExplicitBug>::{closure#0}
15: 0x76189109d126 - std[8f2514a7521e08da]::sys_common::backtrace::__rust_end_short_backtrace::<std[8f2514a7521e08da]::panicking::begin_panic<rustc_errors[6317d7b3566379c9]::ExplicitBug>::{closure#0}, !>
16: 0x76189109ce06 - std[8f2514a7521e08da]::panicking::begin_panic::<rustc_errors[6317d7b3566379c9]::ExplicitBug>
17: 0x7618910a93e1 - <rustc_errors[6317d7b3566379c9]::diagnostic::BugAbort as rustc_errors[6317d7b3566379c9]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
18: 0x76189154e28c - rustc_middle[beddfb1a40acb3b0]::util::bug::opt_span_bug_fmt::<rustc_span[e4d92a8a79c25c0d]::span_encoding::Span>::{closure#0}
19: 0x76189153570a - rustc_middle[beddfb1a40acb3b0]::ty::context::tls::with_opt::<rustc_middle[beddfb1a40acb3b0]::util::bug::opt_span_bug_fmt<rustc_span[e4d92a8a79c25c0d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
20: 0x7618915355ab - rustc_middle[beddfb1a40acb3b0]::ty::context::tls::with_context_opt::<rustc_middle[beddfb1a40acb3b0]::ty::context::tls::with_opt<rustc_middle[beddfb1a40acb3b0]::util::bug::opt_span_bug_fmt<rustc_span[e4d92a8a79c25c0d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
21: 0x76188f158970 - rustc_middle[beddfb1a40acb3b0]::util::bug::bug_fmt
22: 0x76189115b6cd - <<rustc_hir_analysis[bf32ea695ac88b3a]::collect::ItemCtxt as rustc_hir_analysis[bf32ea695ac88b3a]::hir_ty_lowering::HirTyLowerer>::ct_infer::{closure#0} as core[889f3aa880875fe1]::ops::function::FnOnce<(rustc_middle[beddfb1a40acb3b0]::ty::region::Region, rustc_type_ir[71569043e5d8ff1f]::DebruijnIndex)>>::call_once::{shim:vtable#0}
23: 0x7618933f80bf - <rustc_middle[beddfb1a40acb3b0]::ty::Ty as rustc_type_ir[71569043e5d8ff1f]::fold::TypeSuperFoldable<rustc_middle[beddfb1a40acb3b0]::ty::context::TyCtxt>>::try_super_fold_with::<rustc_middle[beddfb1a40acb3b0]::ty::fold::RegionFolder>
24: 0x7618911b1172 - <rustc_hir_analysis[bf32ea695ac88b3a]::collect::ItemCtxt as rustc_hir_analysis[bf32ea695ac88b3a]::hir_ty_lowering::HirTyLowerer>::ct_infer
25: 0x761892bb5ba7 - <<dyn rustc_hir_analysis[bf32ea695ac88b3a]::hir_ty_lowering::HirTyLowerer>::lower_generic_args_of_path::{closure#0}::GenericArgsCtxt as rustc_hir_analysis[bf32ea695ac88b3a]::hir_ty_lowering::GenericArgsLowerer>::inferred_kind
26: 0x76188ff9fd89 - <dyn rustc_hir_analysis[bf32ea695ac88b3a]::hir_ty_lowering::HirTyLowerer>::lower_path
27: 0x761892608b90 - <dyn rustc_hir_analysis[bf32ea695ac88b3a]::hir_ty_lowering::HirTyLowerer>::lower_ty_common
28: 0x761892608cb8 - <dyn rustc_hir_analysis[bf32ea695ac88b3a]::hir_ty_lowering::HirTyLowerer>::lower_ty_common
29: 0x76189001f534 - rustc_hir_analysis[bf32ea695ac88b3a]::collect::type_of::type_of
30: 0x7618925c7022 - rustc_query_impl[b0cb5ce86efe2b6f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b0cb5ce86efe2b6f]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 8usize]>>
31: 0x7618925c5c5e - rustc_query_system[b2b547e2545c09cc]::query::plumbing::try_execute_query::<rustc_query_impl[b0cb5ce86efe2b6f]::DynamicConfig<rustc_query_system[b2b547e2545c09cc]::query::caches::DefIdCache<rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[b0cb5ce86efe2b6f]::plumbing::QueryCtxt, false>
32: 0x7618925c575b - rustc_query_impl[b0cb5ce86efe2b6f]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
33: 0x761892bb67df - rustc_middle[beddfb1a40acb3b0]::query::plumbing::query_get_at::<rustc_query_system[b2b547e2545c09cc]::query::caches::DefIdCache<rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 8usize]>>>
34: 0x7618925f1658 - rustc_hir_typeck[f9b529d928705c65]::typeck
35: 0x7618925ef909 - rustc_query_impl[b0cb5ce86efe2b6f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b0cb5ce86efe2b6f]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 8usize]>>
36: 0x7618925dbf31 - rustc_query_system[b2b547e2545c09cc]::query::plumbing::try_execute_query::<rustc_query_impl[b0cb5ce86efe2b6f]::DynamicConfig<rustc_query_system[b2b547e2545c09cc]::query::caches::VecCache<rustc_span[e4d92a8a79c25c0d]::def_id::LocalDefId, rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[b0cb5ce86efe2b6f]::plumbing::QueryCtxt, false>
37: 0x7618925da84c - rustc_query_impl[b0cb5ce86efe2b6f]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
38: 0x7618925dd352 - rustc_hir_typeck[f9b529d928705c65]::used_trait_imports
39: 0x7618925dd275 - rustc_query_impl[b0cb5ce86efe2b6f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b0cb5ce86efe2b6f]::query_impl::used_trait_imports::dynamic_query::{closure#2}::{closure#0}, rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 8usize]>>
40: 0x7618925dbf31 - rustc_query_system[b2b547e2545c09cc]::query::plumbing::try_execute_query::<rustc_query_impl[b0cb5ce86efe2b6f]::DynamicConfig<rustc_query_system[b2b547e2545c09cc]::query::caches::VecCache<rustc_span[e4d92a8a79c25c0d]::def_id::LocalDefId, rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[b0cb5ce86efe2b6f]::plumbing::QueryCtxt, false>
41: 0x7618925db8cc - rustc_query_impl[b0cb5ce86efe2b6f]::query_impl::used_trait_imports::get_query_non_incr::__rust_end_short_backtrace
42: 0x7618925db0d6 - rustc_hir_analysis[bf32ea695ac88b3a]::check_unused::check_unused_traits
43: 0x7618925daf73 - rustc_query_impl[b0cb5ce86efe2b6f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b0cb5ce86efe2b6f]::query_impl::check_unused_traits::dynamic_query::{closure#2}::{closure#0}, rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 0usize]>>
44: 0x76189326d035 - rustc_query_system[b2b547e2545c09cc]::query::plumbing::try_execute_query::<rustc_query_impl[b0cb5ce86efe2b6f]::DynamicConfig<rustc_query_system[b2b547e2545c09cc]::query::caches::SingleCache<rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[b0cb5ce86efe2b6f]::plumbing::QueryCtxt, false>
45: 0x76189326cdbd - rustc_query_impl[b0cb5ce86efe2b6f]::query_impl::check_unused_traits::get_query_non_incr::__rust_end_short_backtrace
46: 0x7618925d90c9 - rustc_hir_analysis[bf32ea695ac88b3a]::check_crate
47: 0x761892c1447a - rustc_interface[4964ecb499cdbc1f]::passes::analysis
48: 0x761892c13fd5 - rustc_query_impl[b0cb5ce86efe2b6f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b0cb5ce86efe2b6f]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 1usize]>>
49: 0x76189326c2e5 - rustc_query_system[b2b547e2545c09cc]::query::plumbing::try_execute_query::<rustc_query_impl[b0cb5ce86efe2b6f]::DynamicConfig<rustc_query_system[b2b547e2545c09cc]::query::caches::SingleCache<rustc_middle[beddfb1a40acb3b0]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[b0cb5ce86efe2b6f]::plumbing::QueryCtxt, false>
50: 0x76189326c049 - rustc_query_impl[b0cb5ce86efe2b6f]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
51: 0x7618930dbb13 - rustc_interface[4964ecb499cdbc1f]::interface::run_compiler::<core[889f3aa880875fe1]::result::Result<(), rustc_span[e4d92a8a79c25c0d]::ErrorGuaranteed>, rustc_driver_impl[bb71fe06a8a7412f]::run_compiler::{closure#0}>::{closure#0}
52: 0x7618931bfc9d - std[8f2514a7521e08da]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[4964ecb499cdbc1f]::util::run_in_thread_with_globals<rustc_interface[4964ecb499cdbc1f]::util::run_in_thread_pool_with_globals<rustc_interface[4964ecb499cdbc1f]::interface::run_compiler<core[889f3aa880875fe1]::result::Result<(), rustc_span[e4d92a8a79c25c0d]::ErrorGuaranteed>, rustc_driver_impl[bb71fe06a8a7412f]::run_compiler::{closure#0}>::{closure#0}, core[889f3aa880875fe1]::result::Result<(), rustc_span[e4d92a8a79c25c0d]::ErrorGuaranteed>>::{closure#0}, core[889f3aa880875fe1]::result::Result<(), rustc_span[e4d92a8a79c25c0d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[889f3aa880875fe1]::result::Result<(), rustc_span[e4d92a8a79c25c0d]::ErrorGuaranteed>>
53: 0x7618931bfaaa - <<std[8f2514a7521e08da]::thread::Builder>::spawn_unchecked_<rustc_interface[4964ecb499cdbc1f]::util::run_in_thread_with_globals<rustc_interface[4964ecb499cdbc1f]::util::run_in_thread_pool_with_globals<rustc_interface[4964ecb499cdbc1f]::interface::run_compiler<core[889f3aa880875fe1]::result::Result<(), rustc_span[e4d92a8a79c25c0d]::ErrorGuaranteed>, rustc_driver_impl[bb71fe06a8a7412f]::run_compiler::{closure#0}>::{closure#0}, core[889f3aa880875fe1]::result::Result<(), rustc_span[e4d92a8a79c25c0d]::ErrorGuaranteed>>::{closure#0}, core[889f3aa880875fe1]::result::Result<(), rustc_span[e4d92a8a79c25c0d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[889f3aa880875fe1]::result::Result<(), rustc_span[e4d92a8a79c25c0d]::ErrorGuaranteed>>::{closure#1} as core[889f3aa880875fe1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
54: 0x76189481eb1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h531fe37614bc09da
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/alloc/src/boxed.rs:2018:9
55: 0x76189481eb1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5d755886c02b3116
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/alloc/src/boxed.rs:2018:9
56: 0x76189481eb1b - std::sys::pal::unix::thread::Thread::new::thread_start::h5d270df0b053eb7f
at /rustc/7bdae134cba57426d3c56b5de737a351762445e1/library/std/src/sys/pal/unix/thread.rs:108:17
57: 0x7618945bc55a - <unknown>
58: 0x761894639a3c - <unknown>
59: 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.79.0-nightly (7bdae134c 2024-04-12) running on x86_64-unknown-linux-gnu
query stack during panic:
#0 [type_of] computing type of `concat_strs::{constant#0}`
#1 [typeck] type-checking `concat_strs::{constant#0}`
#2 [used_trait_imports] finding used_trait_imports `concat_strs::{constant#0}`
#3 [check_unused_traits] checking unused trait imports in crate
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0223, E0412, E0601.
For more information about an error, try `rustc --explain E0223`.
Metadata
Metadata
Assignees
Labels
Area: The high-level intermediate representation (HIR)Category: This is a bug.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: This bug is tracked inside the repo by a `known-bug` test.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.