]> git.lizzy.rs Git - rust.git/commit - src/tools/rust-analyzer
Rollup merge of #83353 - m-ou-se:io-error-avoid-alloc, r=nagisa
authorDylan DPC <dylan.dpc@gmail.com>
Wed, 24 Mar 2021 00:52:29 +0000 (01:52 +0100)
committerGitHub <noreply@github.com>
Wed, 24 Mar 2021 00:52:29 +0000 (01:52 +0100)
commita42e62fa0a59d0ba620889f97513929a113a6fbd
treec8dabc69676343818b44914550e763ddd18d214d
parent2f611da1d66ae98b53358bcb7739884524b7e18d
parent6bbcc5bfbbfd9ba5a6d584a753fa32d80e3a7a17
Rollup merge of #83353 - m-ou-se:io-error-avoid-alloc, r=nagisa

Add internal io::Error::new_const to avoid allocations.

This makes it possible to have a io::Error containing a message with zero allocations, and uses that everywhere to avoid the *three* allocations involved in `io::Error::new(kind, "message")`.

The function signature isn't perfect, because it needs a reference to the `&str`. So for now, this is just a `pub(crate)` function. Later, we'll be able to use `fn new_const<MSG: &'static str>(kind: ErrorKind)` to make that a bit better. (Then we'll also be able to use some ZST trickery if that would result in more efficient code.)

See https://github.com/rust-lang/rust/issues/83352
library/std/src/io/mod.rs
library/std/src/sys/hermit/mod.rs
library/std/src/sys/unix/ext/fs.rs
library/std/src/sys/unix/os.rs
library/std/src/sys/unix/process/process_unix.rs