Skip to content

Commit

Permalink
Make raw standard stream constructors const
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Aug 21, 2020
1 parent 479c23b commit 4a00421
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 30 deletions.
9 changes: 6 additions & 3 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ struct StderrRaw(stdio::Stderr);
/// handles is **not** available to raw handles returned from this function.
///
/// The returned handle has no external synchronization or buffering.
fn stdin_raw() -> StdinRaw {
#[unstable(feature = "libstd_sys_internals", issue = "none")]
const fn stdin_raw() -> StdinRaw {
StdinRaw(stdio::Stdin::new())
}

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

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

Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/cloudabi/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct Stdout(());
pub struct Stderr(());

impl Stdin {
pub fn new() -> Stdin {
pub const fn new() -> Stdin {
Stdin(())
}
}
Expand All @@ -18,7 +18,7 @@ impl io::Read for Stdin {
}

impl Stdout {
pub fn new() -> Stdout {
pub const fn new() -> Stdout {
Stdout(())
}
}
Expand All @@ -37,7 +37,7 @@ impl io::Write for Stdout {
}

impl Stderr {
pub fn new() -> Stderr {
pub const fn new() -> Stderr {
Stderr(())
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/hermit/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Stdout;
pub struct Stderr;

impl Stdin {
pub fn new() -> Stdin {
pub const fn new() -> Stdin {
Stdin
}
}
Expand All @@ -28,7 +28,7 @@ impl io::Read for Stdin {
}

impl Stdout {
pub fn new() -> Stdout {
pub const fn new() -> Stdout {
Stdout
}
}
Expand Down Expand Up @@ -69,7 +69,7 @@ impl io::Write for Stdout {
}

impl Stderr {
pub fn new() -> Stderr {
pub const fn new() -> Stderr {
Stderr
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/sgx/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn with_std_fd<F: FnOnce(&FileDesc) -> R, R>(fd: abi::Fd, f: F) -> R {
}

impl Stdin {
pub fn new() -> Stdin {
pub const fn new() -> Stdin {
Stdin(())
}
}
Expand All @@ -31,7 +31,7 @@ impl io::Read for Stdin {
}

impl Stdout {
pub fn new() -> Stdout {
pub const fn new() -> Stdout {
Stdout(())
}
}
Expand All @@ -47,7 +47,7 @@ impl io::Write for Stdout {
}

impl Stderr {
pub fn new() -> Stderr {
pub const fn new() -> Stderr {
Stderr(())
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/unix/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Stdout(());
pub struct Stderr(());

impl Stdin {
pub fn new() -> Stdin {
pub const fn new() -> Stdin {
Stdin(())
}
}
Expand All @@ -28,7 +28,7 @@ impl io::Read for Stdin {
}

impl Stdout {
pub fn new() -> Stdout {
pub const fn new() -> Stdout {
Stdout(())
}
}
Expand All @@ -53,7 +53,7 @@ impl io::Write for Stdout {
}

impl Stderr {
pub fn new() -> Stderr {
pub const fn new() -> Stderr {
Stderr(())
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/unsupported/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct Stdout;
pub struct Stderr;

impl Stdin {
pub fn new() -> Stdin {
pub const fn new() -> Stdin {
Stdin
}
}
Expand All @@ -17,7 +17,7 @@ impl io::Read for Stdin {
}

impl Stdout {
pub fn new() -> Stdout {
pub const fn new() -> Stdout {
Stdout
}
}
Expand All @@ -33,7 +33,7 @@ impl io::Write for Stdout {
}

impl Stderr {
pub fn new() -> Stderr {
pub const fn new() -> Stderr {
Stderr
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/vxworks/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct Stdout(());
pub struct Stderr(());

impl Stdin {
pub fn new() -> Stdin {
pub const fn new() -> Stdin {
Stdin(())
}
}
Expand All @@ -21,7 +21,7 @@ impl io::Read for Stdin {
}

impl Stdout {
pub fn new() -> Stdout {
pub const fn new() -> Stdout {
Stdout(())
}
}
Expand All @@ -40,7 +40,7 @@ impl io::Write for Stdout {
}

impl Stderr {
pub fn new() -> Stderr {
pub const fn new() -> Stderr {
Stderr(())
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/wasi/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Stdout;
pub struct Stderr;

impl Stdin {
pub fn new() -> Stdin {
pub const fn new() -> Stdin {
Stdin
}

Expand All @@ -33,7 +33,7 @@ impl io::Read for Stdin {
}

impl Stdout {
pub fn new() -> Stdout {
pub const fn new() -> Stdout {
Stdout
}

Expand Down Expand Up @@ -62,7 +62,7 @@ impl io::Write for Stdout {
}

impl Stderr {
pub fn new() -> Stderr {
pub const fn new() -> Stderr {
Stderr
}

Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/windows/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn write_u16s(handle: c::HANDLE, data: &[u16]) -> io::Result<usize> {
}

impl Stdin {
pub fn new() -> Stdin {
pub const fn new() -> Stdin {
Stdin { surrogate: 0 }
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ fn utf16_to_utf8(utf16: &[u16], utf8: &mut [u8]) -> io::Result<usize> {
}

impl Stdout {
pub fn new() -> Stdout {
pub const fn new() -> Stdout {
Stdout
}
}
Expand All @@ -271,7 +271,7 @@ impl io::Write for Stdout {
}

impl Stderr {
pub fn new() -> Stderr {
pub const fn new() -> Stderr {
Stderr
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/windows/stdio_uwp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
}

impl Stdin {
pub fn new() -> Stdin {
pub const fn new() -> Stdin {
Stdin {}
}
}
Expand All @@ -44,7 +44,7 @@ impl io::Read for Stdin {
}

impl Stdout {
pub fn new() -> Stdout {
pub const fn new() -> Stdout {
Stdout
}
}
Expand All @@ -60,7 +60,7 @@ impl io::Write for Stdout {
}

impl Stderr {
pub fn new() -> Stderr {
pub const fn new() -> Stderr {
Stderr
}
}
Expand Down

0 comments on commit 4a00421

Please sign in to comment.