Skip to content

no optimization of Some(v).unwrap() to v for certain types of v #111268

Closed as not planned
@antonilol

Description

@antonilol

I tried this code:

pub fn example(vec: Vec<u32>) -> Vec<u32> {
    Some(vec).unwrap() 
}

I expected to see this happen: a simple move

Instead, this happened: extra logic was added to check for None

see https://godbolt.org/z/sozWosj88

this does not happen with u32 and &Vec<u32>: https://godbolt.org/z/crhePq97z

Meta

godbolt's rustc version:

rustc 1.71.0-nightly (dbba59457 2023-05-01)

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions