From d12d4f760c09a75b6c4ea12dd180a1bfb92aba38 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Tue, 10 Aug 2021 16:50:42 +0200 Subject: [PATCH] uucore: {USimpleError, UUsageError}::new take Into instead of String --- src/uu/chown/src/chown.rs | 2 +- src/uu/dirname/src/dirname.rs | 2 +- src/uu/id/src/id.rs | 8 ++++---- src/uu/sort/src/sort.rs | 4 ++-- src/uucore/src/lib/mods/error.rs | 14 +++++++------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index 4a9da3f77..3d882a564 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -109,7 +109,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if derefer == 1 { return Err(USimpleError::new( 1, - "-R --dereference requires -H or -L".to_string(), + "-R --dereference requires -H or -L", )); } derefer = 0; diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 63ee57272..e7dcc2195 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -79,7 +79,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { print!("{}", separator); } } else { - return Err(UUsageError::new(1, "missing operand".to_string())); + return Err(UUsageError::new(1, "missing operand")); } Ok(()) diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 1dd1b176d..b067be42c 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -173,20 +173,20 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if (state.nflag || state.rflag) && default_format && !state.cflag { return Err(USimpleError::new( 1, - "cannot print only names or real IDs in default format".to_string(), + "cannot print only names or real IDs in default format", )); } if state.zflag && default_format && !state.cflag { // NOTE: GNU test suite "id/zero.sh" needs this stderr output: return Err(USimpleError::new( 1, - "option --zero not permitted in default format".to_string(), + "option --zero not permitted in default format", )); } if state.user_specified && state.cflag { return Err(USimpleError::new( 1, - "cannot print security context when user specified".to_string(), + "cannot print security context when user specified", )); } @@ -220,7 +220,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } else { return Err(USimpleError::new( 1, - "--context (-Z) works only on an SELinux-enabled kernel".to_string(), + "--context (-Z) works only on an SELinux-enabled kernel", )); } } diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 3eebe7c4a..e0b445782 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1238,7 +1238,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if separator.len() != 1 { return Err(UUsageError::new( 2, - "separator must be exactly one character long".into(), + "separator must be exactly one character long", )); } settings.separator = Some(separator.chars().next().unwrap()) @@ -1517,7 +1517,7 @@ fn exec( file_merger.write_all(settings, output) } else if settings.check { if files.len() > 1 { - Err(UUsageError::new(2, "only one file allowed with -c".into())) + Err(UUsageError::new(2, "only one file allowed with -c")) } else { check::check(files.first().unwrap(), settings) } diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index fbeea4ed2..caccb6ac0 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -268,7 +268,7 @@ where /// let err = USimpleError { code: 1, message: "error!".into()}; /// let res: UResult<()> = Err(err.into()); /// // or using the `new` method: -/// let res: UResult<()> = Err(USimpleError::new(1, "error!".into())); +/// let res: UResult<()> = Err(USimpleError::new(1, "error!")); /// ``` #[derive(Debug)] pub struct USimpleError { @@ -278,8 +278,8 @@ pub struct USimpleError { impl USimpleError { #[allow(clippy::new_ret_no_self)] - pub fn new(code: i32, message: String) -> Box { - Box::new(Self { code, message }) + pub fn new>(code: i32, message: S) -> Box { + Box::new(Self { code, message: message.into() }) } } @@ -305,8 +305,8 @@ pub struct UUsageError { impl UUsageError { #[allow(clippy::new_ret_no_self)] - pub fn new(code: i32, message: String) -> Box { - Box::new(Self { code, message }) + pub fn new>(code: i32, message: S) -> Box { + Box::new(Self { code, message: message.into() }) } } @@ -359,9 +359,9 @@ pub struct UIoError { impl UIoError { #[allow(clippy::new_ret_no_self)] - pub fn new(kind: std::io::ErrorKind, context: String) -> Box { + pub fn new>(kind: std::io::ErrorKind, context: S) -> Box { Box::new(Self { - context, + context: context.into(), inner: std::io::Error::new(kind, ""), }) }