Skip to content

String::from and str::to_owned are not inlined #53681

Closed
@nagisa

Description

@nagisa
#![crate_type="rlib"]

pub fn banana() -> String {
    String::from("")
}

pub fn peach() -> String {
    "".to_owned()
}

pub fn expected() -> String {
    unsafe {
    String::from_utf8_unchecked("".as_bytes().to_owned())
    }
}

Playground (Use show assembly or llvm-ir, make sure to turn on optimisations)

All these functions should be equivalent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-slowIssue: Problems and improvements with respect to performance of generated code.T-libs-apiRelevant to the library API 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