Fix parameter of io error helper function
`set_last_error_from_io_error` works with only the error kind, and discards the payload. Fix its signature to make it explicit.
This commit is contained in:
parent
892f706ce5
commit
ba64f485c8
@ -460,15 +460,15 @@ fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
|
||||
this.read_scalar(&errno_place.into())?.check_init()
|
||||
}
|
||||
|
||||
/// Sets the last OS error using a `std::io::Error`. This function tries to produce the most
|
||||
/// Sets the last OS error using a `std::io::ErrorKind`. This function tries to produce the most
|
||||
/// similar OS error from the `std::io::ErrorKind` and sets it as the last OS error.
|
||||
fn set_last_error_from_io_error(&mut self, e: std::io::Error) -> InterpResult<'tcx> {
|
||||
fn set_last_error_from_io_error(&mut self, err_kind: std::io::ErrorKind) -> InterpResult<'tcx> {
|
||||
use std::io::ErrorKind::*;
|
||||
let this = self.eval_context_mut();
|
||||
let target = &this.tcx.sess.target;
|
||||
let target_os = &target.os;
|
||||
let last_error = if target.families.contains(&"unix".to_owned()) {
|
||||
this.eval_libc(match e.kind() {
|
||||
this.eval_libc(match err_kind {
|
||||
ConnectionRefused => "ECONNREFUSED",
|
||||
ConnectionReset => "ECONNRESET",
|
||||
PermissionDenied => "EPERM",
|
||||
@ -484,18 +484,21 @@ fn set_last_error_from_io_error(&mut self, e: std::io::Error) -> InterpResult<'t
|
||||
AlreadyExists => "EEXIST",
|
||||
WouldBlock => "EWOULDBLOCK",
|
||||
_ => {
|
||||
throw_unsup_format!("io error {} cannot be transformed into a raw os error", e)
|
||||
throw_unsup_format!(
|
||||
"io error {:?} cannot be transformed into a raw os error",
|
||||
err_kind
|
||||
)
|
||||
}
|
||||
})?
|
||||
} else if target.families.contains(&"windows".to_owned()) {
|
||||
// FIXME: we have to finish implementing the Windows equivalent of this.
|
||||
this.eval_windows(
|
||||
"c",
|
||||
match e.kind() {
|
||||
match err_kind {
|
||||
NotFound => "ERROR_FILE_NOT_FOUND",
|
||||
_ => throw_unsup_format!(
|
||||
"io error {} cannot be transformed into a raw os error",
|
||||
e
|
||||
"io error {:?} cannot be transformed into a raw os error",
|
||||
err_kind
|
||||
),
|
||||
},
|
||||
)?
|
||||
@ -521,7 +524,7 @@ fn try_unwrap_io_result<T: From<i32>>(
|
||||
match result {
|
||||
Ok(ok) => Ok(ok),
|
||||
Err(e) => {
|
||||
self.eval_context_mut().set_last_error_from_io_error(e)?;
|
||||
self.eval_context_mut().set_last_error_from_io_error(e.kind())?;
|
||||
Ok((-1).into())
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::env;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::io::ErrorKind;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_mir::interpret::Pointer;
|
||||
@ -324,8 +324,7 @@ fn getcwd(
|
||||
|
||||
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
|
||||
this.reject_in_isolation("getcwd", reject_with)?;
|
||||
let err = Error::new(ErrorKind::NotFound, "rejected due to isolation");
|
||||
this.set_last_error_from_io_error(err)?;
|
||||
this.set_last_error_from_io_error(ErrorKind::NotFound)?;
|
||||
return Ok(Scalar::null_ptr(&*this.tcx));
|
||||
}
|
||||
|
||||
@ -340,7 +339,7 @@ fn getcwd(
|
||||
let erange = this.eval_libc("ERANGE")?;
|
||||
this.set_last_error(erange)?;
|
||||
}
|
||||
Err(e) => this.set_last_error_from_io_error(e)?,
|
||||
Err(e) => this.set_last_error_from_io_error(e.kind())?,
|
||||
}
|
||||
|
||||
Ok(Scalar::null_ptr(&*this.tcx))
|
||||
@ -357,8 +356,7 @@ fn GetCurrentDirectoryW(
|
||||
|
||||
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
|
||||
this.reject_in_isolation("GetCurrentDirectoryW", reject_with)?;
|
||||
let err = Error::new(ErrorKind::NotFound, "rejected due to isolation");
|
||||
this.set_last_error_from_io_error(err)?;
|
||||
this.set_last_error_from_io_error(ErrorKind::NotFound)?;
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
@ -369,7 +367,7 @@ fn GetCurrentDirectoryW(
|
||||
match env::current_dir() {
|
||||
Ok(cwd) =>
|
||||
return Ok(windows_check_buffer_size(this.write_path_to_wide_str(&cwd, buf, size)?)),
|
||||
Err(e) => this.set_last_error_from_io_error(e)?,
|
||||
Err(e) => this.set_last_error_from_io_error(e.kind())?,
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
@ -384,8 +382,7 @@ fn chdir(&mut self, path_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
|
||||
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
|
||||
this.reject_in_isolation("chdir", reject_with)?;
|
||||
let err = Error::new(ErrorKind::NotFound, "rejected due to isolation");
|
||||
this.set_last_error_from_io_error(err)?;
|
||||
this.set_last_error_from_io_error(ErrorKind::NotFound)?;
|
||||
|
||||
return Ok(-1);
|
||||
}
|
||||
@ -395,7 +392,7 @@ fn chdir(&mut self, path_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
match env::set_current_dir(path) {
|
||||
Ok(()) => Ok(0),
|
||||
Err(e) => {
|
||||
this.set_last_error_from_io_error(e)?;
|
||||
this.set_last_error_from_io_error(e.kind())?;
|
||||
Ok(-1)
|
||||
}
|
||||
}
|
||||
@ -413,8 +410,7 @@ fn SetCurrentDirectoryW(
|
||||
|
||||
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
|
||||
this.reject_in_isolation("SetCurrentDirectoryW", reject_with)?;
|
||||
let err = Error::new(ErrorKind::NotFound, "rejected due to isolation");
|
||||
this.set_last_error_from_io_error(err)?;
|
||||
this.set_last_error_from_io_error(ErrorKind::NotFound)?;
|
||||
|
||||
return Ok(0);
|
||||
}
|
||||
@ -424,7 +420,7 @@ fn SetCurrentDirectoryW(
|
||||
match env::set_current_dir(path) {
|
||||
Ok(()) => Ok(1),
|
||||
Err(e) => {
|
||||
this.set_last_error_from_io_error(e)?;
|
||||
this.set_last_error_from_io_error(e.kind())?;
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
@ -634,7 +634,7 @@ fn fcntl(&mut self, args: &[OpTy<'tcx, Tag>]) -> InterpResult<'tcx, i32> {
|
||||
match dup_result {
|
||||
Ok(dup_fd) => Ok(fh.insert_fd_with_min_fd(dup_fd, start)),
|
||||
Err(e) => {
|
||||
this.set_last_error_from_io_error(e)?;
|
||||
this.set_last_error_from_io_error(e.kind())?;
|
||||
Ok(-1)
|
||||
}
|
||||
}
|
||||
@ -707,7 +707,7 @@ fn read(&mut self, fd: i32, buf: Scalar<Tag>, count: u64) -> InterpResult<'tcx,
|
||||
Ok(read_bytes)
|
||||
}
|
||||
Err(e) => {
|
||||
this.set_last_error_from_io_error(e)?;
|
||||
this.set_last_error_from_io_error(e.kind())?;
|
||||
Ok(-1)
|
||||
}
|
||||
}
|
||||
@ -1118,7 +1118,7 @@ fn opendir(&mut self, name_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, Scalar<Ta
|
||||
Ok(Scalar::from_machine_usize(id, this))
|
||||
}
|
||||
Err(e) => {
|
||||
this.set_last_error_from_io_error(e)?;
|
||||
this.set_last_error_from_io_error(e.kind())?;
|
||||
Ok(Scalar::null_ptr(this))
|
||||
}
|
||||
}
|
||||
@ -1462,7 +1462,7 @@ fn readlink(
|
||||
Ok(path_bytes.len().try_into().unwrap())
|
||||
}
|
||||
Err(e) => {
|
||||
this.set_last_error_from_io_error(e)?;
|
||||
this.set_last_error_from_io_error(e.kind())?;
|
||||
Ok(-1)
|
||||
}
|
||||
}
|
||||
@ -1526,7 +1526,7 @@ fn from_meta<'tcx, 'mir>(
|
||||
let metadata = match metadata {
|
||||
Ok(metadata) => metadata,
|
||||
Err(e) => {
|
||||
ecx.set_last_error_from_io_error(e)?;
|
||||
ecx.set_last_error_from_io_error(e.kind())?;
|
||||
return Ok(None);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user