Skip to content

Heap allocation in Box optimized out with rustc 1.60 but not with 1.61+ #98679

Closed
@Nekrolm

Description

@Nekrolm

I tried this code:

pub struct BBox {
    top: i32,
    left: i32,
    height: i32,
    width: i32
}

fn fiddle(bbox: BBox) -> Box<BBox> {
    Box::new(BBox {
        top: bbox.top * 2,
        ..bbox
    })
}

pub fn main() {
    let bbox = Box::new(BBox {
            top: 551,
            left: 100,
            height: 200,
            width: 180,
    });
    let bbox = fiddle(*bbox);
    let bbox_top = bbox.top;
    println!("{}", bbox_top)
}

With rustc 1.60 all Box allocations are totally optimized out.
But starting from 1.61 it doesn't happen.

godbolt link

Possible it is the same issue as #97751

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-bugCategory: This is a bug.I-heavyIssue: Problems and improvements with respect to binary size of generated code.I-slowIssue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions