Description
In an attempt to implement array default with const generics, I tried this code:
The code seems overall ok, but the compilation failed. After some try, it seems i can workaround this by add another usage of the "complex expression", and this second code snippet compiles:
However when the usage code is generic, it still doesn't work:
With this third piece of code, I did some debugging, and it seems in the is_const_evaluatable<'cx, 'tcx>
function, there's a call like this:
[compiler\rustc_trait_selection\src\traits\const_evaluatable.rs:44] &def = WithOptConstParam {
did: DefId(0:46 ~ array_default_extern_generic_doesnt_work[317d]::{impl#0}::{constant#0}),
const_param_did: None,
}
[compiler\rustc_trait_selection\src\traits\const_evaluatable.rs:45] &substs = [
R,
Const {
ty: usize,
val: Unevaluated(
Unevaluated {
def: WithOptConstParam {
did: DefId(0:79 ~ array_default_extern_generic_doesnt_work[317d]::impl_test::UnwindContext::stack_storage::{constant#0}),
const_param_did: None,
},
substs: [
R,
],
promoted: None,
},
),
},
]
[compiler\rustc_trait_selection\src\traits\const_evaluatable.rs:46] param_env.caller_bounds() = [
Binder(TraitPredicate(<R as std::default::Default>), []),
Binder(TraitPredicate(<R as std::marker::Sized>), []),
]
And there's no corresponding ConstEvaluatable
bound in it. So it seems the evaluatable analysis is using a wrong or unpopulated "environment bounds"?
This and the const_evaluatable_checked
feature itself is the single blocker for array defaults implementation using const generics. So it would be nice if this can get fixed.
cc @rust-lang/wg-const-eval