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;
/// 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`."
if expr.span.from_expansion() {
return;
}
- if in_macro(expr.span) {
- 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(