make `OsString::new` and `PathBuf::new` unstably const
diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs
index ead4877..2230822 100644
--- a/library/std/src/ffi/os_str.rs
+++ b/library/std/src/ffi/os_str.rs
@@ -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()) }
}
diff --git a/library/std/src/path.rs b/library/std/src/path.rs
index 7959c63..3e34779 100644
--- a/library/std/src/path.rs
+++ b/library/std/src/path.rs
@@ -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() }
}
diff --git a/library/std/src/sys/os_str/bytes.rs b/library/std/src/sys/os_str/bytes.rs
index 4a8808c..f8ab454 100644
--- a/library/std/src/sys/os_str/bytes.rs
+++ b/library/std/src/sys/os_str/bytes.rs
@@ -115,7 +115,7 @@ pub fn into_string(self) -> Result<String, Buf> {
}
#[inline]
- pub fn from_string(s: String) -> Buf {
+ pub const fn from_string(s: String) -> Buf {
Buf { inner: s.into_bytes() }
}
diff --git a/library/std/src/sys/os_str/wtf8.rs b/library/std/src/sys/os_str/wtf8.rs
index 5174ea6..4207a2d 100644
--- a/library/std/src/sys/os_str/wtf8.rs
+++ b/library/std/src/sys/os_str/wtf8.rs
@@ -92,7 +92,7 @@ pub fn into_string(self) -> Result<String, Buf> {
}
#[inline]
- pub fn from_string(s: String) -> Buf {
+ pub const fn from_string(s: String) -> Buf {
Buf { inner: Wtf8Buf::from_string(s) }
}
diff --git a/library/std/src/sys_common/wtf8.rs b/library/std/src/sys_common/wtf8.rs
index f9ec112..50bde88 100644
--- a/library/std/src/sys_common/wtf8.rs
+++ b/library/std/src/sys_common/wtf8.rs
@@ -209,7 +209,7 @@ pub unsafe fn from_bytes_unchecked(value: Vec<u8>) -> 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 }
}