Skip to content

Commit 2086658

Browse files
committed
panic if target platform is incorrect instead
1 parent c2bcab5 commit 2086658

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/helpers.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
368368
}
369369
Ok(())
370370
}
371-
/// Helper function used inside the shims of foreign functions to check that the target
372-
/// platform is `platform`. It returns an error using the `name` of the foreign function if
373-
/// this is not the case.
374-
fn check_platform(&mut self, platform: &str, name: &str) -> InterpResult<'tcx> {
375-
if self.eval_context_mut().tcx.sess.target.target.target_os.to_lowercase() != platform {
376-
throw_unsup_format!(
377-
"`{}` is only available on the `{}` platform",
378-
name,
379-
platform,
380-
)
381-
}
382-
Ok(())
371+
/// Helper function used inside the shims of foreign functions to assert that the target
372+
/// platform is `platform`. It panics showing a message with the `name` of the foreign function
373+
/// if this is not the case.
374+
fn assert_platform(&mut self, platform: &str, name: &str) {
375+
assert_eq!(
376+
self.eval_context_mut().tcx.sess.target.target.target_os.to_lowercase(),
377+
platform,
378+
"`{}` is only available on the `{}` platform",
379+
name,
380+
platform
381+
)
383382
}
384383

385384
/// Sets the last error variable.

src/shims/fs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
347347
) -> InterpResult<'tcx, i32> {
348348
let this = self.eval_context_mut();
349349
this.check_no_isolation("stat")?;
350-
this.check_platform("macos", "stat")?;
350+
this.assert_platform("macos", "stat");
351351
// `stat` always follows symlinks.
352352
this.macos_stat_or_lstat(true, path_op, buf_op)
353353
}
@@ -360,7 +360,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
360360
) -> InterpResult<'tcx, i32> {
361361
let this = self.eval_context_mut();
362362
this.check_no_isolation("lstat")?;
363-
this.check_platform("macos", "lstat")?;
363+
this.assert_platform("macos", "lstat");
364364
this.macos_stat_or_lstat(false, path_op, buf_op)
365365
}
366366

@@ -372,7 +372,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
372372
let this = self.eval_context_mut();
373373

374374
this.check_no_isolation("fstat")?;
375-
this.check_platform("macos", "fstat")?;
375+
this.assert_platform("macos", "fstat");
376376

377377
let fd = this.read_scalar(fd_op)?.to_i32()?;
378378

@@ -416,7 +416,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
416416
let this = self.eval_context_mut();
417417

418418
this.check_no_isolation("statx")?;
419-
this.check_platform("linux", "statx")?;
419+
this.assert_platform("linux", "statx");
420420

421421
let statxbuf_scalar = this.read_scalar(statxbuf_op)?.not_undef()?;
422422
let pathname_scalar = this.read_scalar(pathname_op)?.not_undef()?;

0 commit comments

Comments
 (0)