From 3baa49de7a5f4a6702f40c1e6ee11f9c7fff8aa9 Mon Sep 17 00:00:00 2001 From: benluiwj Date: Sun, 29 Sep 2024 12:12:16 +0800 Subject: [PATCH] update errors --- check_diff/src/lib.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/check_diff/src/lib.rs b/check_diff/src/lib.rs index 3782d393f60..d33481a5574 100644 --- a/check_diff/src/lib.rs +++ b/check_diff/src/lib.rs @@ -3,7 +3,6 @@ use std::io; use std::path::{Path, PathBuf}; use std::process::{Command, Output}; use std::str::Utf8Error; -use std::string::FromUtf8Error; use tracing::info; pub enum CheckDiffError { @@ -34,9 +33,9 @@ impl From for CheckDiffError { } } -impl From for CheckDiffError { - fn from(error: FromUtf8Error) -> Self { - CheckDiffError::FailedUtf8(error.utf8_error()) +impl From for CheckDiffError { + fn from(error: Utf8Error) -> Self { + CheckDiffError::FailedUtf8(error) } } @@ -87,8 +86,7 @@ impl RustfmtRunner { )); }; - let binding = String::from_utf8(command.stdout)?; - let binary_version = binding.trim(); + let binary_version = std::str::from_utf8(&command.stdout)?.trim_end(); return Ok(binary_version.to_string()); } } @@ -196,7 +194,7 @@ pub fn get_ld_lib_path() -> Result { return Err(CheckDiffError::FailedCommand("Error getting sysroot")); }; - let sysroot = String::from_utf8(command.stdout)?; + let sysroot = std::str::from_utf8(&command.stdout)?.trim_end(); let ld_lib_path = format!("{}/lib", sysroot.trim_end()); return Ok(ld_lib_path); @@ -209,9 +207,8 @@ pub fn get_cargo_version() -> Result { )); }; - let cargo_version = String::from_utf8(command.stdout)?; - - return Ok(cargo_version); + let cargo_version = std::str::from_utf8(&command.stdout)?.trim_end(); + return Ok(cargo_version.to_string()); } /// Obtains the ld_lib path and then builds rustfmt from source