From: Andre Bogus Date: Sun, 2 Oct 2016 19:23:26 +0000 (+0200) Subject: Allow option_map_unwrap_or(_else) X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=8188c464291f05399416eb200598f1c8cc4d457a;p=rust.git Allow option_map_unwrap_or(_else) This fixes #1192. --- diff --git a/README.md b/README.md index 7d6ed96681a..8b119ecf627 100644 --- a/README.md +++ b/README.md @@ -283,8 +283,8 @@ name [nonsensical_open_options](https://github.com/Manishearth/rust-clippy/wiki#nonsensical_open_options) | warn | nonsensical combination of options for opening a file [not_unsafe_ptr_arg_deref](https://github.com/Manishearth/rust-clippy/wiki#not_unsafe_ptr_arg_deref) | warn | public functions dereferencing raw pointer arguments but not marked `unsafe` [ok_expect](https://github.com/Manishearth/rust-clippy/wiki#ok_expect) | warn | using `ok().expect()`, which gives worse error messages than calling `expect` directly on the Result -[option_map_unwrap_or](https://github.com/Manishearth/rust-clippy/wiki#option_map_unwrap_or) | warn | using `Option.map(f).unwrap_or(a)`, which is more succinctly expressed as `map_or(a, f)` -[option_map_unwrap_or_else](https://github.com/Manishearth/rust-clippy/wiki#option_map_unwrap_or_else) | warn | using `Option.map(f).unwrap_or_else(g)`, which is more succinctly expressed as `map_or_else(g, f)` +[option_map_unwrap_or](https://github.com/Manishearth/rust-clippy/wiki#option_map_unwrap_or) | allow | using `Option.map(f).unwrap_or(a)`, which is more succinctly expressed as `map_or(a, f)` +[option_map_unwrap_or_else](https://github.com/Manishearth/rust-clippy/wiki#option_map_unwrap_or_else) | allow | using `Option.map(f).unwrap_or_else(g)`, which is more succinctly expressed as `map_or_else(g, f)` [option_unwrap_used](https://github.com/Manishearth/rust-clippy/wiki#option_unwrap_used) | allow | using `Option.unwrap()`, which should at least get a better message using `expect()` [or_fun_call](https://github.com/Manishearth/rust-clippy/wiki#or_fun_call) | warn | using any `*or` method with a function call, which suggests `*or_else` [out_of_bounds_indexing](https://github.com/Manishearth/rust-clippy/wiki#out_of_bounds_indexing) | deny | out of bounds constant indexing diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index fd42d91f41d..4cfd27c9453 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -271,6 +271,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { matches::SINGLE_MATCH_ELSE, mem_forget::MEM_FORGET, methods::FILTER_MAP, + methods::OPTION_MAP_UNWRAP_OR, + methods::OPTION_MAP_UNWRAP_OR_ELSE, methods::OPTION_UNWRAP_USED, methods::RESULT_UNWRAP_USED, methods::WRONG_PUB_SELF_CONVENTION, @@ -370,8 +372,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { methods::ITER_NTH, methods::NEW_RET_NO_SELF, methods::OK_EXPECT, - methods::OPTION_MAP_UNWRAP_OR, - methods::OPTION_MAP_UNWRAP_OR_ELSE, methods::OR_FUN_CALL, methods::SEARCH_IS_SOME, methods::SHOULD_IMPLEMENT_TRAIT, diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index a0a1059ba48..13664e7d912 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -168,7 +168,7 @@ /// ``` declare_lint! { pub OPTION_MAP_UNWRAP_OR, - Warn, + Allow, "using `Option.map(f).unwrap_or(a)`, which is more succinctly expressed as \ `map_or(a, f)`" } @@ -186,7 +186,7 @@ /// ``` declare_lint! { pub OPTION_MAP_UNWRAP_OR_ELSE, - Warn, + Allow, "using `Option.map(f).unwrap_or_else(g)`, which is more succinctly expressed as \ `map_or_else(g, f)`" }