Skip to content

Commit 8756a2f

Browse files
committed
Minor code formatting
1 parent 9551713 commit 8756a2f

File tree

2 files changed

+46
-44
lines changed

2 files changed

+46
-44
lines changed

src/bin/miri.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ fn main() {
294294
miri_config.check_abi = false;
295295
}
296296
"-Zmiri-disable-isolation" => {
297-
if let Some(true) = isolation_enabled {
297+
if matches!(isolation_enabled, Some(true) ) {
298298
panic!(
299299
"-Zmiri-disable-isolation cannot be used along with -Zmiri-isolation-error"
300300
);
@@ -304,7 +304,7 @@ fn main() {
304304
miri_config.isolated_op = miri::IsolatedOp::Allow;
305305
}
306306
arg if arg.starts_with("-Zmiri-isolation-error=") => {
307-
if let Some(false) = isolation_enabled {
307+
if matches!(isolation_enabled, Some(false)) {
308308
panic!(
309309
"-Zmiri-isolation-error cannot be used along with -Zmiri-disable-isolation"
310310
);

src/shims/env.rs

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -326,20 +326,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
326326
this.reject_in_isolation("getcwd", reject_with)?;
327327
let err = Error::new(ErrorKind::NotFound, "rejected due to isolation");
328328
this.set_last_error_from_io_error(err)?;
329-
} else {
330-
let buf = this.read_scalar(&buf_op)?.check_init()?;
331-
let size = this.read_scalar(&size_op)?.to_machine_usize(&*this.tcx)?;
332-
// If we cannot get the current directory, we return null
333-
match env::current_dir() {
334-
Ok(cwd) => {
335-
if this.write_path_to_c_str(&cwd, buf, size)?.0 {
336-
return Ok(buf);
337-
}
338-
let erange = this.eval_libc("ERANGE")?;
339-
this.set_last_error(erange)?;
329+
return Ok(Scalar::null_ptr(&*this.tcx));
330+
}
331+
332+
let buf = this.read_scalar(&buf_op)?.check_init()?;
333+
let size = this.read_scalar(&size_op)?.to_machine_usize(&*this.tcx)?;
334+
// If we cannot get the current directory, we return null
335+
match env::current_dir() {
336+
Ok(cwd) => {
337+
if this.write_path_to_c_str(&cwd, buf, size)?.0 {
338+
return Ok(buf);
340339
}
341-
Err(e) => this.set_last_error_from_io_error(e)?,
340+
let erange = this.eval_libc("ERANGE")?;
341+
this.set_last_error(erange)?;
342342
}
343+
Err(e) => this.set_last_error_from_io_error(e)?,
343344
}
344345

345346
Ok(Scalar::null_ptr(&*this.tcx))
@@ -358,18 +359,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
358359
this.reject_in_isolation("GetCurrentDirectoryW", reject_with)?;
359360
let err = Error::new(ErrorKind::NotFound, "rejected due to isolation");
360361
this.set_last_error_from_io_error(err)?;
361-
} else {
362-
let size = u64::from(this.read_scalar(size_op)?.to_u32()?);
363-
let buf = this.read_scalar(buf_op)?.check_init()?;
364-
365-
// If we cannot get the current directory, we return 0
366-
match env::current_dir() {
367-
Ok(cwd) =>
368-
return Ok(windows_check_buffer_size(
369-
this.write_path_to_wide_str(&cwd, buf, size)?,
370-
)),
371-
Err(e) => this.set_last_error_from_io_error(e)?,
372-
}
362+
return Ok(0);
363+
}
364+
365+
let size = u64::from(this.read_scalar(size_op)?.to_u32()?);
366+
let buf = this.read_scalar(buf_op)?.check_init()?;
367+
368+
// If we cannot get the current directory, we return 0
369+
match env::current_dir() {
370+
Ok(cwd) =>
371+
return Ok(windows_check_buffer_size(
372+
this.write_path_to_wide_str(&cwd, buf, size)?,
373+
)),
374+
Err(e) => this.set_last_error_from_io_error(e)?,
373375
}
374376
Ok(0)
375377
}
@@ -387,16 +389,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
387389
let err = Error::new(ErrorKind::NotFound, "rejected due to isolation");
388390
this.set_last_error_from_io_error(err)?;
389391

390-
Ok(-1)
391-
} else {
392-
let path = this.read_path_from_c_str(this.read_scalar(path_op)?.check_init()?)?;
392+
return Ok(-1);
393+
}
393394

394-
match env::set_current_dir(path) {
395-
Ok(()) => Ok(0),
396-
Err(e) => {
397-
this.set_last_error_from_io_error(e)?;
398-
Ok(-1)
399-
}
395+
let path = this.read_path_from_c_str(this.read_scalar(path_op)?.check_init()?)?;
396+
397+
match env::set_current_dir(path) {
398+
Ok(()) => Ok(0),
399+
Err(e) => {
400+
this.set_last_error_from_io_error(e)?;
401+
Ok(-1)
400402
}
401403
}
402404
}
@@ -416,16 +418,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
416418
let err = Error::new(ErrorKind::NotFound, "rejected due to isolation");
417419
this.set_last_error_from_io_error(err)?;
418420

419-
Ok(0)
420-
} else {
421-
let path = this.read_path_from_wide_str(this.read_scalar(path_op)?.check_init()?)?;
421+
return Ok(0);
422+
}
422423

423-
match env::set_current_dir(path) {
424-
Ok(()) => Ok(1),
425-
Err(e) => {
426-
this.set_last_error_from_io_error(e)?;
427-
Ok(0)
428-
}
424+
let path = this.read_path_from_wide_str(this.read_scalar(path_op)?.check_init()?)?;
425+
426+
match env::set_current_dir(path) {
427+
Ok(()) => Ok(1),
428+
Err(e) => {
429+
this.set_last_error_from_io_error(e)?;
430+
Ok(0)
429431
}
430432
}
431433
}

0 commit comments

Comments
 (0)