Skip to content

io::Error::new(_, string literal) allocates Box<Box<String>> and copies the string #83352

Description

@m-ou-se

It's very common to use io::Error::new(kind, "some message"), including in many places in std. However, that will create a io::Error containing a Repr::Custom containing a Box<Custom> containing a Box<dyn Error + ..> containing a StringError containing a String containing a copy of the message. 🙃

Three allocations to just return an error message which is in some cases not even more helpful than just the ErrorKind, is not great. We should find a way to improve this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`T-libsRelevant to the library 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