Skip to content

RFC 2203 does not work for Vec::new #65737

Closed
@ecstatic-morse

Description

@ecstatic-morse

RFC 2203 specifically calls out Vec::new as a motivating example, however this does not work on the current nightly.

fn main() {
    let _: [Vec<i32>; 4] = [Vec::new(); 4];
}

There are two reasons for this. First, promotion in array repeat expressions currently uses the "implicit" rules for promotability, which forbids promotion of function calls without #[rustc_promotable]. Second, the result of Vec::new() is marked as NeedsDrop since Vec<T> is Drop, which disqualifies it from promotion, even in an explicit context.

cc #49147

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)B-unstableBlocker: Implemented in the nightly compiler and unstable.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions