From ec01b65bce0d8d2ac493e117e0bc9e4ee408c8d2 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 11 Mar 2021 15:52:30 -0500 Subject: [PATCH] More practical clippy settings, simplify some checks --- src/editor.rs | 20 ++++---------------- src/main.rs | 11 ++++------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 8c1baf8..e39f826 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -65,7 +65,6 @@ impl Editor { let args: Vec = env::args().collect(); let mut initial_status = String::from("HELP: Ctrl-S = save | Ctrl-Q = quit"); let document = if let Some(file_name) = args.get(1) { - let file_name = &args[1]; let doc = Document::open(&file_name); if let Ok(doc) = doc { doc @@ -285,11 +284,8 @@ impl Editor { let terminal_height = self.terminal.size().height as usize; let Position { mut y, mut x } = self.cursor_position; let height = self.document.len(); - let mut width = if let Some(row) = self.document.row(y) { - row.len() - } else { - 0 - }; + + let mut width = self.document.row(y).map_or(0, Row::len); match key { Key::Up => y = y.saturating_sub(1), @@ -303,11 +299,7 @@ impl Editor { x -= 1; } else if y > 0 { y -= 1; - if let Some(row) = self.document.row(y) { - x = row.len() - } else { - x = 0 - } + x = self.document.row(y).map_or(0, Row::len); } }, Key::Right => { @@ -337,11 +329,7 @@ impl Editor { _ => (), } - width = if let Some(row) = self.document.row(y) { - row.len() - } else { - 0 - }; + width = self.document.row(y).map_or(0, Row::len); if x > width { x = width; diff --git a/src/main.rs b/src/main.rs index 722bf4d..4580120 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,8 @@ -#![warn(clippy::all, clippy::pedantic, clippy::restriction)] +#![warn(clippy::all, clippy::pedantic)] #![allow( - clippy::missing_docs_in_private_items, - clippy::implicit_return, - clippy::shadow_reuse, - clippy::print_stdout, - clippy::wildcard_enum_match_arm, - clippy::else_if_without_else + clippy::missing_errors_doc, + clippy::must_use_candidate, + clippy::panic, )] mod document; mod editor;