Skip to content

Commit 3baa49d

Browse files
committed
update errors
1 parent f155d6d commit 3baa49d

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

check_diff/src/lib.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::io;
33
use std::path::{Path, PathBuf};
44
use std::process::{Command, Output};
55
use std::str::Utf8Error;
6-
use std::string::FromUtf8Error;
76
use tracing::info;
87

98
pub enum CheckDiffError {
@@ -34,9 +33,9 @@ impl From<GitError> for CheckDiffError {
3433
}
3534
}
3635

37-
impl From<FromUtf8Error> for CheckDiffError {
38-
fn from(error: FromUtf8Error) -> Self {
39-
CheckDiffError::FailedUtf8(error.utf8_error())
36+
impl From<Utf8Error> for CheckDiffError {
37+
fn from(error: Utf8Error) -> Self {
38+
CheckDiffError::FailedUtf8(error)
4039
}
4140
}
4241

@@ -87,8 +86,7 @@ impl RustfmtRunner {
8786
));
8887
};
8988

90-
let binding = String::from_utf8(command.stdout)?;
91-
let binary_version = binding.trim();
89+
let binary_version = std::str::from_utf8(&command.stdout)?.trim_end();
9290
return Ok(binary_version.to_string());
9391
}
9492
}
@@ -196,7 +194,7 @@ pub fn get_ld_lib_path() -> Result<String, CheckDiffError> {
196194
return Err(CheckDiffError::FailedCommand("Error getting sysroot"));
197195
};
198196

199-
let sysroot = String::from_utf8(command.stdout)?;
197+
let sysroot = std::str::from_utf8(&command.stdout)?.trim_end();
200198

201199
let ld_lib_path = format!("{}/lib", sysroot.trim_end());
202200
return Ok(ld_lib_path);
@@ -209,9 +207,8 @@ pub fn get_cargo_version() -> Result<String, CheckDiffError> {
209207
));
210208
};
211209

212-
let cargo_version = String::from_utf8(command.stdout)?;
213-
214-
return Ok(cargo_version);
210+
let cargo_version = std::str::from_utf8(&command.stdout)?.trim_end();
211+
return Ok(cargo_version.to_string());
215212
}
216213

217214
/// Obtains the ld_lib path and then builds rustfmt from source

0 commit comments

Comments
 (0)