Skip to content

Commit fab206b

Browse files
committed
make OsString::new and PathBuf::new unstably const
1 parent e88e854 commit fab206b

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

library/std/src/ffi/os_str.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ impl OsString {
137137
#[stable(feature = "rust1", since = "1.0.0")]
138138
#[must_use]
139139
#[inline]
140-
pub fn new() -> OsString {
140+
#[rustc_const_unstable(feature = "const_pathbuf_osstring_new", issue = "141520")]
141+
pub const fn new() -> OsString {
141142
OsString { inner: Buf::from_string(String::new()) }
142143
}
143144

library/std/src/path.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,8 @@ impl PathBuf {
11911191
#[stable(feature = "rust1", since = "1.0.0")]
11921192
#[must_use]
11931193
#[inline]
1194-
pub fn new() -> PathBuf {
1194+
#[rustc_const_unstable(feature = "const_pathbuf_osstring_new", issue = "141520")]
1195+
pub const fn new() -> PathBuf {
11951196
PathBuf { inner: OsString::new() }
11961197
}
11971198

library/std/src/sys/os_str/bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Buf {
115115
}
116116

117117
#[inline]
118-
pub fn from_string(s: String) -> Buf {
118+
pub const fn from_string(s: String) -> Buf {
119119
Buf { inner: s.into_bytes() }
120120
}
121121

library/std/src/sys/os_str/wtf8.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl Buf {
9292
}
9393

9494
#[inline]
95-
pub fn from_string(s: String) -> Buf {
95+
pub const fn from_string(s: String) -> Buf {
9696
Buf { inner: Wtf8Buf::from_string(s) }
9797
}
9898

library/std/src/sys_common/wtf8.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl Wtf8Buf {
209209
///
210210
/// Since WTF-8 is a superset of UTF-8, this always succeeds.
211211
#[inline]
212-
pub fn from_string(string: String) -> Wtf8Buf {
212+
pub const fn from_string(string: String) -> Wtf8Buf {
213213
Wtf8Buf { bytes: string.into_bytes(), is_known_utf8: true }
214214
}
215215

0 commit comments

Comments
 (0)