@@ -10,8 +10,8 @@ use rustc_span::symbol::sym;
10
10
11
11
declare_clippy_lint ! {
12
12
/// ### What it does
13
- /// Checks for no-op uses of Option::{ as_deref,as_deref_mut} ,
14
- /// for example, `Option<&T>::as_deref()` returns the same type.
13
+ /// Checks for no-op uses of ` Option::as_deref`, for example ,
14
+ /// `Option<&T>::as_deref()` returns the same type.
15
15
///
16
16
/// ### Why is this bad?
17
17
/// Redundant code and improving readability.
@@ -29,12 +29,10 @@ declare_clippy_lint! {
29
29
#[ clippy:: version = "1.57.0" ]
30
30
pub NEEDLESS_OPTION_AS_DEREF ,
31
31
complexity,
32
- "no-op use of `deref` or `deref_mut ` method to `Option`."
32
+ "no-op use of `as_deref ` method to `Option`."
33
33
}
34
34
35
- declare_lint_pass ! ( OptionNeedlessDeref => [
36
- NEEDLESS_OPTION_AS_DEREF ,
37
- ] ) ;
35
+ declare_lint_pass ! ( OptionNeedlessDeref => [ NEEDLESS_OPTION_AS_DEREF ] ) ;
38
36
39
37
impl < ' tcx > LateLintPass < ' tcx > for OptionNeedlessDeref {
40
38
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
@@ -45,19 +43,18 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref {
45
43
let outer_ty = typeck. expr_ty ( expr) ;
46
44
47
45
if_chain ! {
48
- if is_type_diagnostic_item( cx, outer_ty, sym:: Option ) ;
46
+ if is_type_diagnostic_item( cx, outer_ty, sym:: Option ) ;
49
47
if let ExprKind :: MethodCall ( path, _, [ sub_expr] , _) = expr. kind;
50
- let symbol = path. ident. as_str( ) ;
51
- if symbol == "as_deref" || symbol == "as_deref_mut" ;
52
- if TyS :: same_type( outer_ty, typeck. expr_ty( sub_expr) ) ;
53
- then{
48
+ if path. ident. as_str( ) == "as_deref" ;
49
+ if TyS :: same_type( outer_ty, typeck. expr_ty( sub_expr) ) ;
50
+ then {
54
51
span_lint_and_sugg(
55
52
cx,
56
53
NEEDLESS_OPTION_AS_DEREF ,
57
54
expr. span,
58
55
"derefed type is same as origin" ,
59
56
"try this" ,
60
- snippet_opt( cx, sub_expr. span) . unwrap( ) ,
57
+ snippet_opt( cx, sub_expr. span) . unwrap( ) ,
61
58
Applicability :: MachineApplicable
62
59
) ;
63
60
}
0 commit comments