mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-12 16:45:37 +00:00
Rollup merge of #68102 - lzutao:inline, r=alexcrichton
Inline some conversion methods around OsStr Diff on the assembly of this snippet before and after this PR: https://www.diffchecker.com/NeGMjaJ2 ```rust use std::env; use std::io; use std::path::{Path, PathBuf}; pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result<PathBuf> { match env::var_os("CARGO_HOME").filter(|h| !h.is_empty()) { Some(home) => { let home = PathBuf::from(home); if home.is_absolute() { Ok(home) } else { Ok(cwd.join(&home)) } } _ => env::home_dir() .map(|p| p.join(".cargo")) .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find cargo home dir")), } } ```
This commit is contained in:
commit
c960c3e057
@ -250,6 +250,7 @@ impl From<String> for Box<dyn Error + Send + Sync> {
|
||||
/// assert!(
|
||||
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
|
||||
/// ```
|
||||
#[inline]
|
||||
fn from(err: String) -> Box<dyn Error + Send + Sync> {
|
||||
struct StringError(String);
|
||||
|
||||
@ -317,6 +318,7 @@ impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> {
|
||||
/// assert!(
|
||||
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
|
||||
/// ```
|
||||
#[inline]
|
||||
fn from(err: &str) -> Box<dyn Error + Send + Sync + 'a> {
|
||||
From::from(String::from(err))
|
||||
}
|
||||
|
@ -615,6 +615,7 @@ impl OsStr {
|
||||
/// assert!(!os_str.is_empty());
|
||||
/// ```
|
||||
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.inner.inner.is_empty()
|
||||
}
|
||||
@ -965,6 +966,7 @@ impl AsRef<OsStr> for OsStr {
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl AsRef<OsStr> for OsString {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &OsStr {
|
||||
self
|
||||
}
|
||||
|
@ -1475,6 +1475,7 @@ impl From<OsString> for PathBuf {
|
||||
/// Converts a `OsString` into a `PathBuf`
|
||||
///
|
||||
/// This conversion does not allocate or copy memory.
|
||||
#[inline]
|
||||
fn from(s: OsString) -> PathBuf {
|
||||
PathBuf { inner: s }
|
||||
}
|
||||
@ -1535,7 +1536,7 @@ impl fmt::Debug for PathBuf {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl ops::Deref for PathBuf {
|
||||
type Target = Path;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Path {
|
||||
Path::new(&self.inner)
|
||||
}
|
||||
@ -2655,6 +2656,7 @@ impl AsRef<Path> for OsString {
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl AsRef<Path> for str {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &Path {
|
||||
Path::new(self)
|
||||
}
|
||||
@ -2669,6 +2671,7 @@ impl AsRef<Path> for String {
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl AsRef<Path> for PathBuf {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &Path {
|
||||
self
|
||||
}
|
||||
|
@ -104,6 +104,7 @@ impl Buf {
|
||||
self.inner.shrink_to(min_capacity)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_slice(&self) -> &Slice {
|
||||
unsafe { mem::transmute(&*self.inner) }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user