diff options
| author | bors <bors@rust-lang.org> | 2022-04-17 18:34:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-04-17 18:34:16 +0000 |
| commit | e5ebece910f8bfcc2361bddd847a7ae623debd57 (patch) | |
| tree | 6adff9abfd2d1cd896d2b8678160998d406ebe77 /clippy_lints/src/methods/mod.rs | |
| parent | 0f4f9ecdb3d4db785b5d96ef5c61454e079b12c4 (diff) | |
| parent | 2903b56f177b2b23db62d6bf2d500837d704fb4e (diff) | |
Auto merge of #8665 - InfRandomness:option_take_on_temporary, r=llogiq
Introduce needless_option_take lint - \[x] Followed [lint naming conventions][lint_naming] - \[x] Added passing UI tests (including committed `.stderr` file) - \[x] `cargo test` passes locally - \[x] Executed `cargo dev update_lints` - \[x] Added lint documentation - \[x] Run `cargo dev fmt` Fixes #8618 changelog: Introduce [`needless_option_take`] lint
Diffstat (limited to 'clippy_lints/src/methods/mod.rs')
| -rw-r--r-- | clippy_lints/src/methods/mod.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 70a2aaf78a0..23266739645 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -43,6 +43,7 @@ mod map_flatten; mod map_identity; mod map_unwrap_or; mod needless_option_as_deref; +mod needless_option_take; mod ok_expect; mod option_as_ref_deref; mod option_map_or_none; @@ -2162,6 +2163,26 @@ declare_clippy_lint! { "use of `char::is_digit(..)` with literal radix of 10 or 16" } +declare_clippy_lint! { + /// + /// ### Why is this bad? + /// + /// ### Example + /// ```rust + /// let x = Some(3); + /// x.as_ref().take(); + /// ``` + /// Use instead: + /// ```rust + /// let x = Some(3); + /// x.as_ref(); + /// ``` + #[clippy::version = "1.61.0"] + pub NEEDLESS_OPTION_TAKE, + complexity, + "using `.as_ref().take()` on a temporary value" +} + pub struct Methods { avoid_breaking_exported_api: bool, msrv: Option<RustcVersion>, @@ -2251,6 +2272,7 @@ impl_lint_pass!(Methods => [ ERR_EXPECT, NEEDLESS_OPTION_AS_DEREF, IS_DIGIT_ASCII_RADIX, + NEEDLESS_OPTION_TAKE, ]); /// Extracts a method call name, args, and `Span` of the method name. @@ -2623,6 +2645,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio } } }, + ("take", []) => needless_option_take::check(cx, expr, recv), ("to_os_string" | "to_owned" | "to_path_buf" | "to_vec", []) => { implicit_clone::check(cx, name, expr, recv); }, |
