From d14ca05d6b877826337db02888514269e1071f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Thu, 2 Dec 2021 10:31:19 +0900 Subject: [PATCH] Simplify some cases that use return None to use ? --- helix-core/src/indent.rs | 5 +---- helix-term/src/commands/dap.rs | 5 +---- helix-view/src/gutter.rs | 7 +------ 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index 88ab09b5..8ccc0120 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -194,10 +194,7 @@ fn get_highest_syntax_node_at_bytepos(syntax: &Syntax, pos: usize) -> Option node, - None => return None, - }; + let mut node = tree.root_node().descendant_for_byte_range(pos, pos)?; while let Some(parent) = node.parent() { if parent.start_byte() == node.start_byte() { diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index 8184475c..b44be16c 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -165,10 +165,7 @@ fn get_breakpoint_at_current_line(editor: &mut Editor) -> Option<(usize, Breakpo let text = doc.text().slice(..); let line = doc.selection(view.id).primary().cursor_line(text); - let path = match doc.path() { - Some(path) => path, - None => return None, - }; + let path = doc.path()?; editor.breakpoints.get(path).and_then(|breakpoints| { let i = breakpoints.iter().position(|b| b.line == line); i.map(|i| (i, breakpoints[i].clone())) diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index f1127b6e..e156b9e5 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -119,12 +119,7 @@ pub fn breakpoints<'doc>( Box::new(move |line: usize, _selected: bool, out: &mut String| { let breakpoint = breakpoints .iter() - .find(|breakpoint| breakpoint.line == line); - - let breakpoint = match breakpoint { - Some(b) => b, - None => return None, - }; + .find(|breakpoint| breakpoint.line == line)?; let mut style = if breakpoint.condition.is_some() && breakpoint.log_message.is_some() { error.add_modifier(Modifier::UNDERLINED)