Skip to content

Trivial vec![] creation then iteration doesn't optimize out the allocation #43272

Closed
@bluss

Description

@bluss

Rustc used to be able to replace vec![1, 2, 3].iter().sum::<i32>() with a constant when optimizing, not at the moment. It simply looks like a Layout method that is not inlinable.

(This is a regression strictly speaking — stable & beta can do this optimization, but not nightly.)

Code to reproduce:

playground link

pub fn sum_me() -> i32 {
    vec![1, 2, 3].iter().sum::<i32>()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions