Skip to content

Commit 479c23b

Browse files
committed
Remove result type from raw standard streams constructors
Raw standard streams constructors are infallible. Remove unnecessary result type.
1 parent 32cb8d4 commit 479c23b

File tree

10 files changed

+71
-79
lines changed

10 files changed

+71
-79
lines changed

library/std/src/io/stdio.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -50,8 +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() -> io::Result<StdinRaw> {
54-
stdio::Stdin::new().map(StdinRaw)
53+
fn stdin_raw() -> StdinRaw {
54+
StdinRaw(stdio::Stdin::new())
5555
}
5656

5757
/// Constructs a new raw handle to the standard output stream of this process.
@@ -63,8 +63,8 @@ fn stdin_raw() -> io::Result<StdinRaw> {
6363
///
6464
/// The returned handle has no external synchronization or buffering layered on
6565
/// top.
66-
fn stdout_raw() -> io::Result<StdoutRaw> {
67-
stdio::Stdout::new().map(StdoutRaw)
66+
fn stdout_raw() -> StdoutRaw {
67+
StdoutRaw(stdio::Stdout::new())
6868
}
6969

7070
/// Constructs a new raw handle to the standard error stream of this process.
@@ -74,8 +74,8 @@ fn stdout_raw() -> io::Result<StdoutRaw> {
7474
///
7575
/// The returned handle has no external synchronization or buffering layered on
7676
/// top.
77-
fn stderr_raw() -> io::Result<StderrRaw> {
78-
stdio::Stderr::new().map(StderrRaw)
77+
fn stderr_raw() -> StderrRaw {
78+
StderrRaw(stdio::Stderr::new())
7979
}
8080

8181
impl Read for StdinRaw {
@@ -356,11 +356,7 @@ pub fn stdin() -> Stdin {
356356

357357
fn stdin_init() -> Arc<Mutex<BufReader<Maybe<StdinRaw>>>> {
358358
// This must not reentrantly access `INSTANCE`
359-
let stdin = match stdin_raw() {
360-
Ok(stdin) => Maybe::Real(stdin),
361-
_ => Maybe::Fake,
362-
};
363-
359+
let stdin = Maybe::Real(stdin_raw());
364360
Arc::new(Mutex::new(BufReader::with_capacity(stdio::STDIN_BUF_SIZE, stdin)))
365361
}
366362
}
@@ -602,10 +598,7 @@ pub fn stdout() -> Stdout {
602598

603599
fn stdout_init() -> Arc<ReentrantMutex<RefCell<LineWriter<Maybe<StdoutRaw>>>>> {
604600
// This must not reentrantly access `INSTANCE`
605-
let stdout = match stdout_raw() {
606-
Ok(stdout) => Maybe::Real(stdout),
607-
_ => Maybe::Fake,
608-
};
601+
let stdout = Maybe::Real(stdout_raw());
609602
unsafe {
610603
let ret = Arc::new(ReentrantMutex::new(RefCell::new(LineWriter::new(stdout))));
611604
ret.init();
@@ -788,9 +781,8 @@ pub fn stderr() -> Stderr {
788781
static INIT: Once = Once::new();
789782
INIT.call_once(|| unsafe {
790783
INSTANCE.init();
791-
if let Ok(stderr) = stderr_raw() {
792-
*INSTANCE.lock().borrow_mut() = Maybe::Real(stderr);
793-
}
784+
let stderr = stderr_raw();
785+
*INSTANCE.lock().borrow_mut() = Maybe::Real(stderr);
794786
});
795787
Stderr { inner: &INSTANCE }
796788
}

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

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

88
impl Stdin {
9-
pub fn new() -> io::Result<Stdin> {
10-
Ok(Stdin(()))
9+
pub fn new() -> Stdin {
10+
Stdin(())
1111
}
1212
}
1313

@@ -18,8 +18,8 @@ impl io::Read for Stdin {
1818
}
1919

2020
impl Stdout {
21-
pub fn new() -> io::Result<Stdout> {
22-
Ok(Stdout(()))
21+
pub fn new() -> Stdout {
22+
Stdout(())
2323
}
2424
}
2525

@@ -37,8 +37,8 @@ impl io::Write for Stdout {
3737
}
3838

3939
impl Stderr {
40-
pub fn new() -> io::Result<Stderr> {
41-
Ok(Stderr(()))
40+
pub fn new() -> Stderr {
41+
Stderr(())
4242
}
4343
}
4444

@@ -62,5 +62,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
6262
pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
6363

6464
pub fn panic_output() -> Option<impl io::Write> {
65-
Stderr::new().ok()
65+
Some(Stderr::new())
6666
}

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

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

99
impl Stdin {
10-
pub fn new() -> io::Result<Stdin> {
11-
Ok(Stdin)
10+
pub fn new() -> Stdin {
11+
Stdin
1212
}
1313
}
1414

@@ -28,8 +28,8 @@ impl io::Read for Stdin {
2828
}
2929

3030
impl Stdout {
31-
pub fn new() -> io::Result<Stdout> {
32-
Ok(Stdout)
31+
pub fn new() -> Stdout {
32+
Stdout
3333
}
3434
}
3535

@@ -69,8 +69,8 @@ impl io::Write for Stdout {
6969
}
7070

7171
impl Stderr {
72-
pub fn new() -> io::Result<Stderr> {
73-
Ok(Stderr)
72+
pub fn new() -> Stderr {
73+
Stderr
7474
}
7575
}
7676

@@ -116,5 +116,5 @@ pub fn is_ebadf(_err: &io::Error) -> bool {
116116
}
117117

118118
pub fn panic_output() -> Option<impl io::Write> {
119-
Stderr::new().ok()
119+
Some(Stderr::new())
120120
}

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

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

2121
impl Stdin {
22-
pub fn new() -> io::Result<Stdin> {
23-
Ok(Stdin(()))
22+
pub fn new() -> Stdin {
23+
Stdin(())
2424
}
2525
}
2626

@@ -31,8 +31,8 @@ impl io::Read for Stdin {
3131
}
3232

3333
impl Stdout {
34-
pub fn new() -> io::Result<Stdout> {
35-
Ok(Stdout(()))
34+
pub fn new() -> Stdout {
35+
Stdout(())
3636
}
3737
}
3838

@@ -47,8 +47,8 @@ impl io::Write for Stdout {
4747
}
4848

4949
impl Stderr {
50-
pub fn new() -> io::Result<Stderr> {
51-
Ok(Stderr(()))
50+
pub fn new() -> Stderr {
51+
Stderr(())
5252
}
5353
}
5454

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

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

99
impl Stdin {
10-
pub fn new() -> io::Result<Stdin> {
11-
Ok(Stdin(()))
10+
pub fn new() -> Stdin {
11+
Stdin(())
1212
}
1313
}
1414

@@ -28,8 +28,8 @@ impl io::Read for Stdin {
2828
}
2929

3030
impl Stdout {
31-
pub fn new() -> io::Result<Stdout> {
32-
Ok(Stdout(()))
31+
pub fn new() -> Stdout {
32+
Stdout(())
3333
}
3434
}
3535

@@ -53,8 +53,8 @@ impl io::Write for Stdout {
5353
}
5454

5555
impl Stderr {
56-
pub fn new() -> io::Result<Stderr> {
57-
Ok(Stderr(()))
56+
pub fn new() -> Stderr {
57+
Stderr(())
5858
}
5959
}
6060

@@ -84,5 +84,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
8484
pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
8585

8686
pub fn panic_output() -> Option<impl io::Write> {
87-
Stderr::new().ok()
87+
Some(Stderr::new())
8888
}

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

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

77
impl Stdin {
8-
pub fn new() -> io::Result<Stdin> {
9-
Ok(Stdin)
8+
pub fn new() -> Stdin {
9+
Stdin
1010
}
1111
}
1212

@@ -17,8 +17,8 @@ impl io::Read for Stdin {
1717
}
1818

1919
impl Stdout {
20-
pub fn new() -> io::Result<Stdout> {
21-
Ok(Stdout)
20+
pub fn new() -> Stdout {
21+
Stdout
2222
}
2323
}
2424

@@ -33,8 +33,8 @@ impl io::Write for Stdout {
3333
}
3434

3535
impl Stderr {
36-
pub fn new() -> io::Result<Stderr> {
37-
Ok(Stderr)
36+
pub fn new() -> Stderr {
37+
Stderr
3838
}
3939
}
4040

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

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

88
impl Stdin {
9-
pub fn new() -> io::Result<Stdin> {
10-
Ok(Stdin(()))
9+
pub fn new() -> Stdin {
10+
Stdin(())
1111
}
1212
}
1313

@@ -21,8 +21,8 @@ impl io::Read for Stdin {
2121
}
2222

2323
impl Stdout {
24-
pub fn new() -> io::Result<Stdout> {
25-
Ok(Stdout(()))
24+
pub fn new() -> Stdout {
25+
Stdout(())
2626
}
2727
}
2828

@@ -40,8 +40,8 @@ impl io::Write for Stdout {
4040
}
4141

4242
impl Stderr {
43-
pub fn new() -> io::Result<Stderr> {
44-
Ok(Stderr(()))
43+
pub fn new() -> Stderr {
44+
Stderr(())
4545
}
4646
}
4747

@@ -65,5 +65,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
6565
pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
6666

6767
pub fn panic_output() -> Option<impl io::Write> {
68-
Stderr::new().ok()
68+
Some(Stderr::new())
6969
}

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

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

99
impl Stdin {
10-
pub fn new() -> io::Result<Stdin> {
11-
Ok(Stdin)
10+
pub fn new() -> Stdin {
11+
Stdin
1212
}
1313

1414
#[inline]
@@ -33,8 +33,8 @@ impl io::Read for Stdin {
3333
}
3434

3535
impl Stdout {
36-
pub fn new() -> io::Result<Stdout> {
37-
Ok(Stdout)
36+
pub fn new() -> Stdout {
37+
Stdout
3838
}
3939

4040
#[inline]
@@ -62,8 +62,8 @@ impl io::Write for Stdout {
6262
}
6363

6464
impl Stderr {
65-
pub fn new() -> io::Result<Stderr> {
66-
Ok(Stderr)
65+
pub fn new() -> Stderr {
66+
Stderr
6767
}
6868

6969
#[inline]
@@ -98,5 +98,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
9898
}
9999

100100
pub fn panic_output() -> Option<impl io::Write> {
101-
Stderr::new().ok()
101+
Some(Stderr::new())
102102
}

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

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

133133
impl Stdin {
134-
pub fn new() -> io::Result<Stdin> {
135-
Ok(Stdin { surrogate: 0 })
134+
pub fn new() -> Stdin {
135+
Stdin { surrogate: 0 }
136136
}
137137
}
138138

@@ -255,8 +255,8 @@ fn utf16_to_utf8(utf16: &[u16], utf8: &mut [u8]) -> io::Result<usize> {
255255
}
256256

257257
impl Stdout {
258-
pub fn new() -> io::Result<Stdout> {
259-
Ok(Stdout)
258+
pub fn new() -> Stdout {
259+
Stdout
260260
}
261261
}
262262

@@ -271,8 +271,8 @@ impl io::Write for Stdout {
271271
}
272272

273273
impl Stderr {
274-
pub fn new() -> io::Result<Stderr> {
275-
Ok(Stderr)
274+
pub fn new() -> Stderr {
275+
Stderr
276276
}
277277
}
278278

@@ -291,5 +291,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
291291
}
292292

293293
pub fn panic_output() -> Option<impl io::Write> {
294-
Stderr::new().ok()
294+
Some(Stderr::new())
295295
}

0 commit comments

Comments
 (0)