]> git.lizzy.rs Git - rust.git/commitdiff
panic if target platform is incorrect instead
authorChristian Poveda <git@christianpoveda.xyz>
Sat, 22 Feb 2020 14:02:25 +0000 (09:02 -0500)
committerChristian Poveda <git@christianpoveda.xyz>
Sat, 22 Feb 2020 14:02:29 +0000 (09:02 -0500)
src/helpers.rs
src/shims/fs.rs

index 2ce4ca6c91dc2da8e48df3000f1d77b52447d319..2ae6910fce2dcd31c2f5fd2de0807228700ce044 100644 (file)
@@ -368,18 +368,17 @@ fn check_no_isolation(&mut self, name: &str) -> InterpResult<'tcx> {
         }
         Ok(())
     }
-    /// Helper function used inside the shims of foreign functions to check that the target
-    /// platform is `platform`. It returns an error using the `name` of the foreign function if
-    /// this is not the case.
-    fn check_platform(&mut self, platform: &str, name: &str) -> InterpResult<'tcx> {
-        if self.eval_context_mut().tcx.sess.target.target.target_os.to_lowercase() != platform {
-            throw_unsup_format!(
-                "`{}` is only available on the `{}` platform",
-                name,
-                platform,
-            )
-        }
-        Ok(())
+    /// Helper function used inside the shims of foreign functions to assert that the target
+    /// platform is `platform`. It panics showing a message with the `name` of the foreign function
+    /// if this is not the case.
+    fn assert_platform(&mut self, platform: &str, name: &str) {
+        assert_eq!(
+            self.eval_context_mut().tcx.sess.target.target.target_os.to_lowercase(),
+            platform,
+            "`{}` is only available on the `{}` platform",
+            name,
+            platform
+        )
     }
 
     /// Sets the last error variable.
index b3d8d6a0ac7ffe645e2e4436ec6a6fbc48dc5606..f846c339defe04c7d0920c13335e0a407f649aee 100644 (file)
@@ -347,7 +347,7 @@ fn macos_stat(
     ) -> InterpResult<'tcx, i32> {
         let this = self.eval_context_mut();
         this.check_no_isolation("stat")?;
-        this.check_platform("macos", "stat")?;
+        this.assert_platform("macos", "stat");
         // `stat` always follows symlinks.
         this.macos_stat_or_lstat(true, path_op, buf_op)
     }
@@ -360,7 +360,7 @@ fn macos_lstat(
     ) -> InterpResult<'tcx, i32> {
         let this = self.eval_context_mut();
         this.check_no_isolation("lstat")?;
-        this.check_platform("macos", "lstat")?;
+        this.assert_platform("macos", "lstat");
         this.macos_stat_or_lstat(false, path_op, buf_op)
     }
 
@@ -372,7 +372,7 @@ fn macos_fstat(
         let this = self.eval_context_mut();
 
         this.check_no_isolation("fstat")?;
-        this.check_platform("macos", "fstat")?;
+        this.assert_platform("macos", "fstat");
 
         let fd = this.read_scalar(fd_op)?.to_i32()?;
 
@@ -416,7 +416,7 @@ fn linux_statx(
         let this = self.eval_context_mut();
 
         this.check_no_isolation("statx")?;
-        this.check_platform("linux", "statx")?;
+        this.assert_platform("linux", "statx");
 
         let statxbuf_scalar = this.read_scalar(statxbuf_op)?.not_undef()?;
         let pathname_scalar = this.read_scalar(pathname_op)?.not_undef()?;