From 04ebd863a630f523385c0ce8f967cff62b515e56 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 8 Feb 2024 16:40:31 +0100 Subject: [PATCH] clippy: fix warnings introduced by Rust 1.76 --- src/uu/nohup/src/nohup.rs | 8 +------- src/uu/od/src/mockstream.rs | 2 +- src/uu/pr/src/pr.rs | 27 +++++++++++++++------------ tests/by-util/test_cat.rs | 2 -- tests/common/util.rs | 2 -- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 74dfa71c5..486518342 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -148,7 +148,6 @@ fn find_stdout() -> UResult { }; match OpenOptions::new() - .write(true) .create(true) .append(true) .open(Path::new(NOHUP_OUT)) @@ -168,12 +167,7 @@ fn find_stdout() -> UResult { let mut homeout = PathBuf::from(home); homeout.push(NOHUP_OUT); let homeout_str = homeout.to_str().unwrap(); - match OpenOptions::new() - .write(true) - .create(true) - .append(true) - .open(&homeout) - { + match OpenOptions::new().create(true).append(true).open(&homeout) { Ok(t) => { show_error!( "ignoring input and appending output to {}", diff --git a/src/uu/od/src/mockstream.rs b/src/uu/od/src/mockstream.rs index 925d52f7e..9904fa9c1 100644 --- a/src/uu/od/src/mockstream.rs +++ b/src/uu/od/src/mockstream.rs @@ -10,7 +10,7 @@ use std::io::{Cursor, Error, ErrorKind, Read, Result}; /// /// # Examples /// -/// ``` +/// ```no_run /// use std::io::{Cursor, Read}; /// /// struct CountIo {} diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index ef178a888..e6e573e0f 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -577,18 +577,19 @@ fn build_options( // +page option is less priority than --pages let page_plus_re = Regex::new(r"\s*\+(\d+:*\d*)\s*").unwrap(); - let start_page_in_plus_option = match page_plus_re.captures(free_args).map(|i| { + let res = page_plus_re.captures(free_args).map(|i| { let unparsed_num = i.get(1).unwrap().as_str().trim(); let x: Vec<_> = unparsed_num.split(':').collect(); x[0].to_string().parse::().map_err(|_e| { PrError::EncounteredErrors(format!("invalid {} argument {}", "+", unparsed_num.quote())) }) - }) { + }); + let start_page_in_plus_option = match res { Some(res) => res?, None => 1, }; - let end_page_in_plus_option = match page_plus_re + let res = page_plus_re .captures(free_args) .map(|i| i.get(1).unwrap().as_str().trim()) .filter(|i| i.contains(':')) @@ -601,7 +602,8 @@ fn build_options( unparsed_num.quote() )) }) - }) { + }); + let end_page_in_plus_option = match res { Some(res) => Some(res?), None => None, }; @@ -616,27 +618,27 @@ fn build_options( }) }; - let start_page = match matches + let res = matches .get_one::(options::PAGES) .map(|i| { let x: Vec<_> = i.split(':').collect(); x[0].to_string() }) - .map(invalid_pages_map) - { + .map(invalid_pages_map); + let start_page = match res { Some(res) => res?, None => start_page_in_plus_option, }; - let end_page = match matches + let res = matches .get_one::(options::PAGES) .filter(|i| i.contains(':')) .map(|i| { let x: Vec<_> = i.split(':').collect(); x[1].to_string() }) - .map(invalid_pages_map) - { + .map(invalid_pages_map); + let end_page = match res { Some(res) => Some(res?), None => end_page_in_plus_option, }; @@ -707,12 +709,13 @@ fn build_options( let re_col = Regex::new(r"\s*-(\d+)\s*").unwrap(); - let start_column_option = match re_col.captures(free_args).map(|i| { + let res = re_col.captures(free_args).map(|i| { let unparsed_num = i.get(1).unwrap().as_str().trim(); unparsed_num.parse::().map_err(|_e| { PrError::EncounteredErrors(format!("invalid {} argument {}", "-", unparsed_num.quote())) }) - }) { + }); + let start_column_option = match res { Some(res) => Some(res?), None => None, }; diff --git a/tests/by-util/test_cat.rs b/tests/by-util/test_cat.rs index aa86ab066..560709f29 100644 --- a/tests/by-util/test_cat.rs +++ b/tests/by-util/test_cat.rs @@ -503,7 +503,6 @@ fn test_write_to_self_empty() { let file = OpenOptions::new() .create_new(true) - .write(true) .append(true) .open(&file_path) .unwrap(); @@ -519,7 +518,6 @@ fn test_write_to_self() { let file = OpenOptions::new() .create_new(true) - .write(true) .append(true) .open(file_path) .unwrap(); diff --git a/tests/common/util.rs b/tests/common/util.rs index 9055c238e..e35b68e74 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -864,7 +864,6 @@ impl AtPath { pub fn append(&self, name: &str, contents: &str) { log_info("write(append)", self.plus_as_string(name)); let mut f = OpenOptions::new() - .write(true) .append(true) .create(true) .open(self.plus(name)) @@ -876,7 +875,6 @@ impl AtPath { pub fn append_bytes(&self, name: &str, contents: &[u8]) { log_info("write(append)", self.plus_as_string(name)); let mut f = OpenOptions::new() - .write(true) .append(true) .create(true) .open(self.plus(name))