Skip to content

type aliases dont propagate implied ConstEvaluatable bounds of rhs #86259

Open
@crlf0710

Description

@crlf0710

In an attempt to implement array default with const generics, I tried this code:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=700737e7598eca3dc58921f4530627f5

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:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d3b02c12306c7e0754020951c84f0cbe

However when the usage code is generic, it still doesn't work:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d3b02c12306c7e0754020951c84f0cbe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions