@@ -43,6 +43,7 @@ mod map_flatten;
43
43
mod map_identity;
44
44
mod map_unwrap_or;
45
45
mod needless_option_as_deref;
46
+ mod needless_option_take;
46
47
mod ok_expect;
47
48
mod option_as_ref_deref;
48
49
mod option_map_or_none;
@@ -2162,6 +2163,26 @@ declare_clippy_lint! {
2162
2163
"use of `char::is_digit(..)` with literal radix of 10 or 16"
2163
2164
}
2164
2165
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
+
2165
2186
pub struct Methods {
2166
2187
avoid_breaking_exported_api : bool ,
2167
2188
msrv : Option < RustcVersion > ,
@@ -2251,6 +2272,7 @@ impl_lint_pass!(Methods => [
2251
2272
ERR_EXPECT ,
2252
2273
NEEDLESS_OPTION_AS_DEREF ,
2253
2274
IS_DIGIT_ASCII_RADIX ,
2275
+ NEEDLESS_OPTION_TAKE ,
2254
2276
] ) ;
2255
2277
2256
2278
/// 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
2623
2645
}
2624
2646
}
2625
2647
} ,
2648
+ ( "take" , [ ] ) => needless_option_take:: check ( cx, expr, recv) ,
2626
2649
( "to_os_string" | "to_owned" | "to_path_buf" | "to_vec" , [ ] ) => {
2627
2650
implicit_clone:: check ( cx, name, expr, recv) ;
2628
2651
} ,
0 commit comments