]> git.lizzy.rs Git - rust.git/commitdiff
Remove result type from raw standard streams constructors
authorTomasz Miąsko <tomasz.miasko@gmail.com>
Thu, 20 Aug 2020 00:00:00 +0000 (00:00 +0000)
committerTomasz Miąsko <tomasz.miasko@gmail.com>
Fri, 21 Aug 2020 11:17:20 +0000 (13:17 +0200)
Raw standard streams constructors are infallible. Remove unnecessary
result type.

library/std/src/io/stdio.rs
library/std/src/sys/cloudabi/stdio.rs
library/std/src/sys/hermit/stdio.rs
library/std/src/sys/sgx/stdio.rs
library/std/src/sys/unix/stdio.rs
library/std/src/sys/unsupported/stdio.rs
library/std/src/sys/vxworks/stdio.rs
library/std/src/sys/wasi/stdio.rs
library/std/src/sys/windows/stdio.rs
library/std/src/sys/windows/stdio_uwp.rs

index 286eb92915e49381a0dd1c42d870cfa28da28b6e..f91264af531d55bfbac5e5200daf8153d1fa32f6 100644 (file)
@@ -50,8 +50,8 @@
 /// handles is **not** available to raw handles returned from this function.
 ///
 /// The returned handle has no external synchronization or buffering.
-fn stdin_raw() -> io::Result<StdinRaw> {
-    stdio::Stdin::new().map(StdinRaw)
+fn stdin_raw() -> StdinRaw {
+    StdinRaw(stdio::Stdin::new())
 }
 
 /// Constructs a new raw handle to the standard output stream of this process.
@@ -63,8 +63,8 @@ fn stdin_raw() -> io::Result<StdinRaw> {
 ///
 /// The returned handle has no external synchronization or buffering layered on
 /// top.
-fn stdout_raw() -> io::Result<StdoutRaw> {
-    stdio::Stdout::new().map(StdoutRaw)
+fn stdout_raw() -> StdoutRaw {
+    StdoutRaw(stdio::Stdout::new())
 }
 
 /// Constructs a new raw handle to the standard error stream of this process.
@@ -74,8 +74,8 @@ fn stdout_raw() -> io::Result<StdoutRaw> {
 ///
 /// The returned handle has no external synchronization or buffering layered on
 /// top.
-fn stderr_raw() -> io::Result<StderrRaw> {
-    stdio::Stderr::new().map(StderrRaw)
+fn stderr_raw() -> StderrRaw {
+    StderrRaw(stdio::Stderr::new())
 }
 
 impl Read for StdinRaw {
@@ -356,11 +356,7 @@ pub fn stdin() -> Stdin {
 
     fn stdin_init() -> Arc<Mutex<BufReader<Maybe<StdinRaw>>>> {
         // This must not reentrantly access `INSTANCE`
-        let stdin = match stdin_raw() {
-            Ok(stdin) => Maybe::Real(stdin),
-            _ => Maybe::Fake,
-        };
-
+        let stdin = Maybe::Real(stdin_raw());
         Arc::new(Mutex::new(BufReader::with_capacity(stdio::STDIN_BUF_SIZE, stdin)))
     }
 }
@@ -602,10 +598,7 @@ pub fn stdout() -> Stdout {
 
     fn stdout_init() -> Arc<ReentrantMutex<RefCell<LineWriter<Maybe<StdoutRaw>>>>> {
         // This must not reentrantly access `INSTANCE`
-        let stdout = match stdout_raw() {
-            Ok(stdout) => Maybe::Real(stdout),
-            _ => Maybe::Fake,
-        };
+        let stdout = Maybe::Real(stdout_raw());
         unsafe {
             let ret = Arc::new(ReentrantMutex::new(RefCell::new(LineWriter::new(stdout))));
             ret.init();
@@ -788,9 +781,8 @@ pub fn stderr() -> Stderr {
     static INIT: Once = Once::new();
     INIT.call_once(|| unsafe {
         INSTANCE.init();
-        if let Ok(stderr) = stderr_raw() {
-            *INSTANCE.lock().borrow_mut() = Maybe::Real(stderr);
-        }
+        let stderr = stderr_raw();
+        *INSTANCE.lock().borrow_mut() = Maybe::Real(stderr);
     });
     Stderr { inner: &INSTANCE }
 }
index 601563c5b1fcbdebe7e5dca84bea6f5432a42f61..d564f4f7f40b235bfe864d57b3df9f9ef2119703 100644 (file)
@@ -6,8 +6,8 @@
 pub struct Stderr(());
 
 impl Stdin {
-    pub fn new() -> io::Result<Stdin> {
-        Ok(Stdin(()))
+    pub fn new() -> Stdin {
+        Stdin(())
     }
 }
 
@@ -18,8 +18,8 @@ fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
 }
 
 impl Stdout {
-    pub fn new() -> io::Result<Stdout> {
-        Ok(Stdout(()))
+    pub fn new() -> Stdout {
+        Stdout(())
     }
 }
 
@@ -37,8 +37,8 @@ fn flush(&mut self) -> io::Result<()> {
 }
 
 impl Stderr {
-    pub fn new() -> io::Result<Stderr> {
-        Ok(Stderr(()))
+    pub fn new() -> Stderr {
+        Stderr(())
     }
 }
 
@@ -62,5 +62,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
 pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
 
 pub fn panic_output() -> Option<impl io::Write> {
-    Stderr::new().ok()
+    Some(Stderr::new())
 }
index f3654ee38716c7c54ab09e65f0230606465ba556..359ea13c2befc08be5033ac81928eab5549a3f47 100644 (file)
@@ -7,8 +7,8 @@
 pub struct Stderr;
 
 impl Stdin {
-    pub fn new() -> io::Result<Stdin> {
-        Ok(Stdin)
+    pub fn new() -> Stdin {
+        Stdin
     }
 }
 
@@ -28,8 +28,8 @@ fn is_read_vectored(&self) -> bool {
 }
 
 impl Stdout {
-    pub fn new() -> io::Result<Stdout> {
-        Ok(Stdout)
+    pub fn new() -> Stdout {
+        Stdout
     }
 }
 
@@ -69,8 +69,8 @@ fn flush(&mut self) -> io::Result<()> {
 }
 
 impl Stderr {
-    pub fn new() -> io::Result<Stderr> {
-        Ok(Stderr)
+    pub fn new() -> Stderr {
+        Stderr
     }
 }
 
@@ -116,5 +116,5 @@ pub fn is_ebadf(_err: &io::Error) -> bool {
 }
 
 pub fn panic_output() -> Option<impl io::Write> {
-    Stderr::new().ok()
+    Some(Stderr::new())
 }
index 716c174bd53b65a165231e2c1959603384b2a4d2..d771a39ea851e8140bdc32d45b8fc9a03d711455 100644 (file)
@@ -19,8 +19,8 @@ fn with_std_fd<F: FnOnce(&FileDesc) -> R, R>(fd: abi::Fd, f: F) -> R {
 }
 
 impl Stdin {
-    pub fn new() -> io::Result<Stdin> {
-        Ok(Stdin(()))
+    pub fn new() -> Stdin {
+        Stdin(())
     }
 }
 
@@ -31,8 +31,8 @@ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
 }
 
 impl Stdout {
-    pub fn new() -> io::Result<Stdout> {
-        Ok(Stdout(()))
+    pub fn new() -> Stdout {
+        Stdout(())
     }
 }
 
@@ -47,8 +47,8 @@ fn flush(&mut self) -> io::Result<()> {
 }
 
 impl Stderr {
-    pub fn new() -> io::Result<Stderr> {
-        Ok(Stderr(()))
+    pub fn new() -> Stderr {
+        Stderr(())
     }
 }
 
index f8353214cbca037fa635f342bf6e700a0aabf8e1..bbf5dd65fa5d9d24936be3cd5c4240aa77971727 100644 (file)
@@ -7,8 +7,8 @@
 pub struct Stderr(());
 
 impl Stdin {
-    pub fn new() -> io::Result<Stdin> {
-        Ok(Stdin(()))
+    pub fn new() -> Stdin {
+        Stdin(())
     }
 }
 
@@ -28,8 +28,8 @@ fn is_read_vectored(&self) -> bool {
 }
 
 impl Stdout {
-    pub fn new() -> io::Result<Stdout> {
-        Ok(Stdout(()))
+    pub fn new() -> Stdout {
+        Stdout(())
     }
 }
 
@@ -53,8 +53,8 @@ fn flush(&mut self) -> io::Result<()> {
 }
 
 impl Stderr {
-    pub fn new() -> io::Result<Stderr> {
-        Ok(Stderr(()))
+    pub fn new() -> Stderr {
+        Stderr(())
     }
 }
 
@@ -84,5 +84,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
 pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
 
 pub fn panic_output() -> Option<impl io::Write> {
-    Stderr::new().ok()
+    Some(Stderr::new())
 }
index 5a4e4505e93bddce1805a1f163e2df0c66bc7cfd..7e60e0712dd9d2bbd8f2494f7cc7e5a770916bff 100644 (file)
@@ -5,8 +5,8 @@
 pub struct Stderr;
 
 impl Stdin {
-    pub fn new() -> io::Result<Stdin> {
-        Ok(Stdin)
+    pub fn new() -> Stdin {
+        Stdin
     }
 }
 
@@ -17,8 +17,8 @@ fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
 }
 
 impl Stdout {
-    pub fn new() -> io::Result<Stdout> {
-        Ok(Stdout)
+    pub fn new() -> Stdout {
+        Stdout
     }
 }
 
@@ -33,8 +33,8 @@ fn flush(&mut self) -> io::Result<()> {
 }
 
 impl Stderr {
-    pub fn new() -> io::Result<Stderr> {
-        Ok(Stderr)
+    pub fn new() -> Stderr {
+        Stderr
     }
 }
 
index 622444ccafd3cd0d97d4426b8e515951b82d1c77..e99d2d583467ee77c60e01f5eae27fb3cb1a670a 100644 (file)
@@ -6,8 +6,8 @@
 pub struct Stderr(());
 
 impl Stdin {
-    pub fn new() -> io::Result<Stdin> {
-        Ok(Stdin(()))
+    pub fn new() -> Stdin {
+        Stdin(())
     }
 }
 
@@ -21,8 +21,8 @@ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
 }
 
 impl Stdout {
-    pub fn new() -> io::Result<Stdout> {
-        Ok(Stdout(()))
+    pub fn new() -> Stdout {
+        Stdout(())
     }
 }
 
@@ -40,8 +40,8 @@ fn flush(&mut self) -> io::Result<()> {
 }
 
 impl Stderr {
-    pub fn new() -> io::Result<Stderr> {
-        Ok(Stderr(()))
+    pub fn new() -> Stderr {
+        Stderr(())
     }
 }
 
@@ -65,5 +65,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
 pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
 
 pub fn panic_output() -> Option<impl io::Write> {
-    Stderr::new().ok()
+    Some(Stderr::new())
 }
index 78e3911dc4efea33e1edc322a40e54ab7856e2bb..cc27e2ee5833c1b2ea506b965fa369df954b1647 100644 (file)
@@ -7,8 +7,8 @@
 pub struct Stderr;
 
 impl Stdin {
-    pub fn new() -> io::Result<Stdin> {
-        Ok(Stdin)
+    pub fn new() -> Stdin {
+        Stdin
     }
 
     #[inline]
@@ -33,8 +33,8 @@ fn is_read_vectored(&self) -> bool {
 }
 
 impl Stdout {
-    pub fn new() -> io::Result<Stdout> {
-        Ok(Stdout)
+    pub fn new() -> Stdout {
+        Stdout
     }
 
     #[inline]
@@ -62,8 +62,8 @@ fn flush(&mut self) -> io::Result<()> {
 }
 
 impl Stderr {
-    pub fn new() -> io::Result<Stderr> {
-        Ok(Stderr)
+    pub fn new() -> Stderr {
+        Stderr
     }
 
     #[inline]
@@ -98,5 +98,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
 }
 
 pub fn panic_output() -> Option<impl io::Write> {
-    Stderr::new().ok()
+    Some(Stderr::new())
 }
index c84896296ecb930902e09d010d60c85d216c3c60..b2e5458c0d2220b3e155bf3ae8636da17fbe7fd0 100644 (file)
@@ -131,8 +131,8 @@ fn write_u16s(handle: c::HANDLE, data: &[u16]) -> io::Result<usize> {
 }
 
 impl Stdin {
-    pub fn new() -> io::Result<Stdin> {
-        Ok(Stdin { surrogate: 0 })
+    pub fn new() -> Stdin {
+        Stdin { surrogate: 0 }
     }
 }
 
@@ -255,8 +255,8 @@ fn utf16_to_utf8(utf16: &[u16], utf8: &mut [u8]) -> io::Result<usize> {
 }
 
 impl Stdout {
-    pub fn new() -> io::Result<Stdout> {
-        Ok(Stdout)
+    pub fn new() -> Stdout {
+        Stdout
     }
 }
 
@@ -271,8 +271,8 @@ fn flush(&mut self) -> io::Result<()> {
 }
 
 impl Stderr {
-    pub fn new() -> io::Result<Stderr> {
-        Ok(Stderr)
+    pub fn new() -> Stderr {
+        Stderr
     }
 }
 
@@ -291,5 +291,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
 }
 
 pub fn panic_output() -> Option<impl io::Write> {
-    Stderr::new().ok()
+    Some(Stderr::new())
 }
index 5bdabf6d4b78efdaa81c74e514ce8076e459bf5e..0016f5dcd011240f992ea109e7f3bebd09e84d64 100644 (file)
@@ -30,8 +30,8 @@ fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
 }
 
 impl Stdin {
-    pub fn new() -> io::Result<Stdin> {
-        Ok(Stdin {})
+    pub fn new() -> Stdin {
+        Stdin {}
     }
 }
 
@@ -44,8 +44,8 @@ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
 }
 
 impl Stdout {
-    pub fn new() -> io::Result<Stdout> {
-        Ok(Stdout)
+    pub fn new() -> Stdout {
+        Stdout
     }
 }
 
@@ -60,8 +60,8 @@ fn flush(&mut self) -> io::Result<()> {
 }
 
 impl Stderr {
-    pub fn new() -> io::Result<Stderr> {
-        Ok(Stderr)
+    pub fn new() -> Stderr {
+        Stderr
     }
 }
 
@@ -80,5 +80,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
 }
 
 pub fn panic_output() -> Option<impl io::Write> {
-    Stderr::new().ok()
+    Some(Stderr::new())
 }