rust/tests/ui/const-generics/generic_const_exprs/trivial-anon-const-use-cases.rs
Martin Nordholts 4882ea4b3c rustc_resolve: Improve resolve_const_param_in_non_trivial_anon_const wording
In some contexts, const expressions are OK. Add a `here` to the error
message to clarify this.
2025-06-07 13:01:16 +02:00

20 lines
599 B
Rust

//! Regression test for <https://github.com/rust-lang/rust/issues/79429>.
//@ revisions: full min
#![cfg_attr(full, feature(generic_const_exprs))]
#![cfg_attr(full, allow(incomplete_features))]
struct X<const S: usize>;
impl<const S: usize> X<S> {
const LEN: usize = S + 1; // `S + 1` is a valid const expression in this context.
}
struct Y<const S: usize> {
stuff: [u8; { S + 1 }], // `S + 1` is NOT a valid const expression in this context.
//[min]~^ ERROR generic parameters may not be used in const operations
//[full]~^^ ERROR unconstrained generic constant
}
fn main() {}