Skip to content

Commit 4a00421

Browse files
committed
Make raw standard stream constructors const
1 parent 479c23b commit 4a00421

File tree

10 files changed

+33
-30
lines changed

10 files changed

+33
-30
lines changed

library/std/src/io/stdio.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ struct StderrRaw(stdio::Stderr);
5050
/// handles is **not** available to raw handles returned from this function.
5151
///
5252
/// The returned handle has no external synchronization or buffering.
53-
fn stdin_raw() -> StdinRaw {
53+
#[unstable(feature = "libstd_sys_internals", issue = "none")]
54+
const fn stdin_raw() -> StdinRaw {
5455
StdinRaw(stdio::Stdin::new())
5556
}
5657

@@ -63,7 +64,8 @@ fn stdin_raw() -> StdinRaw {
6364
///
6465
/// The returned handle has no external synchronization or buffering layered on
6566
/// top.
66-
fn stdout_raw() -> StdoutRaw {
67+
#[unstable(feature = "libstd_sys_internals", issue = "none")]
68+
const fn stdout_raw() -> StdoutRaw {
6769
StdoutRaw(stdio::Stdout::new())
6870
}
6971

@@ -74,7 +76,8 @@ fn stdout_raw() -> StdoutRaw {
7476
///
7577
/// The returned handle has no external synchronization or buffering layered on
7678
/// top.
77-
fn stderr_raw() -> StderrRaw {
79+
#[unstable(feature = "libstd_sys_internals", issue = "none")]
80+
const fn stderr_raw() -> StderrRaw {
7881
StderrRaw(stdio::Stderr::new())
7982
}
8083

library/std/src/sys/cloudabi/stdio.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub struct Stdout(());
66
pub struct Stderr(());
77

88
impl Stdin {
9-
pub fn new() -> Stdin {
9+
pub const fn new() -> Stdin {
1010
Stdin(())
1111
}
1212
}
@@ -18,7 +18,7 @@ impl io::Read for Stdin {
1818
}
1919

2020
impl Stdout {
21-
pub fn new() -> Stdout {
21+
pub const fn new() -> Stdout {
2222
Stdout(())
2323
}
2424
}
@@ -37,7 +37,7 @@ impl io::Write for Stdout {
3737
}
3838

3939
impl Stderr {
40-
pub fn new() -> Stderr {
40+
pub const fn new() -> Stderr {
4141
Stderr(())
4242
}
4343
}

library/std/src/sys/hermit/stdio.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct Stdout;
77
pub struct Stderr;
88

99
impl Stdin {
10-
pub fn new() -> Stdin {
10+
pub const fn new() -> Stdin {
1111
Stdin
1212
}
1313
}
@@ -28,7 +28,7 @@ impl io::Read for Stdin {
2828
}
2929

3030
impl Stdout {
31-
pub fn new() -> Stdout {
31+
pub const fn new() -> Stdout {
3232
Stdout
3333
}
3434
}
@@ -69,7 +69,7 @@ impl io::Write for Stdout {
6969
}
7070

7171
impl Stderr {
72-
pub fn new() -> Stderr {
72+
pub const fn new() -> Stderr {
7373
Stderr
7474
}
7575
}

library/std/src/sys/sgx/stdio.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn with_std_fd<F: FnOnce(&FileDesc) -> R, R>(fd: abi::Fd, f: F) -> R {
1919
}
2020

2121
impl Stdin {
22-
pub fn new() -> Stdin {
22+
pub const fn new() -> Stdin {
2323
Stdin(())
2424
}
2525
}
@@ -31,7 +31,7 @@ impl io::Read for Stdin {
3131
}
3232

3333
impl Stdout {
34-
pub fn new() -> Stdout {
34+
pub const fn new() -> Stdout {
3535
Stdout(())
3636
}
3737
}
@@ -47,7 +47,7 @@ impl io::Write for Stdout {
4747
}
4848

4949
impl Stderr {
50-
pub fn new() -> Stderr {
50+
pub const fn new() -> Stderr {
5151
Stderr(())
5252
}
5353
}

library/std/src/sys/unix/stdio.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct Stdout(());
77
pub struct Stderr(());
88

99
impl Stdin {
10-
pub fn new() -> Stdin {
10+
pub const fn new() -> Stdin {
1111
Stdin(())
1212
}
1313
}
@@ -28,7 +28,7 @@ impl io::Read for Stdin {
2828
}
2929

3030
impl Stdout {
31-
pub fn new() -> Stdout {
31+
pub const fn new() -> Stdout {
3232
Stdout(())
3333
}
3434
}
@@ -53,7 +53,7 @@ impl io::Write for Stdout {
5353
}
5454

5555
impl Stderr {
56-
pub fn new() -> Stderr {
56+
pub const fn new() -> Stderr {
5757
Stderr(())
5858
}
5959
}

library/std/src/sys/unsupported/stdio.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub struct Stdout;
55
pub struct Stderr;
66

77
impl Stdin {
8-
pub fn new() -> Stdin {
8+
pub const fn new() -> Stdin {
99
Stdin
1010
}
1111
}
@@ -17,7 +17,7 @@ impl io::Read for Stdin {
1717
}
1818

1919
impl Stdout {
20-
pub fn new() -> Stdout {
20+
pub const fn new() -> Stdout {
2121
Stdout
2222
}
2323
}
@@ -33,7 +33,7 @@ impl io::Write for Stdout {
3333
}
3434

3535
impl Stderr {
36-
pub fn new() -> Stderr {
36+
pub const fn new() -> Stderr {
3737
Stderr
3838
}
3939
}

library/std/src/sys/vxworks/stdio.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub struct Stdout(());
66
pub struct Stderr(());
77

88
impl Stdin {
9-
pub fn new() -> Stdin {
9+
pub const fn new() -> Stdin {
1010
Stdin(())
1111
}
1212
}
@@ -21,7 +21,7 @@ impl io::Read for Stdin {
2121
}
2222

2323
impl Stdout {
24-
pub fn new() -> Stdout {
24+
pub const fn new() -> Stdout {
2525
Stdout(())
2626
}
2727
}
@@ -40,7 +40,7 @@ impl io::Write for Stdout {
4040
}
4141

4242
impl Stderr {
43-
pub fn new() -> Stderr {
43+
pub const fn new() -> Stderr {
4444
Stderr(())
4545
}
4646
}

library/std/src/sys/wasi/stdio.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct Stdout;
77
pub struct Stderr;
88

99
impl Stdin {
10-
pub fn new() -> Stdin {
10+
pub const fn new() -> Stdin {
1111
Stdin
1212
}
1313

@@ -33,7 +33,7 @@ impl io::Read for Stdin {
3333
}
3434

3535
impl Stdout {
36-
pub fn new() -> Stdout {
36+
pub const fn new() -> Stdout {
3737
Stdout
3838
}
3939

@@ -62,7 +62,7 @@ impl io::Write for Stdout {
6262
}
6363

6464
impl Stderr {
65-
pub fn new() -> Stderr {
65+
pub const fn new() -> Stderr {
6666
Stderr
6767
}
6868

library/std/src/sys/windows/stdio.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn write_u16s(handle: c::HANDLE, data: &[u16]) -> io::Result<usize> {
131131
}
132132

133133
impl Stdin {
134-
pub fn new() -> Stdin {
134+
pub const fn new() -> Stdin {
135135
Stdin { surrogate: 0 }
136136
}
137137
}
@@ -255,7 +255,7 @@ fn utf16_to_utf8(utf16: &[u16], utf8: &mut [u8]) -> io::Result<usize> {
255255
}
256256

257257
impl Stdout {
258-
pub fn new() -> Stdout {
258+
pub const fn new() -> Stdout {
259259
Stdout
260260
}
261261
}
@@ -271,7 +271,7 @@ impl io::Write for Stdout {
271271
}
272272

273273
impl Stderr {
274-
pub fn new() -> Stderr {
274+
pub const fn new() -> Stderr {
275275
Stderr
276276
}
277277
}

library/std/src/sys/windows/stdio_uwp.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
3030
}
3131

3232
impl Stdin {
33-
pub fn new() -> Stdin {
33+
pub const fn new() -> Stdin {
3434
Stdin {}
3535
}
3636
}
@@ -44,7 +44,7 @@ impl io::Read for Stdin {
4444
}
4545

4646
impl Stdout {
47-
pub fn new() -> Stdout {
47+
pub const fn new() -> Stdout {
4848
Stdout
4949
}
5050
}
@@ -60,7 +60,7 @@ impl io::Write for Stdout {
6060
}
6161

6262
impl Stderr {
63-
pub fn new() -> Stderr {
63+
pub const fn new() -> Stderr {
6464
Stderr
6565
}
6666
}

0 commit comments

Comments
 (0)