Using a const parameter in an inline const pattern causes an ICE, but only when you don't directly use the parameter. This seems to be the same problem as #82518, although under different circumstances.
Code
#![feature(inline_const)]
#![feature(generic_const_exprs)]
const fn foo(val: usize) -> usize { val }
fn bar<const N: usize>(num: usize) -> &'static str
where [(); foo(N)]:
{
match num {
const { foo(N) } => "fizz",
_ => "buzz"
}
}
Using const { N } instead of const { foo(N) } gives
error[E0158]: const parameters cannot be referenced in patterns
Disappointing, but undoubtedly the intended behavior.
The above example wouldn't be easy to come across naturally, but if the const parameter was (for example) an array and you tried to index it, the compiler would tell you to use a const fn to do that. This code causes the same ICE:
Using a const parameter in an inline const pattern causes an ICE, but only when you don't directly use the parameter. This seems to be the same problem as #82518, although under different circumstances.
Code
Using
const { N }
instead ofconst { foo(N) }
givesDisappointing, but undoubtedly the intended behavior.
The above example wouldn't be easy to come across naturally, but if the const parameter was (for example) an array and you tried to index it, the compiler would tell you to use a
const fn
to do that. This code causes the same ICE:I should note that this issue is only present with the
inline_const
feature and thegeneric_const_exprs
feature.Meta
rustc --version --verbose
:Error output
Backtrace
``` thread 'rustc' panicked at 'Box', compiler/rustc_errors/src/lib.rs:1147:9
stack backtrace:
0: std::panicking::begin_panic
1: std::panic::panic_any
2: rustc_errors::HandlerInner::bug
3: rustc_errors::Handler::bug
4: rustc_middle::ty::context::tls::with_opt
5: rustc_middle::util::bug::opt_span_bug_fmt
6: rustc_middle::util::bug::bug_fmt
7: indexmap::map::core::Entry::or_insert_with
8: rustc_mir_build::build::matches::::test_candidates_with_or
9: rustc_data_structures::stack::ensure_sufficient_stack
10: rustc_mir_build::build::matches::::lower_match_tree
11: rustc_mir_build::build::matches::::match_expr
12: rustc_mir_build::build::expr::into::::expr_into_dest
13: rustc_mir_build::build::expr::into::::expr_into_dest
14: rustc_mir_build::build::block::::ast_block_stmts
15: rustc_mir_build::build::scope::::in_scope
16: rustc_mir_build::build::expr::into::::expr_into_dest
17: rustc_mir_build::build::expr::into::::expr_into_dest
18: rustc_mir_build::build::expr::into::::expr_into_dest
19: rustc_mir_build::build::construct_fn
20: rustc_infer::infer::InferCtxtBuilder::enter
21: rustc_mir_build::build::mir_built
22: rustc_query_system::dep_graph::graph::DepGraph::with_task
23: rustc_data_structures::stack::ensure_sufficient_stack
24: rustc_query_system::query::plumbing::try_execute_query
25: ::mir_built
26: rustc_mir_transform::check_unsafety::unsafety_check_result
27: core::ops::function::FnOnce::call_once
28: rustc_query_system::dep_graph::graph::DepGraph::with_task
29: rustc_data_structures::stack::ensure_sufficient_stack
30: rustc_query_system::query::plumbing::try_execute_query
31: ::unsafety_check_result
32: rustc_mir_transform::mir_const
33: rustc_query_system::dep_graph::graph::DepGraph::with_task
34: rustc_data_structures::stack::ensure_sufficient_stack
35: rustc_query_system::query::plumbing::try_execute_query
36: ::mir_const
37: rustc_mir_transform::mir_promoted
38: rustc_query_system::dep_graph::graph::DepGraph::with_task
39: rustc_data_structures::stack::ensure_sufficient_stack
40: rustc_query_system::query::plumbing::try_execute_query
41: ::mir_promoted
42: core::ops::function::FnOnce::call_once
43: rustc_query_system::dep_graph::graph::DepGraph::with_task
44: rustc_data_structures::stack::ensure_sufficient_stack
45: rustc_query_system::query::plumbing::try_execute_query
46: ::mir_borrowck
47: rustc_middle::hir::map::Map::par_body_owners
48: rustc_session::utils::::time
49: rustc_interface::passes::analysis
50: rustc_query_system::dep_graph::graph::DepGraph::with_task
51: rustc_data_structures::stack::ensure_sufficient_stack
52: rustc_query_system::query::plumbing::try_execute_query
53: rustc_query_system::query::plumbing::get_query
54: rustc_interface::passes::QueryContext::enter
55: rustc_interface::queries::::enter
56: rustc_span::with_source_map
57: scoped_tls::ScopedKey::set
```