Rollup merge of #141467 - cyrgani:const-empty-stringlikes, r=Amanieu
make `OsString::new` and `PathBuf::new` unstably const Since #129041, `String::into_bytes` is `const`, which allows making `OsString::new` and `PathBuf::new` unstably const now. Not sure what the exact process for this is; does it need an ACP?
This commit is contained in:
commit
88620b400e
5 changed files with 7 additions and 5 deletions
|
|
@ -137,7 +137,8 @@ impl OsString {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn new() -> OsString {
|
||||
#[rustc_const_unstable(feature = "const_pathbuf_osstring_new", issue = "141520")]
|
||||
pub const fn new() -> OsString {
|
||||
OsString { inner: Buf::from_string(String::new()) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1191,7 +1191,8 @@ impl PathBuf {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn new() -> PathBuf {
|
||||
#[rustc_const_unstable(feature = "const_pathbuf_osstring_new", issue = "141520")]
|
||||
pub const fn new() -> PathBuf {
|
||||
PathBuf { inner: OsString::new() }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ impl Buf {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_string(s: String) -> Buf {
|
||||
pub const fn from_string(s: String) -> Buf {
|
||||
Buf { inner: s.into_bytes() }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ impl Buf {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_string(s: String) -> Buf {
|
||||
pub const fn from_string(s: String) -> Buf {
|
||||
Buf { inner: Wtf8Buf::from_string(s) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ impl Wtf8Buf {
|
|||
///
|
||||
/// Since WTF-8 is a superset of UTF-8, this always succeeds.
|
||||
#[inline]
|
||||
pub fn from_string(string: String) -> Wtf8Buf {
|
||||
pub const fn from_string(string: String) -> Wtf8Buf {
|
||||
Wtf8Buf { bytes: string.into_bytes(), is_known_utf8: true }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue