Skip to content

Tracking issue for unsizing casts in const fns #64992

Closed

Description

Right now we don't allow unsizing casts (array -> slice or type -> dyn Trait) in const fns on stable.

While we can't allow unsizing to dyn Trait until we've figured out trait bounds in const fns, we can easily allow unsizing casts for slices, there's no reason not to have them. The only reason we didn't have them in the initial min_const_fn feature gate was the fact that we preferred overly aggressive rules over accidental stabilization.

The relevant code is

Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), _, _) => Err((
span,
"unsizing casts are not allowed in const fn".into(),
)),

We need to check the destination and source types for slice and array respectively and permit the cast in that case. We also need to recurse with check_operand on the value that is being casted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-const-fnArea: const fn foo(..) {..}. Pure functions which can be applied at compile time.B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: A tracking issue for an RFC or an unstable feature.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions