Skip to content

Commit 5458b65

Browse files
committed
use exhaustive_patterns to be able to use ?
1 parent af6ace6 commit 5458b65

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/libstd/sys/redox/process.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl Command {
150150
match cvt(syscall::clone(0))? {
151151
0 => {
152152
drop(input);
153-
let err = self.do_exec(theirs);
153+
let Err(err) = self.do_exec(theirs);
154154
let errno = err.raw_os_error().unwrap_or(syscall::EINVAL) as u32;
155155
let bytes = [
156156
(errno >> 24) as u8,
@@ -218,7 +218,10 @@ impl Command {
218218
}
219219

220220
match self.setup_io(default, true) {
221-
Ok((_, theirs)) => unsafe { self.do_exec(theirs) },
221+
Ok((_, theirs)) => unsafe {
222+
let Err(e) = self.do_exec(theirs);
223+
e
224+
},
222225
Err(e) => e,
223226
}
224227
}
@@ -253,7 +256,7 @@ impl Command {
253256
// allocation). Instead we just close it manually. This will never
254257
// have the drop glue anyway because this code never returns (the
255258
// child will either exec() or invoke syscall::exit)
256-
unsafe fn do_exec(&mut self, stdio: ChildPipes) -> io::Error {
259+
unsafe fn do_exec(&mut self, stdio: ChildPipes) -> Result<!, io::Error> {
257260
if let Some(fd) = stdio.stderr.fd() {
258261
cvt(syscall::dup2(fd, 2, &[]))?;
259262
let mut flags = cvt(syscall::fcntl(2, syscall::F_GETFD, 0))?;
@@ -308,7 +311,7 @@ impl Command {
308311
let mut file = if let Some(program) = program {
309312
File::open(program.as_os_str())?
310313
} else {
311-
return io::Error::from_raw_os_error(syscall::ENOENT);
314+
return Err(io::Error::from_raw_os_error(syscall::ENOENT));
312315
};
313316

314317
// Push all the arguments
@@ -343,7 +346,7 @@ impl Command {
343346
meta.mode() & 0o7
344347
};
345348
if mode & 1 == 0 {
346-
return io::Error::from_raw_os_error(syscall::EPERM);
349+
return Err(io::Error::from_raw_os_error(syscall::EPERM));
347350
}
348351

349352
// Second of all, we need to actually read which interpreter it wants
@@ -389,13 +392,12 @@ impl Command {
389392
}
390393

391394
if let Err(err) = syscall::fexec(file.as_raw_fd(), &args, &vars) {
392-
io::Error::from_raw_os_error(err.errno as i32)
395+
Err(io::Error::from_raw_os_error(err.errno as i32))
393396
} else {
394397
panic!("return from exec without err");
395398
}
396399
}
397400

398-
399401
fn setup_io(&self, default: Stdio, needs_stdin: bool)
400402
-> io::Result<(StdioPipes, ChildPipes)> {
401403
let null = Stdio::Null;

src/libstd/sys/unix/process/process_unix.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Command {
4747
match result {
4848
0 => {
4949
drop(input);
50-
let err = self.do_exec(theirs, envp.as_ref());
50+
let Err(err) = self.do_exec(theirs, envp.as_ref());
5151
let errno = err.raw_os_error().unwrap_or(libc::EINVAL) as u32;
5252
let bytes = [
5353
(errno >> 24) as u8,
@@ -123,7 +123,8 @@ impl Command {
123123
// environment lock before we try to exec.
124124
let _lock = sys::os::env_lock();
125125

126-
self.do_exec(theirs, envp.as_ref())
126+
let Err(e) = self.do_exec(theirs, envp.as_ref());
127+
e
127128
}
128129
}
129130
Err(e) => e,
@@ -164,7 +165,7 @@ impl Command {
164165
&mut self,
165166
stdio: ChildPipes,
166167
maybe_envp: Option<&CStringArray>
167-
) -> io::Error {
168+
) -> Result<!, io::Error> {
168169
use crate::sys::{self, cvt_r};
169170

170171
if let Some(fd) = stdio.stdin.fd() {
@@ -224,7 +225,7 @@ impl Command {
224225
ptr::null_mut()))?;
225226
let ret = sys::signal(libc::SIGPIPE, libc::SIG_DFL);
226227
if ret == libc::SIG_ERR {
227-
return io::Error::last_os_error()
228+
return Err(io::Error::last_os_error())
228229
}
229230
}
230231

@@ -254,7 +255,7 @@ impl Command {
254255
}
255256

256257
libc::execvp(self.get_argv()[0], self.get_argv().as_ptr());
257-
io::Error::last_os_error()
258+
Err(io::Error::last_os_error())
258259
}
259260

260261
#[cfg(not(any(target_os = "macos", target_os = "freebsd",

0 commit comments

Comments
 (0)