diff options
Diffstat (limited to 'src/libstd/sys')
25 files changed, 307 insertions, 307 deletions
diff --git a/src/libstd/sys/common/backtrace.rs b/src/libstd/sys/common/backtrace.rs index 3c84783d215..b81fb3011c7 100644 --- a/src/libstd/sys/common/backtrace.rs +++ b/src/libstd/sys/common/backtrace.rs @@ -46,10 +46,10 @@ pub fn log_enabled() -> bool { // These output functions should now be used everywhere to ensure consistency. pub fn output(w: &mut Write, idx: isize, addr: *mut libc::c_void, s: Option<&[u8]>) -> io::Result<()> { - try!(write!(w, " {:2}: {:2$?} - ", idx, addr, HEX_WIDTH)); + write!(w, " {:2}: {:2$?} - ", idx, addr, HEX_WIDTH)?; match s.and_then(|s| str::from_utf8(s).ok()) { - Some(string) => try!(demangle(w, string)), - None => try!(write!(w, "<unknown>")), + Some(string) => demangle(w, string)?, + None => write!(w, "<unknown>")?, } w.write_all(&['\n' as u8]) } @@ -59,9 +59,9 @@ pub fn output_fileline(w: &mut Write, file: &[u8], line: libc::c_int, more: bool) -> io::Result<()> { let file = str::from_utf8(file).unwrap_or("<unknown>"); // prior line: " ##: {:2$} - func" - try!(write!(w, " {:3$}at {}:{}", "", file, line, HEX_WIDTH)); + write!(w, " {:3$}at {}:{}", "", file, line, HEX_WIDTH)?; if more { - try!(write!(w, " <... and possibly more>")); + write!(w, " <... and possibly more>")?; } w.write_all(&['\n' as u8]) } @@ -121,12 +121,12 @@ pub fn demangle(writer: &mut Write, s: &str) -> io::Result<()> { // Alright, let's do this. if !valid { - try!(writer.write_all(s.as_bytes())); + writer.write_all(s.as_bytes())?; } else { let mut first = true; while !inner.is_empty() { if !first { - try!(writer.write_all(b"::")); + writer.write_all(b"::")?; } else { first = false; } @@ -177,7 +177,7 @@ pub fn demangle(writer: &mut Write, s: &str) -> io::Result<()> { None => rest.len(), Some(i) => i, }; - try!(writer.write_all(rest[..idx].as_bytes())); + writer.write_all(rest[..idx].as_bytes())?; rest = &rest[idx..]; } } diff --git a/src/libstd/sys/common/gnu/libbacktrace.rs b/src/libstd/sys/common/gnu/libbacktrace.rs index 8b3cb04030c..db719ccce61 100644 --- a/src/libstd/sys/common/gnu/libbacktrace.rs +++ b/src/libstd/sys/common/gnu/libbacktrace.rs @@ -172,9 +172,9 @@ pub fn print(w: &mut Write, idx: isize, addr: *mut libc::c_void, data_addr as *mut libc::c_void) }; if ret == 0 || data.is_null() { - try!(output(w, idx, addr, None)); + output(w, idx, addr, None)?; } else { - try!(output(w, idx, addr, Some(unsafe { CStr::from_ptr(data).to_bytes() }))); + output(w, idx, addr, Some(unsafe { CStr::from_ptr(data).to_bytes() }))?; } // pcinfo may return an arbitrary number of file:line pairs, @@ -198,7 +198,7 @@ pub fn print(w: &mut Write, idx: isize, addr: *mut libc::c_void, for (i, &(file, line)) in fileline_buf[..fileline_count].iter().enumerate() { if file.is_null() { continue; } // just to be sure let file = unsafe { CStr::from_ptr(file).to_bytes() }; - try!(output_fileline(w, file, line, i == FILELINE_SIZE - 1)); + output_fileline(w, file, line, i == FILELINE_SIZE - 1)?; } } diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 3fa70d0ce4b..07c535bf730 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -48,8 +48,8 @@ pub fn setsockopt<T>(sock: &Socket, opt: c_int, val: c_int, payload: T) -> io::Result<()> { unsafe { let payload = &payload as *const T as *const c_void; - try!(cvt(c::setsockopt(*sock.as_inner(), opt, val, payload, - mem::size_of::<T>() as c::socklen_t))); + cvt(c::setsockopt(*sock.as_inner(), opt, val, payload, + mem::size_of::<T>() as c::socklen_t))?; Ok(()) } } @@ -59,9 +59,9 @@ pub fn getsockopt<T: Copy>(sock: &Socket, opt: c_int, unsafe { let mut slot: T = mem::zeroed(); let mut len = mem::size_of::<T>() as c::socklen_t; - try!(cvt(c::getsockopt(*sock.as_inner(), opt, val, + cvt(c::getsockopt(*sock.as_inner(), opt, val, &mut slot as *mut _ as *mut _, - &mut len))); + &mut len))?; assert_eq!(len as usize, mem::size_of::<T>()); Ok(slot) } @@ -73,7 +73,7 @@ fn sockname<F>(f: F) -> io::Result<SocketAddr> unsafe { let mut storage: c::sockaddr_storage = mem::zeroed(); let mut len = mem::size_of_val(&storage) as c::socklen_t; - try!(cvt(f(&mut storage as *mut _ as *mut _, &mut len))); + cvt(f(&mut storage as *mut _ as *mut _, &mut len))?; sockaddr_to_addr(&storage, len as usize) } } @@ -143,11 +143,11 @@ impl Drop for LookupHost { pub fn lookup_host(host: &str) -> io::Result<LookupHost> { init(); - let c_host = try!(CString::new(host)); + let c_host = CString::new(host)?; let mut res = ptr::null_mut(); unsafe { - try!(cvt_gai(c::getaddrinfo(c_host.as_ptr(), ptr::null(), ptr::null(), - &mut res))); + cvt_gai(c::getaddrinfo(c_host.as_ptr(), ptr::null(), ptr::null(), + &mut res))?; Ok(LookupHost { original: res, cur: res }) } } @@ -164,10 +164,10 @@ impl TcpStream { pub fn connect(addr: &SocketAddr) -> io::Result<TcpStream> { init(); - let sock = try!(Socket::new(addr, c::SOCK_STREAM)); + let sock = Socket::new(addr, c::SOCK_STREAM)?; let (addrp, len) = addr.into_inner(); - try!(cvt_r(|| unsafe { c::connect(*sock.as_inner(), addrp, len) })); + cvt_r(|| unsafe { c::connect(*sock.as_inner(), addrp, len) })?; Ok(TcpStream { inner: sock }) } @@ -201,12 +201,12 @@ impl TcpStream { pub fn write(&self, buf: &[u8]) -> io::Result<usize> { let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t; - let ret = try!(cvt(unsafe { + let ret = cvt(unsafe { c::send(*self.inner.as_inner(), buf.as_ptr() as *const c_void, len, 0) - })); + })?; Ok(ret as usize) } @@ -243,7 +243,7 @@ impl TcpStream { } pub fn ttl(&self) -> io::Result<u32> { - let raw: c_int = try!(getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)); + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; Ok(raw as u32) } @@ -252,7 +252,7 @@ impl TcpStream { } pub fn only_v6(&self) -> io::Result<bool> { - let raw: c_int = try!(getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)); + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)?; Ok(raw != 0) } @@ -301,22 +301,22 @@ impl TcpListener { pub fn bind(addr: &SocketAddr) -> io::Result<TcpListener> { init(); - let sock = try!(Socket::new(addr, c::SOCK_STREAM)); + let sock = Socket::new(addr, c::SOCK_STREAM)?; // On platforms with Berkeley-derived sockets, this allows // to quickly rebind a socket, without needing to wait for // the OS to clean up the previous one. if !cfg!(windows) { - try!(setsockopt(&sock, c::SOL_SOCKET, c::SO_REUSEADDR, - 1 as c_int)); + setsockopt(&sock, c::SOL_SOCKET, c::SO_REUSEADDR, + 1 as c_int)?; } // Bind our new socket let (addrp, len) = addr.into_inner(); - try!(cvt(unsafe { c::bind(*sock.as_inner(), addrp, len) })); + cvt(unsafe { c::bind(*sock.as_inner(), addrp, len) })?; // Start listening - try!(cvt(unsafe { c::listen(*sock.as_inner(), 128) })); + cvt(unsafe { c::listen(*sock.as_inner(), 128) })?; Ok(TcpListener { inner: sock }) } @@ -333,9 +333,9 @@ impl TcpListener { pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> { let mut storage: c::sockaddr_storage = unsafe { mem::zeroed() }; let mut len = mem::size_of_val(&storage) as c::socklen_t; - let sock = try!(self.inner.accept(&mut storage as *mut _ as *mut _, - &mut len)); - let addr = try!(sockaddr_to_addr(&storage, len as usize)); + let sock = self.inner.accept(&mut storage as *mut _ as *mut _, + &mut len)?; + let addr = sockaddr_to_addr(&storage, len as usize)?; Ok((TcpStream { inner: sock, }, addr)) } @@ -348,7 +348,7 @@ impl TcpListener { } pub fn ttl(&self) -> io::Result<u32> { - let raw: c_int = try!(getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)); + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; Ok(raw as u32) } @@ -357,7 +357,7 @@ impl TcpListener { } pub fn only_v6(&self) -> io::Result<bool> { - let raw: c_int = try!(getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)); + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)?; Ok(raw != 0) } @@ -402,9 +402,9 @@ impl UdpSocket { pub fn bind(addr: &SocketAddr) -> io::Result<UdpSocket> { init(); - let sock = try!(Socket::new(addr, c::SOCK_DGRAM)); + let sock = Socket::new(addr, c::SOCK_DGRAM)?; let (addrp, len) = addr.into_inner(); - try!(cvt(unsafe { c::bind(*sock.as_inner(), addrp, len) })); + cvt(unsafe { c::bind(*sock.as_inner(), addrp, len) })?; Ok(UdpSocket { inner: sock }) } @@ -423,23 +423,23 @@ impl UdpSocket { let mut addrlen = mem::size_of_val(&storage) as c::socklen_t; let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t; - let n = try!(cvt(unsafe { + let n = cvt(unsafe { c::recvfrom(*self.inner.as_inner(), buf.as_mut_ptr() as *mut c_void, len, 0, &mut storage as *mut _ as *mut _, &mut addrlen) - })); - Ok((n as usize, try!(sockaddr_to_addr(&storage, addrlen as usize)))) + })?; + Ok((n as usize, sockaddr_to_addr(&storage, addrlen as usize)?)) } pub fn send_to(&self, buf: &[u8], dst: &SocketAddr) -> io::Result<usize> { let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t; let (dstp, dstlen) = dst.into_inner(); - let ret = try!(cvt(unsafe { + let ret = cvt(unsafe { c::sendto(*self.inner.as_inner(), buf.as_ptr() as *const c_void, len, 0, dstp, dstlen) - })); + })?; Ok(ret as usize) } @@ -468,7 +468,7 @@ impl UdpSocket { } pub fn broadcast(&self) -> io::Result<bool> { - let raw: c_int = try!(getsockopt(&self.inner, c::SOL_SOCKET, c::SO_BROADCAST)); + let raw: c_int = getsockopt(&self.inner, c::SOL_SOCKET, c::SO_BROADCAST)?; Ok(raw != 0) } @@ -477,7 +477,7 @@ impl UdpSocket { } pub fn multicast_loop_v4(&self) -> io::Result<bool> { - let raw: c_int = try!(getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)); + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)?; Ok(raw != 0) } @@ -486,7 +486,7 @@ impl UdpSocket { } pub fn multicast_ttl_v4(&self) -> io::Result<u32> { - let raw: c_int = try!(getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)); + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)?; Ok(raw as u32) } @@ -495,7 +495,7 @@ impl UdpSocket { } pub fn multicast_loop_v6(&self) -> io::Result<bool> { - let raw: c_int = try!(getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP)); + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP)?; Ok(raw != 0) } @@ -540,7 +540,7 @@ impl UdpSocket { } pub fn ttl(&self) -> io::Result<u32> { - let raw: c_int = try!(getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)); + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; Ok(raw as u32) } @@ -549,7 +549,7 @@ impl UdpSocket { } pub fn only_v6(&self) -> io::Result<bool> { - let raw: c_int = try!(getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)); + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)?; Ok(raw != 0) } @@ -567,12 +567,12 @@ impl UdpSocket { pub fn send(&self, buf: &[u8]) -> io::Result<usize> { let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t; - let ret = try!(cvt(unsafe { + let ret = cvt(unsafe { c::send(*self.inner.as_inner(), buf.as_ptr() as *const c_void, len, 0) - })); + })?; Ok(ret as usize) } diff --git a/src/libstd/sys/common/remutex.rs b/src/libstd/sys/common/remutex.rs index 1793ad0e445..39d41042467 100644 --- a/src/libstd/sys/common/remutex.rs +++ b/src/libstd/sys/common/remutex.rs @@ -99,7 +99,7 @@ impl<T> ReentrantMutex<T> { /// acquired. pub fn try_lock(&self) -> TryLockResult<ReentrantMutexGuard<T>> { if unsafe { self.inner.try_lock() } { - Ok(try!(ReentrantMutexGuard::new(&self))) + Ok(ReentrantMutexGuard::new(&self)?) } else { Err(TryLockError::WouldBlock) } diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index db3bc2ed751..8b79016c251 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -388,32 +388,32 @@ impl fmt::Debug for Wtf8 { fn write_str_escaped(f: &mut fmt::Formatter, s: &str) -> fmt::Result { use fmt::Write; for c in s.chars().flat_map(|c| c.escape_default()) { - try!(f.write_char(c)) + f.write_char(c)? } Ok(()) } - try!(formatter.write_str("\"")); + formatter.write_str("\"")?; let mut pos = 0; loop { match self.next_surrogate(pos) { None => break, Some((surrogate_pos, surrogate)) => { - try!(write_str_escaped( + write_str_escaped( formatter, unsafe { str::from_utf8_unchecked( &self.bytes[pos .. surrogate_pos] )}, - )); - try!(write!(formatter, "\\u{{{:X}}}", surrogate)); + )?; + write!(formatter, "\\u{{{:X}}}", surrogate)?; pos = surrogate_pos + 3; } } } - try!(write_str_escaped( + write_str_escaped( formatter, unsafe { str::from_utf8_unchecked(&self.bytes[pos..]) }, - )); + )?; formatter.write_str("\"") } } diff --git a/src/libstd/sys/unix/backtrace/tracing/backtrace_fn.rs b/src/libstd/sys/unix/backtrace/tracing/backtrace_fn.rs index 46f276aecf4..de93d3d4e50 100644 --- a/src/libstd/sys/unix/backtrace/tracing/backtrace_fn.rs +++ b/src/libstd/sys/unix/backtrace/tracing/backtrace_fn.rs @@ -40,7 +40,7 @@ pub fn write(w: &mut Write) -> io::Result<()> { static LOCK: StaticMutex = StaticMutex::new(); let _g = LOCK.lock(); - try!(writeln!(w, "stack backtrace:")); + writeln!(w, "stack backtrace:")?; // 100 lines should be enough const SIZE: usize = 100; let mut buf: [*mut libc::c_void; SIZE] = unsafe { mem::zeroed() }; @@ -48,7 +48,7 @@ pub fn write(w: &mut Write) -> io::Result<()> { // skipping the first one as it is write itself for i in 1..cnt { - try!(print(w, i as isize, buf[i], buf[i])) + print(w, i as isize, buf[i], buf[i])? } Ok(()) } diff --git a/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs b/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs index 8b32b5ec040..8d880917166 100644 --- a/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs +++ b/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs @@ -33,7 +33,7 @@ pub fn write(w: &mut Write) -> io::Result<()> { static LOCK: StaticMutex = StaticMutex::new(); let _g = LOCK.lock(); - try!(writeln!(w, "stack backtrace:")); + writeln!(w, "stack backtrace:")?; let mut cx = Context { writer: w, last_error: None, idx: 0 }; return match unsafe { diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 2ee825f1ec2..51ac8cb82d1 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -87,7 +87,7 @@ impl SocketAddr { unsafe { let mut addr: libc::sockaddr_un = mem::zeroed(); let mut len = mem::size_of::<libc::sockaddr_un>() as libc::socklen_t; - try!(cvt(f(&mut addr as *mut _ as *mut _, &mut len))); + cvt(f(&mut addr as *mut _ as *mut _, &mut len))?; SocketAddr::from_parts(addr, len) } } @@ -155,9 +155,9 @@ struct AsciiEscaped<'a>(&'a [u8]); impl<'a> fmt::Display for AsciiEscaped<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(write!(fmt, "\"")); + write!(fmt, "\"")?; for byte in self.0.iter().cloned().flat_map(ascii::escape_default) { - try!(write!(fmt, "{}", byte as char)); + write!(fmt, "{}", byte as char)?; } write!(fmt, "\"") } @@ -200,10 +200,10 @@ impl UnixStream { pub fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> { fn inner(path: &Path) -> io::Result<UnixStream> { unsafe { - let inner = try!(Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)); - let (addr, len) = try!(sockaddr_un(path)); + let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; + let (addr, len) = sockaddr_un(path)?; - try!(cvt(libc::connect(*inner.as_inner(), &addr as *const _ as *const _, len))); + cvt(libc::connect(*inner.as_inner(), &addr as *const _ as *const _, len))?; Ok(UnixStream(inner)) } } @@ -214,7 +214,7 @@ impl UnixStream { /// /// Returns two `UnixStream`s which are connected to each other. pub fn pair() -> io::Result<(UnixStream, UnixStream)> { - let (i1, i2) = try!(Socket::new_pair(libc::AF_UNIX, libc::SOCK_STREAM)); + let (i1, i2) = Socket::new_pair(libc::AF_UNIX, libc::SOCK_STREAM)?; Ok((UnixStream(i1), UnixStream(i2))) } @@ -395,11 +395,11 @@ impl UnixListener { pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> { fn inner(path: &Path) -> io::Result<UnixListener> { unsafe { - let inner = try!(Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)); - let (addr, len) = try!(sockaddr_un(path)); + let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; + let (addr, len) = sockaddr_un(path)?; - try!(cvt(libc::bind(*inner.as_inner(), &addr as *const _ as *const _, len))); - try!(cvt(libc::listen(*inner.as_inner(), 128))); + cvt(libc::bind(*inner.as_inner(), &addr as *const _ as *const _, len))?; + cvt(libc::listen(*inner.as_inner(), 128))?; Ok(UnixListener(inner)) } @@ -415,8 +415,8 @@ impl UnixListener { pub fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> { let mut storage: libc::sockaddr_un = unsafe { mem::zeroed() }; let mut len = mem::size_of_val(&storage) as libc::socklen_t; - let sock = try!(self.0.accept(&mut storage as *mut _ as *mut _, &mut len)); - let addr = try!(SocketAddr::from_parts(storage, len)); + let sock = self.0.accept(&mut storage as *mut _ as *mut _, &mut len)?; + let addr = SocketAddr::from_parts(storage, len)?; Ok((UnixStream(sock), addr)) } @@ -536,10 +536,10 @@ impl UnixDatagram { pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixDatagram> { fn inner(path: &Path) -> io::Result<UnixDatagram> { unsafe { - let socket = try!(UnixDatagram::unbound()); - let (addr, len) = try!(sockaddr_un(path)); + let socket = UnixDatagram::unbound()?; + let (addr, len) = sockaddr_un(path)?; - try!(cvt(libc::bind(*socket.0.as_inner(), &addr as *const _ as *const _, len))); + cvt(libc::bind(*socket.0.as_inner(), &addr as *const _ as *const _, len))?; Ok(socket) } @@ -549,7 +549,7 @@ impl UnixDatagram { /// Creates a Unix Datagram socket which is not bound to any address. pub fn unbound() -> io::Result<UnixDatagram> { - let inner = try!(Socket::new_raw(libc::AF_UNIX, libc::SOCK_DGRAM)); + let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_DGRAM)?; Ok(UnixDatagram(inner)) } @@ -557,7 +557,7 @@ impl UnixDatagram { /// /// Returns two `UnixDatagrams`s which are connected to each other. pub fn pair() -> io::Result<(UnixDatagram, UnixDatagram)> { - let (i1, i2) = try!(Socket::new_pair(libc::AF_UNIX, libc::SOCK_DGRAM)); + let (i1, i2) = Socket::new_pair(libc::AF_UNIX, libc::SOCK_DGRAM)?; Ok((UnixDatagram(i1), UnixDatagram(i2))) } @@ -568,9 +568,9 @@ impl UnixDatagram { pub fn connect<P: AsRef<Path>>(&self, path: P) -> io::Result<()> { fn inner(d: &UnixDatagram, path: &Path) -> io::Result<()> { unsafe { - let (addr, len) = try!(sockaddr_un(path)); + let (addr, len) = sockaddr_un(path)?; - try!(cvt(libc::connect(*d.0.as_inner(), &addr as *const _ as *const _, len))); + cvt(libc::connect(*d.0.as_inner(), &addr as *const _ as *const _, len))?; Ok(()) } @@ -605,7 +605,7 @@ impl UnixDatagram { /// whence the data came. pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { let mut count = 0; - let addr = try!(SocketAddr::new(|addr, len| { + let addr = SocketAddr::new(|addr, len| { unsafe { count = libc::recvfrom(*self.0.as_inner(), buf.as_mut_ptr() as *mut _, @@ -621,7 +621,7 @@ impl UnixDatagram { -1 } } - })); + })?; Ok((count as usize, addr)) } @@ -639,14 +639,14 @@ impl UnixDatagram { pub fn send_to<P: AsRef<Path>>(&self, buf: &[u8], path: P) -> io::Result<usize> { fn inner(d: &UnixDatagram, buf: &[u8], path: &Path) -> io::Result<usize> { unsafe { - let (addr, len) = try!(sockaddr_un(path)); + let (addr, len) = sockaddr_un(path)?; - let count = try!(cvt(libc::sendto(*d.0.as_inner(), + let count = cvt(libc::sendto(*d.0.as_inner(), buf.as_ptr() as *const _, buf.len(), 0, &addr as *const _ as *const _, - len))); + len))?; Ok(count as usize) } } diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index 8ec073858fd..94c48be02ff 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -39,11 +39,11 @@ impl FileDesc { } pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> { - let ret = try!(cvt(unsafe { + let ret = cvt(unsafe { libc::read(self.fd, buf.as_mut_ptr() as *mut c_void, buf.len() as size_t) - })); + })?; Ok(ret as usize) } @@ -53,11 +53,11 @@ impl FileDesc { } pub fn write(&self, buf: &[u8]) -> io::Result<usize> { - let ret = try!(cvt(unsafe { + let ret = cvt(unsafe { libc::write(self.fd, buf.as_ptr() as *const c_void, buf.len() as size_t) - })); + })?; Ok(ret as usize) } diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 3985a07470e..810a34478c5 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -418,18 +418,18 @@ impl OpenOptions { impl File { pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> { - let path = try!(cstr(path)); + let path = cstr(path)?; File::open_c(&path, opts) } pub fn open_c(path: &CStr, opts: &OpenOptions) -> io::Result<File> { let flags = libc::O_CLOEXEC | - try!(opts.get_access_mode()) | - try!(opts.get_creation_mode()) | + opts.get_access_mode()? | + opts.get_creation_mode()? | (opts.custom_flags as c_int & !libc::O_ACCMODE); - let fd = try!(cvt_r(|| unsafe { + let fd = cvt_r(|| unsafe { open64(path.as_ptr(), flags, opts.mode as c_int) - })); + })?; let fd = FileDesc::new(fd); // Currently the standard library supports Linux 2.6.18 which did not @@ -448,19 +448,19 @@ impl File { pub fn file_attr(&self) -> io::Result<FileAttr> { let mut stat: stat64 = unsafe { mem::zeroed() }; - try!(cvt(unsafe { + cvt(unsafe { fstat64(self.0.raw(), &mut stat) - })); + })?; Ok(FileAttr { stat: stat }) } pub fn fsync(&self) -> io::Result<()> { - try!(cvt_r(|| unsafe { libc::fsync(self.0.raw()) })); + cvt_r(|| unsafe { libc::fsync(self.0.raw()) })?; Ok(()) } pub fn datasync(&self) -> io::Result<()> { - try!(cvt_r(|| unsafe { os_datasync(self.0.raw()) })); + cvt_r(|| unsafe { os_datasync(self.0.raw()) })?; return Ok(()); #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -476,9 +476,9 @@ impl File { } pub fn truncate(&self, size: u64) -> io::Result<()> { - try!(cvt_r(|| unsafe { + cvt_r(|| unsafe { ftruncate64(self.0.raw(), size as off64_t) - })); + })?; Ok(()) } @@ -502,7 +502,7 @@ impl File { SeekFrom::End(off) => (libc::SEEK_END, off as off64_t), SeekFrom::Current(off) => (libc::SEEK_CUR, off as off64_t), }; - let n = try!(cvt(unsafe { lseek64(self.0.raw(), pos, whence) })); + let n = cvt(unsafe { lseek64(self.0.raw(), pos, whence) })?; Ok(n as u64) } @@ -521,8 +521,8 @@ impl DirBuilder { } pub fn mkdir(&self, p: &Path) -> io::Result<()> { - let p = try!(cstr(p)); - try!(cvt(unsafe { libc::mkdir(p.as_ptr(), self.mode) })); + let p = cstr(p)?; + cvt(unsafe { libc::mkdir(p.as_ptr(), self.mode) })?; Ok(()) } @@ -532,7 +532,7 @@ impl DirBuilder { } fn cstr(path: &Path) -> io::Result<CString> { - Ok(try!(CString::new(path.as_os_str().as_bytes()))) + Ok(CString::new(path.as_os_str().as_bytes())?) } impl FromInner<c_int> for File { @@ -610,7 +610,7 @@ impl fmt::Debug for File { pub fn readdir(p: &Path) -> io::Result<ReadDir> { let root = Arc::new(p.to_path_buf()); - let p = try!(cstr(p)); + let p = cstr(p)?; unsafe { let ptr = libc::opendir(p.as_ptr()); if ptr.is_null() { @@ -622,32 +622,32 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> { } pub fn unlink(p: &Path) -> io::Result<()> { - let p = try!(cstr(p)); - try!(cvt(unsafe { libc::unlink(p.as_ptr()) })); + let p = cstr(p)?; + cvt(unsafe { libc::unlink(p.as_ptr()) })?; Ok(()) } pub fn rename(old: &Path, new: &Path) -> io::Result<()> { - let old = try!(cstr(old)); - let new = try!(cstr(new)); - try!(cvt(unsafe { libc::rename(old.as_ptr(), new.as_ptr()) })); + let old = cstr(old)?; + let new = cstr(new)?; + cvt(unsafe { libc::rename(old.as_ptr(), new.as_ptr()) })?; Ok(()) } pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> { - let p = try!(cstr(p)); - try!(cvt_r(|| unsafe { libc::chmod(p.as_ptr(), perm.mode) })); + let p = cstr(p)?; + cvt_r(|| unsafe { libc::chmod(p.as_ptr(), perm.mode) })?; Ok(()) } pub fn rmdir(p: &Path) -> io::Result<()> { - let p = try!(cstr(p)); - try!(cvt(unsafe { libc::rmdir(p.as_ptr()) })); + let p = cstr(p)?; + cvt(unsafe { libc::rmdir(p.as_ptr()) })?; Ok(()) } pub fn remove_dir_all(path: &Path) -> io::Result<()> { - let filetype = try!(lstat(path)).file_type(); + let filetype = lstat(path)?.file_type(); if filetype.is_symlink() { unlink(path) } else { @@ -656,27 +656,27 @@ pub fn remove_dir_all(path: &Path) -> io::Result<()> { } fn remove_dir_all_recursive(path: &Path) -> io::Result<()> { - for child in try!(readdir(path)) { - let child = try!(child); - if try!(child.file_type()).is_dir() { - try!(remove_dir_all_recursive(&child.path())); + for child in readdir(path)? { + let child = child?; + if child.file_type()?.is_dir() { + remove_dir_all_recursive(&child.path())?; } else { - try!(unlink(&child.path())); + unlink(&child.path())?; } } rmdir(path) } pub fn readlink(p: &Path) -> io::Result<PathBuf> { - let c_path = try!(cstr(p)); + let c_path = cstr(p)?; let p = c_path.as_ptr(); let mut buf = Vec::with_capacity(256); loop { - let buf_read = try!(cvt(unsafe { + let buf_read = cvt(unsafe { libc::readlink(p, buf.as_mut_ptr() as *mut _, buf.capacity() as libc::size_t) - })) as usize; + })? as usize; unsafe { buf.set_len(buf_read); } @@ -694,39 +694,39 @@ pub fn readlink(p: &Path) -> io::Result<PathBuf> { } pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { - let src = try!(cstr(src)); - let dst = try!(cstr(dst)); - try!(cvt(unsafe { libc::symlink(src.as_ptr(), dst.as_ptr()) })); + let src = cstr(src)?; + let dst = cstr(dst)?; + cvt(unsafe { libc::symlink(src.as_ptr(), dst.as_ptr()) })?; Ok(()) } pub fn link(src: &Path, dst: &Path) -> io::Result<()> { - let src = try!(cstr(src)); - let dst = try!(cstr(dst)); - try!(cvt(unsafe { libc::link(src.as_ptr(), dst.as_ptr()) })); + let src = cstr(src)?; + let dst = cstr(dst)?; + cvt(unsafe { libc::link(src.as_ptr(), dst.as_ptr()) })?; Ok(()) } pub fn stat(p: &Path) -> io::Result<FileAttr> { - let p = try!(cstr(p)); + let p = cstr(p)?; let mut stat: stat64 = unsafe { mem::zeroed() }; - try!(cvt(unsafe { + cvt(unsafe { stat64(p.as_ptr(), &mut stat as *mut _ as *mut _) - })); + })?; Ok(FileAttr { stat: stat }) } pub fn lstat(p: &Path) -> io::Result<FileAttr> { - let p = try!(cstr(p)); + let p = cstr(p)?; let mut stat: stat64 = unsafe { mem::zeroed() }; - try!(cvt(unsafe { + cvt(unsafe { lstat64(p.as_ptr(), &mut stat as *mut _ as *mut _) - })); + })?; Ok(FileAttr { stat: stat }) } pub fn canonicalize(p: &Path) -> io::Result<PathBuf> { - let path = try!(CString::new(p.as_os_str().as_bytes())); + let path = CString::new(p.as_os_str().as_bytes())?; let buf; unsafe { let r = libc::realpath(path.as_ptr(), ptr::null_mut()); @@ -746,11 +746,11 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { "the source path is not an existing regular file")) } - let mut reader = try!(File::open(from)); - let mut writer = try!(File::create(to)); - let perm = try!(reader.metadata()).permissions(); + let mut reader = File::open(from)?; + let mut writer = File::create(to)?; + let perm = reader.metadata()?.permissions(); - let ret = try!(io::copy(&mut reader, &mut writer)); - try!(set_permissions(to, perm)); + let ret = io::copy(&mut reader, &mut writer)?; + set_permissions(to, perm)?; Ok(ret) } diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index d7b353c9b2a..830957a7e59 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -75,7 +75,7 @@ impl Socket { } } - let fd = try!(cvt(libc::socket(fam, ty, 0))); + let fd = cvt(libc::socket(fam, ty, 0))?; let fd = FileDesc::new(fd); fd.set_cloexec(); Ok(Socket(fd)) @@ -97,7 +97,7 @@ impl Socket { } } - try!(cvt(libc::socketpair(fam, ty, 0, fds.as_mut_ptr()))); + cvt(libc::socketpair(fam, ty, 0, fds.as_mut_ptr()))?; let a = FileDesc::new(fds[0]); a.set_cloexec(); let b = FileDesc::new(fds[1]); @@ -128,9 +128,9 @@ impl Socket { } } - let fd = try!(cvt_r(|| unsafe { + let fd = cvt_r(|| unsafe { libc::accept(self.0.raw(), storage, len) - })); + })?; let fd = FileDesc::new(fd); fd.set_cloexec(); Ok(Socket(fd)) @@ -185,7 +185,7 @@ impl Socket { } pub fn timeout(&self, kind: libc::c_int) -> io::Result<Option<Duration>> { - let raw: libc::timeval = try!(getsockopt(self, libc::SOL_SOCKET, kind)); + let raw: libc::timeval = getsockopt(self, libc::SOL_SOCKET, kind)?; if raw.tv_sec == 0 && raw.tv_usec == 0 { Ok(None) } else { @@ -201,7 +201,7 @@ impl Socket { Shutdown::Read => libc::SHUT_RD, Shutdown::Both => libc::SHUT_RDWR, }; - try!(cvt(unsafe { libc::shutdown(self.0.raw(), how) })); + cvt(unsafe { libc::shutdown(self.0.raw(), how) })?; Ok(()) } @@ -210,7 +210,7 @@ impl Socket { } pub fn nodelay(&self) -> io::Result<bool> { - let raw: c_int = try!(getsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY)); + let raw: c_int = getsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY)?; Ok(raw != 0) } @@ -220,7 +220,7 @@ impl Socket { } pub fn take_error(&self) -> io::Result<Option<io::Error>> { - let raw: c_int = try!(getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)); + let raw: c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)?; if raw == 0 { Ok(None) } else { diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index b6a0bd84409..0d77f344914 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -110,7 +110,7 @@ pub fn getcwd() -> io::Result<PathBuf> { pub fn chdir(p: &path::Path) -> io::Result<()> { let p: &OsStr = p.as_ref(); - let p = try!(CString::new(p.as_bytes())); + let p = CString::new(p.as_bytes())?; unsafe { match libc::chdir(p.as_ptr()) == (0 as c_int) { true => Ok(()), @@ -180,16 +180,16 @@ pub fn current_exe() -> io::Result<PathBuf> { libc::KERN_PROC_PATHNAME as c_int, -1 as c_int]; let mut sz: libc::size_t = 0; - try!(cvt(libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, + cvt(libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, ptr::null_mut(), &mut sz, ptr::null_mut(), - 0 as libc::size_t))); + 0 as libc::size_t))?; if sz == 0 { return Err(io::Error::last_os_error()) } let mut v: Vec<u8> = Vec::with_capacity(sz as usize); - try!(cvt(libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, + cvt(libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, v.as_mut_ptr() as *mut libc::c_void, &mut sz, - ptr::null_mut(), 0 as libc::size_t))); + ptr::null_mut(), 0 as libc::size_t))?; if sz == 0 { return Err(io::Error::last_os_error()); } @@ -217,11 +217,11 @@ pub fn current_exe() -> io::Result<PathBuf> { libc::KERN_PROC_ARGV]; let mib = mib.as_mut_ptr(); let mut argv_len = 0; - try!(cvt(libc::sysctl(mib, 4, 0 as *mut _, &mut argv_len, - 0 as *mut _, 0))); + cvt(libc::sysctl(mib, 4, 0 as *mut _, &mut argv_len, + 0 as *mut _, 0))?; let mut argv = Vec::<*const libc::c_char>::with_capacity(argv_len as usize); - try!(cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, - &mut argv_len, 0 as *mut _, 0))); + cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, + &mut argv_len, 0 as *mut _, 0))?; argv.set_len(argv_len as usize); if argv[0].is_null() { return Err(io::Error::new(io::ErrorKind::Other, @@ -460,7 +460,7 @@ pub fn env() -> Env { pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { // environment variables with a nul byte can't be set, so their value is // always None as well - let k = try!(CString::new(k.as_bytes())); + let k = CString::new(k.as_bytes())?; let _g = ENV_LOCK.lock(); Ok(unsafe { let s = libc::getenv(k.as_ptr()) as *const _; @@ -473,8 +473,8 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { } pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { - let k = try!(CString::new(k.as_bytes())); - let v = try!(CString::new(v.as_bytes())); + let k = CString::new(k.as_bytes())?; + let v = CString::new(v.as_bytes())?; let _g = ENV_LOCK.lock(); cvt(unsafe { libc::setenv(k.as_ptr(), v.as_ptr(), 1) @@ -482,7 +482,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { } pub fn unsetenv(n: &OsStr) -> io::Result<()> { - let nbuf = try!(CString::new(n.as_bytes())); + let nbuf = CString::new(n.as_bytes())?; let _g = ENV_LOCK.lock(); cvt(unsafe { libc::unsetenv(nbuf.as_ptr()) diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index e5cb3761001..beca2d46753 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -87,13 +87,13 @@ pub fn read2(p1: AnonPipe, let max = cmp::max(p1.raw(), p2.raw()); loop { // wait for either pipe to become readable using `select` - try!(cvt_r(|| unsafe { + cvt_r(|| unsafe { let mut read: libc::fd_set = mem::zeroed(); libc::FD_SET(p1.raw(), &mut read); libc::FD_SET(p2.raw(), &mut read); libc::select(max + 1, &mut read, 0 as *mut _, 0 as *mut _, 0 as *mut _) - })); + })?; // Read as much as we can from each pipe, ignoring EWOULDBLOCK or // EAGAIN. If we hit EOF, then this will happen because the underlying @@ -113,11 +113,11 @@ pub fn read2(p1: AnonPipe, } } }; - if try!(read(&p1, v1)) { + if read(&p1, v1)? { p2.set_nonblocking(false); return p2.read_to_end(v2).map(|_| ()); } - if try!(read(&p2, v2)) { + if read(&p2, v2)? { p1.set_nonblocking(false); return p1.read_to_end(v1).map(|_| ()); } diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 47b0ff42f93..83f76c1cbc5 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -225,11 +225,11 @@ impl Command { "nul byte found in provided data")); } - let (ours, theirs) = try!(self.setup_io(default, needs_stdin)); - let (input, output) = try!(sys::pipe::anon_pipe()); + let (ours, theirs) = self.setup_io(default, needs_stdin)?; + let (input, output) = sys::pipe::anon_pipe()?; let pid = unsafe { - match try!(cvt(libc::fork())) { + match cvt(libc::fork())? { 0 => { drop(input); let err = self.do_exec(theirs); @@ -343,17 +343,17 @@ impl Command { } if let Some(fd) = stdio.stdin.fd() { - try!(cvt_r(|| libc::dup2(fd, libc::STDIN_FILENO))); + cvt_r(|| libc::dup2(fd, libc::STDIN_FILENO))?; } if let Some(fd) = stdio.stdout.fd() { - try!(cvt_r(|| libc::dup2(fd, libc::STDOUT_FILENO))); + cvt_r(|| libc::dup2(fd, libc::STDOUT_FILENO))?; } if let Some(fd) = stdio.stderr.fd() { - try!(cvt_r(|| libc::dup2(fd, libc::STDERR_FILENO))); + cvt_r(|| libc::dup2(fd, libc::STDERR_FILENO))?; } if let Some(u) = self.gid { - try!(cvt(libc::setgid(u as gid_t))); + cvt(libc::setgid(u as gid_t))?; } if let Some(u) = self.uid { // When dropping privileges from root, the `setgroups` call @@ -365,7 +365,7 @@ impl Command { // privilege dropping function. let _ = libc::setgroups(0, ptr::null()); - try!(cvt(libc::setuid(u as uid_t))); + cvt(libc::setuid(u as uid_t))?; } if self.session_leader { // Don't check the error of setsid because it fails if we're the @@ -374,7 +374,7 @@ impl Command { let _ = libc::setsid(); } if let Some(ref cwd) = self.cwd { - try!(cvt(libc::chdir(cwd.as_ptr()))); + cvt(libc::chdir(cwd.as_ptr()))?; } if let Some(ref envp) = self.envp { *sys::os::environ() = envp.as_ptr(); @@ -390,9 +390,9 @@ impl Command { // need to clean things up now to avoid confusing the program // we're about to run. let mut set: libc::sigset_t = mem::uninitialized(); - try!(cvt(libc::sigemptyset(&mut set))); - try!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, - ptr::null_mut()))); + cvt(libc::sigemptyset(&mut set))?; + cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, + ptr::null_mut()))?; let ret = libc::signal(libc::SIGPIPE, libc::SIG_DFL); if ret == libc::SIG_ERR { return io::Error::last_os_error() @@ -400,7 +400,7 @@ impl Command { } for callback in self.closures.iter_mut() { - try!(callback()); + callback()?; } libc::execvp(self.argv[0], self.argv.as_ptr()); @@ -415,9 +415,9 @@ impl Command { let stdin = self.stdin.as_ref().unwrap_or(default_stdin); let stdout = self.stdout.as_ref().unwrap_or(&default); let stderr = self.stderr.as_ref().unwrap_or(&default); - let (their_stdin, our_stdin) = try!(stdin.to_child_stdio(true)); - let (their_stdout, our_stdout) = try!(stdout.to_child_stdio(false)); - let (their_stderr, our_stderr) = try!(stderr.to_child_stdio(false)); + let (their_stdin, our_stdin) = stdin.to_child_stdio(true)?; + let (their_stdout, our_stdout) = stdout.to_child_stdio(false)?; + let (their_stderr, our_stderr) = stderr.to_child_stdio(false)?; let ours = StdioPipes { stdin: our_stdin, stdout: our_stdout, @@ -454,14 +454,14 @@ impl Stdio { // overwritten prematurely. Stdio::Fd(ref fd) => { if fd.raw() >= 0 && fd.raw() <= libc::STDERR_FILENO { - Ok((ChildStdio::Owned(try!(fd.duplicate())), None)) + Ok((ChildStdio::Owned(fd.duplicate()?), None)) } else { Ok((ChildStdio::Explicit(fd.raw()), None)) } } Stdio::MakePipe => { - let (reader, writer) = try!(pipe::anon_pipe()); + let (reader, writer) = pipe::anon_pipe()?; let (ours, theirs) = if readable { (writer, reader) } else { @@ -477,7 +477,7 @@ impl Stdio { let path = unsafe { CStr::from_ptr("/dev/null\0".as_ptr() as *const _) }; - let fd = try!(File::open_c(&path, &opts)); + let fd = File::open_c(&path, &opts)?; Ok((ChildStdio::Owned(fd.into_fd()), None)) } } @@ -508,9 +508,9 @@ fn pair_to_key(key: &OsStr, value: &OsStr, saw_nul: &mut bool) -> CString { impl fmt::Debug for Command { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "{:?}", self.program)); + write!(f, "{:?}", self.program)?; for arg in &self.args { - try!(write!(f, " {:?}", arg)); + write!(f, " {:?}", arg)?; } Ok(()) } @@ -589,7 +589,7 @@ impl Process { return Ok(status) } let mut status = 0 as c_int; - try!(cvt_r(|| unsafe { libc::waitpid(self.pid, &mut status, 0) })); + cvt_r(|| unsafe { libc::waitpid(self.pid, &mut status, 0) })?; self.status = Some(ExitStatus(status)); Ok(ExitStatus(status)) } diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index fa504ade084..92c3bf8829a 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -138,7 +138,7 @@ mod imp { return Ok(OsRng { inner: OsGetrandomRng }); } - let reader = try!(File::open("/dev/urandom")); + let reader = File::open("/dev/urandom")?; let reader_rng = ReaderRng::new(reader); Ok(OsRng { inner: OsReaderRng(reader_rng) }) diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index 3cc3a631b89..0e10a8d8e8d 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -131,7 +131,7 @@ pub fn write(w: &mut Write) -> io::Result<()> { // Start from -1 to avoid printing this stack frame, which will // always be exactly the same. let mut i = -1; - try!(write!(w, "stack backtrace:\n")); + write!(w, "stack backtrace:\n")?; while StackWalk64(image, process, thread, &mut frame, &mut context, ptr::null_mut(), ptr::null_mut(), @@ -144,7 +144,7 @@ pub fn write(w: &mut Write) -> io::Result<()> { i += 1; if i >= 0 { - try!(printing::print(w, i, addr - 1, process, &dbghelp)); + printing::print(w, i, addr - 1, process, &dbghelp)?; } } diff --git a/src/libstd/sys/windows/dynamic_lib.rs b/src/libstd/sys/windows/dynamic_lib.rs index 84cfbe5e721..dde13ec8364 100644 --- a/src/libstd/sys/windows/dynamic_lib.rs +++ b/src/libstd/sys/windows/dynamic_lib.rs @@ -36,7 +36,7 @@ impl DynamicLibrary { } pub fn symbol(&self, symbol: &str) -> io::Result<usize> { - let symbol = try!(CString::new(symbol)); + let symbol = CString::new(symbol)?; unsafe { match c::GetProcAddress(self.handle, symbol.as_ptr()) as usize { 0 => Err(io::Error::last_os_error()), diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 624fef097fc..46397e14718 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -248,13 +248,13 @@ impl OpenOptions { impl File { pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> { - let path = try!(to_u16s(path)); + let path = to_u16s(path)?; let handle = unsafe { c::CreateFileW(path.as_ptr(), - try!(opts.get_access_mode()), + opts.get_access_mode()?, opts.share_mode, opts.security_attributes as *mut _, - try!(opts.get_creation_mode()), + opts.get_creation_mode()?, opts.get_flags_and_attributes(), ptr::null_mut()) }; @@ -266,7 +266,7 @@ impl File { } pub fn fsync(&self) -> io::Result<()> { - try!(cvt(unsafe { c::FlushFileBuffers(self.handle.raw()) })); + cvt(unsafe { c::FlushFileBuffers(self.handle.raw()) })?; Ok(()) } @@ -277,20 +277,20 @@ impl File { EndOfFile: size as c::LARGE_INTEGER, }; let size = mem::size_of_val(&info); - try!(cvt(unsafe { + cvt(unsafe { c::SetFileInformationByHandle(self.handle.raw(), c::FileEndOfFileInfo, &mut info as *mut _ as *mut _, size as c::DWORD) - })); + })?; Ok(()) } pub fn file_attr(&self) -> io::Result<FileAttr> { unsafe { let mut info: c::BY_HANDLE_FILE_INFORMATION = mem::zeroed(); - try!(cvt(c::GetFileInformationByHandle(self.handle.raw(), - &mut info))); + cvt(c::GetFileInformationByHandle(self.handle.raw(), + &mut info))?; let mut attr = FileAttr { attributes: info.dwFileAttributes, creation_time: info.ftCreationTime, @@ -331,16 +331,16 @@ impl File { }; let pos = pos as c::LARGE_INTEGER; let mut newpos = 0; - try!(cvt(unsafe { + cvt(unsafe { c::SetFilePointerEx(self.handle.raw(), pos, &mut newpos, whence) - })); + })?; Ok(newpos as u64) } pub fn duplicate(&self) -> io::Result<File> { Ok(File { - handle: try!(self.handle.duplicate(0, true, c::DUPLICATE_SAME_ACCESS)), + handle: self.handle.duplicate(0, true, c::DUPLICATE_SAME_ACCESS)?, }) } @@ -353,7 +353,7 @@ impl File { -> io::Result<(c::DWORD, &'a c::REPARSE_DATA_BUFFER)> { unsafe { let mut bytes = 0; - try!(cvt({ + cvt({ c::DeviceIoControl(self.handle.raw(), c::FSCTL_GET_REPARSE_POINT, ptr::null_mut(), @@ -362,14 +362,14 @@ impl File { space.len() as c::DWORD, &mut bytes, ptr::null_mut()) - })); + })?; Ok((bytes, &*(space.as_ptr() as *const c::REPARSE_DATA_BUFFER))) } } fn readlink(&self) -> io::Result<PathBuf> { let mut space = [0u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; - let (_bytes, buf) = try!(self.reparse_point(&mut space)); + let (_bytes, buf) = self.reparse_point(&mut space)?; unsafe { let (path_buffer, subst_off, subst_len, relative) = match buf.ReparseTag { c::IO_REPARSE_TAG_SYMLINK => { @@ -516,10 +516,10 @@ impl DirBuilder { pub fn new() -> DirBuilder { DirBuilder } pub fn mkdir(&self, p: &Path) -> io::Result<()> { - let p = try!(to_u16s(p)); - try!(cvt(unsafe { + let p = to_u16s(p)?; + cvt(unsafe { c::CreateDirectoryW(p.as_ptr(), ptr::null_mut()) - })); + })?; Ok(()) } } @@ -527,7 +527,7 @@ impl DirBuilder { pub fn readdir(p: &Path) -> io::Result<ReadDir> { let root = p.to_path_buf(); let star = p.join("*"); - let path = try!(to_u16s(&star)); + let path = to_u16s(&star)?; unsafe { let mut wfd = mem::zeroed(); @@ -545,28 +545,28 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> { } pub fn unlink(p: &Path) -> io::Result<()> { - let p_u16s = try!(to_u16s(p)); - try!(cvt(unsafe { c::DeleteFileW(p_u16s.as_ptr()) })); + let p_u16s = to_u16s(p)?; + cvt(unsafe { c::DeleteFileW(p_u16s.as_ptr()) })?; Ok(()) } pub fn rename(old: &Path, new: &Path) -> io::Result<()> { - let old = try!(to_u16s(old)); - let new = try!(to_u16s(new)); - try!(cvt(unsafe { + let old = to_u16s(old)?; + let new = to_u16s(new)?; + cvt(unsafe { c::MoveFileExW(old.as_ptr(), new.as_ptr(), c::MOVEFILE_REPLACE_EXISTING) - })); + })?; Ok(()) } pub fn rmdir(p: &Path) -> io::Result<()> { - let p = try!(to_u16s(p)); - try!(cvt(unsafe { c::RemoveDirectoryW(p.as_ptr()) })); + let p = to_u16s(p)?; + cvt(unsafe { c::RemoveDirectoryW(p.as_ptr()) })?; Ok(()) } pub fn remove_dir_all(path: &Path) -> io::Result<()> { - let filetype = try!(lstat(path)).file_type(); + let filetype = lstat(path)?.file_type(); if filetype.is_symlink() { // On Windows symlinks to files and directories are removed differently. // rmdir only deletes dir symlinks and junctions, not file symlinks. @@ -577,15 +577,15 @@ pub fn remove_dir_all(path: &Path) -> io::Result<()> { } fn remove_dir_all_recursive(path: &Path) -> io::Result<()> { - for child in try!(readdir(path)) { - let child = try!(child); - let child_type = try!(child.file_type()); + for child in readdir(path)? { + let child = child?; + let child_type = child.file_type()?; if child_type.is_dir() { - try!(remove_dir_all_recursive(&child.path())); + remove_dir_all_recursive(&child.path())?; } else if child_type.is_symlink_dir() { - try!(rmdir(&child.path())); + rmdir(&child.path())?; } else { - try!(unlink(&child.path())); + unlink(&child.path())?; } } rmdir(path) @@ -599,7 +599,7 @@ pub fn readlink(path: &Path) -> io::Result<PathBuf> { opts.access_mode(0); opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT | c::FILE_FLAG_BACKUP_SEMANTICS); - let file = try!(File::open(&path, &opts)); + let file = File::open(&path, &opts)?; file.readlink() } @@ -608,21 +608,21 @@ pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { } pub fn symlink_inner(src: &Path, dst: &Path, dir: bool) -> io::Result<()> { - let src = try!(to_u16s(src)); - let dst = try!(to_u16s(dst)); + let src = to_u16s(src)?; + let dst = to_u16s(dst)?; let flags = if dir { c::SYMBOLIC_LINK_FLAG_DIRECTORY } else { 0 }; - try!(cvt(unsafe { + cvt(unsafe { c::CreateSymbolicLinkW(dst.as_ptr(), src.as_ptr(), flags) as c::BOOL - })); + })?; Ok(()) } pub fn link(src: &Path, dst: &Path) -> io::Result<()> { - let src = try!(to_u16s(src)); - let dst = try!(to_u16s(dst)); - try!(cvt(unsafe { + let src = to_u16s(src)?; + let dst = to_u16s(dst)?; + cvt(unsafe { c::CreateHardLinkW(dst.as_ptr(), src.as_ptr(), ptr::null_mut()) - })); + })?; Ok(()) } @@ -632,7 +632,7 @@ pub fn stat(path: &Path) -> io::Result<FileAttr> { opts.access_mode(0); // This flag is so we can open directories too opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS); - let file = try!(File::open(path, &opts)); + let file = File::open(path, &opts)?; file.file_attr() } @@ -641,14 +641,14 @@ pub fn lstat(path: &Path) -> io::Result<FileAttr> { // No read or write permissions are necessary opts.access_mode(0); opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS | c::FILE_FLAG_OPEN_REPARSE_POINT); - let file = try!(File::open(path, &opts)); + let file = File::open(path, &opts)?; file.file_attr() } pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> { - let p = try!(to_u16s(p)); + let p = to_u16s(p)?; unsafe { - try!(cvt(c::SetFileAttributesW(p.as_ptr(), perm.attrs))); + cvt(c::SetFileAttributesW(p.as_ptr(), perm.attrs))?; Ok(()) } } @@ -668,7 +668,7 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> { opts.access_mode(0); // This flag is so we can open directories too opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS); - let f = try!(File::open(p, &opts)); + let f = File::open(p, &opts)?; get_path(&f) } @@ -687,13 +687,13 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { *(lpData as *mut i64) = TotalBytesTransferred; c::PROGRESS_CONTINUE } - let pfrom = try!(to_u16s(from)); - let pto = try!(to_u16s(to)); + let pfrom = to_u16s(from)?; + let pto = to_u16s(to)?; let mut size = 0i64; - try!(cvt(unsafe { + cvt(unsafe { c::CopyFileExW(pfrom.as_ptr(), pto.as_ptr(), Some(callback), &mut size as *mut _ as *mut _, ptr::null_mut(), 0) - })); + })?; Ok(size as u64) } @@ -710,13 +710,13 @@ pub fn symlink_junction<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::R #[allow(dead_code)] fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> { let d = DirBuilder::new(); - try!(d.mkdir(&junction)); + d.mkdir(&junction)?; let mut opts = OpenOptions::new(); opts.write(true); opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT | c::FILE_FLAG_BACKUP_SEMANTICS); - let f = try!(File::open(junction, &opts)); + let f = File::open(junction, &opts)?; let h = f.handle().raw(); unsafe { diff --git a/src/libstd/sys/windows/handle.rs b/src/libstd/sys/windows/handle.rs index 1396d670902..74546bb893b 100644 --- a/src/libstd/sys/windows/handle.rs +++ b/src/libstd/sys/windows/handle.rs @@ -169,22 +169,22 @@ impl RawHandle { // WriteFile takes a DWORD (u32) for the length so it only supports // writing u32::MAX bytes at a time. let len = cmp::min(buf.len(), u32::MAX as usize) as c::DWORD; - try!(cvt(unsafe { + cvt(unsafe { c::WriteFile(self.0, buf.as_ptr() as c::LPVOID, len, &mut amt, ptr::null_mut()) - })); + })?; Ok(amt as usize) } pub fn duplicate(&self, access: c::DWORD, inherit: bool, options: c::DWORD) -> io::Result<Handle> { let mut ret = 0 as c::HANDLE; - try!(cvt(unsafe { + cvt(unsafe { let cur_proc = c::GetCurrentProcess(); c::DuplicateHandle(cur_proc, self.0, cur_proc, &mut ret, access, inherit as c::BOOL, options) - })); + })?; Ok(Handle::new(ret)) } } diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index 3a2f06418cf..ab2d969fe0a 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -92,35 +92,35 @@ impl Socket { SocketAddr::V4(..) => c::AF_INET, SocketAddr::V6(..) => c::AF_INET6, }; - let socket = try!(unsafe { + let socket = unsafe { match c::WSASocketW(fam, ty, 0, ptr::null_mut(), 0, c::WSA_FLAG_OVERLAPPED) { c::INVALID_SOCKET => Err(last_error()), n => Ok(Socket(n)), } - }); - try!(socket.set_no_inherit()); + }?; + socket.set_no_inherit()?; Ok(socket) } pub fn accept(&self, storage: *mut c::SOCKADDR, len: *mut c_int) -> io::Result<Socket> { - let socket = try!(unsafe { + let socket = unsafe { match c::accept(self.0, storage, len) { c::INVALID_SOCKET => Err(last_error()), n => Ok(Socket(n)), } - }); - try!(socket.set_no_inherit()); + }?; + socket.set_no_inherit()?; Ok(socket) } pub fn duplicate(&self) -> io::Result<Socket> { - let socket = try!(unsafe { + let socket = unsafe { let mut info: c::WSAPROTOCOL_INFO = mem::zeroed(); - try!(cvt(c::WSADuplicateSocketW(self.0, + cvt(c::WSADuplicateSocketW(self.0, c::GetCurrentProcessId(), - &mut info))); + &mut info))?; match c::WSASocketW(info.iAddressFamily, info.iSocketType, info.iProtocol, @@ -129,8 +129,8 @@ impl Socket { c::INVALID_SOCKET => Err(last_error()), n => Ok(Socket(n)), } - }); - try!(socket.set_no_inherit()); + }?; + socket.set_no_inherit()?; Ok(socket) } @@ -169,7 +169,7 @@ impl Socket { } pub fn timeout(&self, kind: c_int) -> io::Result<Option<Duration>> { - let raw: c::DWORD = try!(net::getsockopt(self, c::SOL_SOCKET, kind)); + let raw: c::DWORD = net::getsockopt(self, c::SOL_SOCKET, kind)?; if raw == 0 { Ok(None) } else { @@ -192,7 +192,7 @@ impl Socket { Shutdown::Read => c::SD_RECEIVE, Shutdown::Both => c::SD_BOTH, }; - try!(cvt(unsafe { c::shutdown(self.0, how) })); + cvt(unsafe { c::shutdown(self.0, how) })?; Ok(()) } @@ -211,12 +211,12 @@ impl Socket { } pub fn nodelay(&self) -> io::Result<bool> { - let raw: c::BYTE = try!(net::getsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY)); + let raw: c::BYTE = net::getsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY)?; Ok(raw != 0) } pub fn take_error(&self) -> io::Result<Option<io::Error>> { - let raw: c_int = try!(net::getsockopt(self, c::SOL_SOCKET, c::SO_ERROR)); + let raw: c_int = net::getsockopt(self, c::SOL_SOCKET, c::SO_ERROR)?; if raw == 0 { Ok(None) } else { diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 688475a7565..32ca32e76cb 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -239,7 +239,7 @@ pub fn chdir(p: &path::Path) -> io::Result<()> { } pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { - let k = try!(to_u16s(k)); + let k = to_u16s(k)?; let res = super::fill_utf16_buf(|buf, sz| unsafe { c::GetEnvironmentVariableW(k.as_ptr(), buf, sz) }, |buf| { @@ -258,8 +258,8 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { } pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { - let k = try!(to_u16s(k)); - let v = try!(to_u16s(v)); + let k = to_u16s(k)?; + let v = to_u16s(v)?; cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) @@ -267,7 +267,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { } pub fn unsetenv(n: &OsStr) -> io::Result<()> { - let v = try!(to_u16s(n)); + let v = to_u16s(n)?; cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(|_| ()) diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs index fbe38d76e95..8631a63d653 100644 --- a/src/libstd/sys/windows/pipe.rs +++ b/src/libstd/sys/windows/pipe.rs @@ -95,7 +95,7 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> { opts.read(false); opts.share_mode(0); opts.attributes(c::FILE_FLAG_OVERLAPPED); - let writer = try!(File::open(Path::new(&name), &opts)); + let writer = File::open(Path::new(&name), &opts)?; let writer = AnonPipe { inner: writer.into_handle() }; Ok((AnonPipe { inner: reader }, AnonPipe { inner: writer.into_handle() })) @@ -126,8 +126,8 @@ pub fn read2(p1: AnonPipe, let p1 = p1.into_handle(); let p2 = p2.into_handle(); - let mut p1 = try!(AsyncPipe::new(p1, v1)); - let mut p2 = try!(AsyncPipe::new(p2, v2)); + let mut p1 = AsyncPipe::new(p1, v1)?; + let mut p2 = AsyncPipe::new(p2, v2)?; let objs = [p1.event.raw(), p2.event.raw()]; // In a loop we wait for either pipe's scheduled read operation to complete. @@ -143,11 +143,11 @@ pub fn read2(p1: AnonPipe, c::WaitForMultipleObjects(2, objs.as_ptr(), c::FALSE, c::INFINITE) }; if res == c::WAIT_OBJECT_0 { - if !try!(p1.result()) || !try!(p1.schedule_read()) { + if !p1.result()? || !p1.schedule_read()? { return p2.finish() } } else if res == c::WAIT_OBJECT_0 + 1 { - if !try!(p2.result()) || !try!(p2.schedule_read()) { + if !p2.result()? || !p2.schedule_read()? { return p1.finish() } } else { @@ -183,7 +183,7 @@ impl<'a> AsyncPipe<'a> { // WaitForMultipleObjects call above for pipes created initially, // and the only time an even will go back to "unset" will be once an // I/O operation is successfully scheduled (what we want). - let event = try!(Handle::new_event(true, true)); + let event = Handle::new_event(true, true)?; let mut overlapped: Box<c::OVERLAPPED> = unsafe { Box::new(mem::zeroed()) }; @@ -207,7 +207,7 @@ impl<'a> AsyncPipe<'a> { assert_eq!(self.state, State::NotReading); let amt = unsafe { let slice = slice_to_end(self.dst); - try!(self.pipe.read_overlapped(slice, &mut *self.overlapped)) + self.pipe.read_overlapped(slice, &mut *self.overlapped)? }; // If this read finished immediately then our overlapped event will @@ -240,7 +240,7 @@ impl<'a> AsyncPipe<'a> { let amt = match self.state { State::NotReading => return Ok(true), State::Reading => { - try!(self.pipe.overlapped_result(&mut *self.overlapped, true)) + self.pipe.overlapped_result(&mut *self.overlapped, true)? } State::Read(amt) => amt, }; @@ -257,7 +257,7 @@ impl<'a> AsyncPipe<'a> { /// Waits for any pending and schedule read, and then calls `read_to_end` /// if necessary to read all the remaining information. fn finish(&mut self) -> io::Result<()> { - while try!(self.result()) && try!(self.schedule_read()) { + while self.result()? && self.schedule_read()? { // ... } Ok(()) diff --git a/src/libstd/sys/windows/printing/msvc.rs b/src/libstd/sys/windows/printing/msvc.rs index 37aaa1f1b0e..9c29ac4082a 100644 --- a/src/libstd/sys/windows/printing/msvc.rs +++ b/src/libstd/sys/windows/printing/msvc.rs @@ -53,7 +53,7 @@ pub fn print(w: &mut Write, None }; - try!(output(w, i, addr as usize as *mut c_void, name)); + output(w, i, addr as usize as *mut c_void, name)?; // Now find out the filename and line number let mut line: c::IMAGEHLP_LINE64 = mem::zeroed(); diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 524c932eed4..f479b36ebbd 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -151,7 +151,7 @@ impl Command { si.dwFlags = c::STARTF_USESTDHANDLES; let program = program.as_ref().unwrap_or(&self.program); - let mut cmd_str = try!(make_command_line(program, &self.args)); + let mut cmd_str = make_command_line(program, &self.args)?; cmd_str.push(0); // add null terminator // stolen from the libuv code. @@ -160,8 +160,8 @@ impl Command { flags |= c::DETACHED_PROCESS | c::CREATE_NEW_PROCESS_GROUP; } - let (envp, _data) = try!(make_envp(self.env.as_ref())); - let (dirp, _data) = try!(make_dirp(self.cwd.as_ref())); + let (envp, _data) = make_envp(self.env.as_ref())?; + let (dirp, _data) = make_dirp(self.cwd.as_ref())?; let mut pi = zeroed_process_information(); // Prepare all stdio handles to be inherited by the child. This @@ -186,23 +186,23 @@ impl Command { let stdin = self.stdin.as_ref().unwrap_or(default_stdin); let stdout = self.stdout.as_ref().unwrap_or(&default); let stderr = self.stderr.as_ref().unwrap_or(&default); - let stdin = try!(stdin.to_handle(c::STD_INPUT_HANDLE, &mut pipes.stdin)); - let stdout = try!(stdout.to_handle(c::STD_OUTPUT_HANDLE, - &mut pipes.stdout)); - let stderr = try!(stderr.to_handle(c::STD_ERROR_HANDLE, - &mut pipes.stderr)); + let stdin = stdin.to_handle(c::STD_INPUT_HANDLE, &mut pipes.stdin)?; + let stdout = stdout.to_handle(c::STD_OUTPUT_HANDLE, + &mut pipes.stdout)?; + let stderr = stderr.to_handle(c::STD_ERROR_HANDLE, + &mut pipes.stderr)?; si.hStdInput = stdin.raw(); si.hStdOutput = stdout.raw(); si.hStdError = stderr.raw(); - try!(unsafe { + unsafe { cvt(c::CreateProcessW(ptr::null(), cmd_str.as_mut_ptr(), ptr::null_mut(), ptr::null_mut(), c::TRUE, flags, envp, dirp, &mut si, &mut pi)) - }); + }?; // We close the thread handle because we don't care about keeping // the thread id valid, and we aren't keeping the thread handle @@ -216,9 +216,9 @@ impl Command { impl fmt::Debug for Command { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "{:?}", self.program)); + write!(f, "{:?}", self.program)?; for arg in &self.args { - try!(write!(f, " {:?}", arg)); + write!(f, " {:?}", arg)?; } Ok(()) } @@ -240,18 +240,18 @@ impl Stdio { } Stdio::MakePipe => { - let (reader, writer) = try!(pipe::anon_pipe()); + let (reader, writer) = pipe::anon_pipe()?; let (ours, theirs) = if stdio_id == c::STD_INPUT_HANDLE { (writer, reader) } else { (reader, writer) }; *pipe = Some(ours); - try!(cvt(unsafe { + cvt(unsafe { c::SetHandleInformation(theirs.handle().raw(), c::HANDLE_FLAG_INHERIT, c::HANDLE_FLAG_INHERIT) - })); + })?; Ok(theirs.into_handle()) } @@ -296,9 +296,9 @@ pub struct Process { impl Process { pub fn kill(&mut self) -> io::Result<()> { - try!(cvt(unsafe { + cvt(unsafe { c::TerminateProcess(self.handle.raw(), 1) - })); + })?; Ok(()) } @@ -315,7 +315,7 @@ impl Process { return Err(Error::last_os_error()) } let mut status = 0; - try!(cvt(c::GetExitCodeProcess(self.handle.raw(), &mut status))); + cvt(c::GetExitCodeProcess(self.handle.raw(), &mut status))?; Ok(ExitStatus(status)) } } @@ -381,10 +381,10 @@ fn make_command_line(prog: &OsStr, args: &[OsString]) -> io::Result<Vec<u16>> { // Encode the command and arguments in a command line string such // that the spawned process may recover them using CommandLineToArgvW. let mut cmd: Vec<u16> = Vec::new(); - try!(append_arg(&mut cmd, prog)); + append_arg(&mut cmd, prog)?; for arg in args { cmd.push(' ' as u16); - try!(append_arg(&mut cmd, arg)); + append_arg(&mut cmd, arg)?; } return Ok(cmd); @@ -392,7 +392,7 @@ fn make_command_line(prog: &OsStr, args: &[OsString]) -> io::Result<Vec<u16>> { // If an argument has 0 characters then we need to quote it to ensure // that it actually gets passed through on the command line or otherwise // it will be dropped entirely when parsed on the other end. - try!(ensure_no_nuls(arg)); + ensure_no_nuls(arg)?; let arg_bytes = &arg.as_inner().inner.as_inner(); let quote = arg_bytes.iter().any(|c| *c == b' ' || *c == b'\t') || arg_bytes.is_empty(); @@ -438,9 +438,9 @@ fn make_envp(env: Option<&collections::HashMap<OsString, OsString>>) let mut blk = Vec::new(); for pair in env { - blk.extend(try!(ensure_no_nuls(pair.0)).encode_wide()); + blk.extend(ensure_no_nuls(pair.0)?.encode_wide()); blk.push('=' as u16); - blk.extend(try!(ensure_no_nuls(pair.1)).encode_wide()); + blk.extend(ensure_no_nuls(pair.1)?.encode_wide()); blk.push(0); } blk.push(0); @@ -454,7 +454,7 @@ fn make_dirp(d: Option<&OsString>) -> io::Result<(*const u16, Vec<u16>)> { match d { Some(dir) => { - let mut dir_str: Vec<u16> = try!(ensure_no_nuls(dir)).encode_wide().collect(); + let mut dir_str: Vec<u16> = ensure_no_nuls(dir)?.encode_wide().collect(); dir_str.push(0); Ok((dir_str.as_ptr(), dir_str)) }, diff --git a/src/libstd/sys/windows/stdio.rs b/src/libstd/sys/windows/stdio.rs index 0a0851ffac3..fa3cab2191e 100644 --- a/src/libstd/sys/windows/stdio.rs +++ b/src/libstd/sys/windows/stdio.rs @@ -78,13 +78,13 @@ fn write(out: &Output, data: &[u8]) -> io::Result<usize> { }; let utf16 = utf8.encode_utf16().collect::<Vec<u16>>(); let mut written = 0; - try!(cvt(unsafe { + cvt(unsafe { c::WriteConsoleW(handle, utf16.as_ptr() as c::LPCVOID, utf16.len() as u32, &mut written, ptr::null_mut()) - })); + })?; // FIXME if this only partially writes the utf16 buffer then we need to // figure out how many bytes of `data` were actually written @@ -112,13 +112,13 @@ impl Stdin { if utf8.position() as usize == utf8.get_ref().len() { let mut utf16 = vec![0u16; 0x1000]; let mut num = 0; - try!(cvt(unsafe { + cvt(unsafe { c::ReadConsoleW(handle, utf16.as_mut_ptr() as c::LPVOID, utf16.len() as u32, &mut num, ptr::null_mut()) - })); + })?; utf16.truncate(num as usize); // FIXME: what to do about this data that has already been read? let data = match String::from_utf16(&utf16) { |
