-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
generic_const_exprs
does not work properly with const/type param defaults
#106994
Comments
Thank you for identifying this. And for any progress (hopefully). Minimizing this even more - even without any declared trait: #![allow(incomplete_features)]
#![feature(generic_const_exprs)]
struct V<const U: usize = {1+2}>
where
[(); U]:; Update for ordinary Rust developers: struct V<const U: usize = {1+2}>
where
[(); U]:; So, if you need expressions in |
Hoping to help narrow this closer: This fails even if the #![allow(incomplete_features)]
#![feature(generic_const_exprs)]
struct FailingToCompile<const U: usize = 0usize as usize>
where
[(); U]:; Interestingly, if the #![allow(incomplete_features)]
#![feature(generic_const_exprs)]
macro_rules! bound_size {
() => {1usize}
}
struct BracesAreNOTcheckedBeforeICE<const U: usize = bound_size!() as usize>
where [(); U]:; But, if there's no casting/transformation in the #![allow(incomplete_features)]
#![feature(generic_const_exprs)]
macro_rules! bound_size {
() => {1usize}
}
struct BracesAREcheckedIfNoICE<const U: usize = bound_size!()>
where [(); U]:; If the same value is NOT cast in the generic params' list from a default value (or if it has no default value), but it's cast when instantiating the generic type, it DOES compile: #![allow(incomplete_features)]
#![feature(generic_const_exprs)]
struct Compiles<const U: usize = 0>
where [(); U]:;
type T = Compiles<{1i32 as usize}>;
fn main() {
let _t: T = T {};
} However, if the #![allow(incomplete_features)]
#![feature(generic_const_exprs)]
struct Compiles<const I: i32 = 0>
where [(); I as usize]:;
{} The result type of the #![allow(incomplete_features)]
#![feature(generic_const_exprs)]
struct IncorrectTypeOfDefaultValueIsNOTcheckedBeforeICE<const U: usize = {1u8 + 0i32 as usize}>
where
[(); U]:; But, when there is no struct TypeOfDefaultValueIScheckedIfNObounds<const U: usize = {1u8 + 0i32 as usize}>; |
What other combinations are worth checking (for someone not knowing deep |
I do not believe there is anything worth checking, this issue is relatively well understood already. The problem is how to solve it, not figuring out what the cause is |
Still, while I'm narrowing this down from the "consumer's" point of view, and searching for workarounds, here are 2 examples.
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
trait Tr {
const C: usize = 0;
}
struct Str {}
impl Tr for Str {}
// ICE, but ONLY if this generic type is used (in a function signature, an expression...).
struct ICE<T: Tr = Str, const C: usize = {T::C}>
where [(); C]:,
{
_t: core::marker::PhantomData<T>,
_arr: [(); C],
}
// Using the above type in a function signature, or in an expression causes an ICE.
fn _type_in_fn_sig_return_causes_ice() -> ICE {
loop{}
}
// and/or:
fn _type_in_fn_sig_param_causes_ice(_: &ICE) {
loop{}
}
// and/or:
fn _instantiate() {
ICE::<Str> {
_t: core::marker::PhantomData {},
_arr: []
};
}
#![allow(incomplete_features)]
// `struct ICE` below compiles well WITHOUT generic_const_exprs. But it does have an ICE with
// generic_const_exprs!
//
// The ICE is triggered even if the const generic-based struct itself (`ICE` below) is not used at
// all (not in any function signature, expression...). (And regardless of whether the type is
// public.)
#![feature(generic_const_exprs)]
trait Tr {
const C: usize = 0;
}
struct Str {}
impl Tr for Str {}
struct ICE<const C: usize={Str::C}>
where [(); C]:,
{
_arr: [(); C],
} |
In order to make
feature(generic_const_exprs)
not completely broken when used withfeature(const_generics_defaults)
, #86580 was landed. From the description of the PR:because of this these two features are still pretty incompatible with eachother. This issue tracks this as there have been a large volume of issues that are all about which makes looking through
F-generic_const-exprs
issues harder than it needs to be.It was previously attempted to fix this in #106847 but that was closed:
duplicate issues
When this is fixed the following should be revisited and checked to make sure everything works as intended:
The text was updated successfully, but these errors were encountered: