From fb021d7ceff3f8b1d7cdb0c2bdd75ea07c0428d2 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 15 Mar 2023 17:46:36 -0400 Subject: refactor: remove usages of `map_or` / `map_or_else` (#18212) These methods are confusing because the arguments are backwards. I feel like they should have never been added to `Option` and that clippy should suggest rewriting to `map(...).unwrap_or(...)`/`map(...).unwrap_or_else(|| ...)` https://github.com/rust-lang/rfcs/issues/1025 --- cli/tools/repl/editor.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'cli/tools/repl') diff --git a/cli/tools/repl/editor.rs b/cli/tools/repl/editor.rs index c9f019305..bf38573f4 100644 --- a/cli/tools/repl/editor.rs +++ b/cli/tools/repl/editor.rs @@ -167,12 +167,11 @@ fn is_word_boundary(c: char) -> bool { } fn get_expr_from_line_at_pos(line: &str, cursor_pos: usize) -> &str { - let start = line[..cursor_pos] - .rfind(is_word_boundary) - .map_or_else(|| 0, |i| i); + let start = line[..cursor_pos].rfind(is_word_boundary).unwrap_or(0); let end = line[cursor_pos..] .rfind(is_word_boundary) - .map_or_else(|| cursor_pos, |i| cursor_pos + i); + .map(|i| cursor_pos + i) + .unwrap_or(cursor_pos); let word = &line[start..end]; let word = word.strip_prefix(is_word_boundary).unwrap_or(word); -- cgit v1.2.3