@@ -43,6 +43,7 @@ mod map_flatten;
4343mod map_identity;
4444mod map_unwrap_or;
4545mod needless_option_as_deref;
46+ mod needless_option_take;
4647mod ok_expect;
4748mod option_as_ref_deref;
4849mod option_map_or_none;
@@ -2162,6 +2163,26 @@ declare_clippy_lint! {
21622163 "use of `char::is_digit(..)` with literal radix of 10 or 16"
21632164}
21642165
2166+ declare_clippy_lint ! {
2167+ ///
2168+ /// ### Why is this bad?
2169+ ///
2170+ /// ### Example
2171+ /// ```rust
2172+ /// let x = Some(3);
2173+ /// x.as_ref().take();
2174+ /// ```
2175+ /// Use instead:
2176+ /// ```rust
2177+ /// let x = Some(3);
2178+ /// x.as_ref();
2179+ /// ```
2180+ #[ clippy:: version = "1.61.0" ]
2181+ pub NEEDLESS_OPTION_TAKE ,
2182+ complexity,
2183+ "using `.as_ref().take()` on a temporary value"
2184+ }
2185+
21652186pub struct Methods {
21662187 avoid_breaking_exported_api : bool ,
21672188 msrv : Option < RustcVersion > ,
@@ -2251,6 +2272,7 @@ impl_lint_pass!(Methods => [
22512272 ERR_EXPECT ,
22522273 NEEDLESS_OPTION_AS_DEREF ,
22532274 IS_DIGIT_ASCII_RADIX ,
2275+ NEEDLESS_OPTION_TAKE ,
22542276] ) ;
22552277
22562278/// 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
26232645 }
26242646 }
26252647 } ,
2648+ ( "take" , [ ] ) => needless_option_take:: check ( cx, expr, recv) ,
26262649 ( "to_os_string" | "to_owned" | "to_path_buf" | "to_vec" , [ ] ) => {
26272650 implicit_clone:: check ( cx, name, expr, recv) ;
26282651 } ,
0 commit comments