message: Move error up, early return
diff: @@ -871,7 +871,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
  let entry_ptr = this.force_ptr(this.read_scalar(entry_op)?.not_undef()?)?;
  let dirent64_layout = this.libc_ty_layout("dirent64")?;
  - if let Some(dir_iter) = this.machine.dir_handler.streams.get_mut(&dirp) {
  + let dir_iter = this.machine.dir_handler.streams.get_mut(&dirp).ok_or_else(|| {
  + err_unsup_format!("The DIR pointer passed to readdir64_r did not come from opendir")
  + })?;
  match dir_iter.next() {
  Some(Ok(dir_entry)) => {
  // Write into entry, write pointer to result, return 0 on success.
  @@ -881,7 +883,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
  let name_offset = dirent64_layout.details.fields.offset(4);
  let name_ptr = entry_ptr.offset(name_offset, this)?;
  - let name_fits = this.write_os_str_to_c_str(&dir_entry.file_name(), Scalar::Ptr(name_ptr), 256)?;
  + let file_name = dir_entry.file_name();
  + let name_fits = this.write_os_str_to_c_str(&file_name, Scalar::Ptr(name_ptr), 256)?;
  if !name_fits {
  panic!("A directory entry had a name too large to fit in libc::dirent64");
  }
  @@ -920,11 +923,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
  Some(Err(e)) => match e.raw_os_error() {
  // return positive error number on error
  Some(error) => Ok(error),
  - None => throw_unsup_format!("The error {} couldn't be converted to a return value", e),
  - }
  + None => {
  + throw_unsup_format!("The error {} couldn't be converted to a return value", e)
  }
  - } else {
  - throw_unsup_format!("The DIR pointer passed to readdir64_r did not come from opendir")
  + },
  }
  }
  @@ -943,7 +945,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
  let entry_ptr = this.force_ptr(this.read_scalar(entry_op)?.not_undef()?)?;
  let dirent_layout = this.libc_ty_layout("dirent")?;
  - if let Some(dir_iter) = this.machine.dir_handler.streams.get_mut(&dirp) {
  + let dir_iter = this.machine.dir_handler.streams.get_mut(&dirp).ok_or_else(|| {
  + err_unsup_format!("The DIR pointer passed to readdir_r did not come from opendir")
  + })?;
  match dir_iter.next() {
  Some(Ok(dir_entry)) => {
  // Write into entry, write pointer to result, return 0 on success.
  @@ -996,11 +1000,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
  Some(Err(e)) => match e.raw_os_error() {
  // return positive error number on error
  Some(error) => Ok(error),
  - None => throw_unsup_format!("The error {} couldn't be converted to a return value", e),
  - }
  + None => {
  + throw_unsup_format!("The error {} couldn't be converted to a return value", e)
  }
  - } else {
  - throw_unsup_format!("The DIR pointer passed to readdir_r did not come from opendir")
  + },
  }
  }
  