]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/needless_option_as_deref.rs
modify code
[rust.git] / clippy_lints / src / needless_option_as_deref.rs
index 5024a881d2aa8b10b63d586fc70b2b7fe688a99b..21d8263390af3c813d2ae842d8bfa5f167fa0698 100644 (file)
@@ -1,5 +1,4 @@
 use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::in_macro;
 use clippy_utils::source::snippet_opt;
 use clippy_utils::ty::is_type_diagnostic_item;
 use rustc_errors::Applicability;
@@ -27,6 +26,7 @@
     /// let a = Some(&1);
     /// let b = a;
     /// ```
+    #[clippy::version = "1.57.0"]
     pub NEEDLESS_OPTION_AS_DEREF,
     complexity,
     "no-op use of `deref` or `deref_mut` method to `Option`."
 
 impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
-        if expr.span.from_expansion() || in_macro(expr.span) {
+        if expr.span.from_expansion() {
             return;
         }
         let typeck = cx.typeck_results();
         let outer_ty = typeck.expr_ty(expr);
 
         if_chain! {
-            if is_type_diagnostic_item(cx,outer_ty,sym::option_type);
-            if let ExprKind::MethodCall(path, _, [sub_expr], _) = expr.kind;
+            if is_type_diagnostic_item(cx,outer_ty,sym::Option);
+            if let ExprKind::MethodCall(path, [sub_expr], _) = expr.kind;
             let symbol = path.ident.as_str();
-            if symbol=="as_deref" || symbol=="as_deref_mut";
+            if symbol == "as_deref" || symbol == "as_deref_mut";
             if TyS::same_type( outer_ty, typeck.expr_ty(sub_expr) );
             then{
                 span_lint_and_sugg(