Add context to i/o errors
diff --git a/gen/build/src/error.rs b/gen/build/src/error.rs
index c8eafa5..e1bfff2 100644
--- a/gen/build/src/error.rs
+++ b/gen/build/src/error.rs
@@ -1,6 +1,6 @@
+use crate::gen::fs;
use std::error::Error as StdError;
use std::fmt::{self, Display};
-use std::io;
pub(super) type Result<T, E = Error> = std::result::Result<T, E>;
@@ -8,7 +8,7 @@
pub(super) enum Error {
MissingOutDir,
TargetDir,
- Io(io::Error),
+ Fs(fs::Error),
}
impl Display for Error {
@@ -16,7 +16,7 @@
match self {
Error::MissingOutDir => write!(f, "missing OUT_DIR environment variable"),
Error::TargetDir => write!(f, "failed to locate target dir"),
- Error::Io(err) => err.fmt(f),
+ Error::Fs(err) => err.fmt(f),
}
}
}
@@ -24,14 +24,14 @@
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
- Error::Io(err) => err.source(),
+ Error::Fs(err) => err.source(),
_ => None,
}
}
}
-impl From<io::Error> for Error {
- fn from(err: io::Error) -> Self {
- Error::Io(err)
+impl From<fs::Error> for Error {
+ fn from(err: fs::Error) -> Self {
+ Error::Fs(err)
}
}
diff --git a/gen/build/src/lib.rs b/gen/build/src/lib.rs
index 840424e..8f48f20 100644
--- a/gen/build/src/lib.rs
+++ b/gen/build/src/lib.rs
@@ -59,8 +59,7 @@
use crate::error::Result;
use crate::gen::error::report;
-use crate::gen::Opt;
-use std::fs;
+use crate::gen::{fs, Opt};
use std::io::{self, Write};
use std::iter;
use std::path::Path;
diff --git a/gen/build/src/paths.rs b/gen/build/src/paths.rs
index ca183d9..7c572ec 100644
--- a/gen/build/src/paths.rs
+++ b/gen/build/src/paths.rs
@@ -1,6 +1,6 @@
use crate::error::{Error, Result};
+use crate::gen::fs;
use std::env;
-use std::fs;
use std::path::{Path, PathBuf};
fn out_dir() -> Result<PathBuf> {
@@ -94,23 +94,21 @@
// unable to handle in includes. Use a poor approximation instead.
// https://github.com/rust-lang/rust/issues/42869
// https://github.com/alexcrichton/cc-rs/issues/169
- Ok(env::current_dir()?.join(path))
+ Ok(fs::current_dir()?.join(path))
}
#[cfg(unix)]
-use std::os::unix::fs::symlink as symlink_or_copy;
+use self::fs::symlink as symlink_or_copy;
#[cfg(windows)]
fn symlink_or_copy(src: &Path, dst: &Path) -> Result<()> {
- use std::os::windows::fs::symlink_file;
-
// Pre-Windows 10, symlinks require admin privileges. Since Windows 10, they
// require Developer Mode. If it fails, fall back to copying the file.
- if symlink_file(src, dst).is_err() {
+ if fs::symlink_file(src, dst).is_err() {
fs::copy(src, dst)?;
}
Ok(())
}
#[cfg(not(any(unix, windows)))]
-use std::fs::copy as symlink_or_copy;
+use self::fs::copy as symlink_or_copy;