needless_question_mark: don't lint if Some(..) is inside a macro def and the ? is not.
The suggestion would fail to apply. Fixes #6921 changelog: needless_question_mark: don't lint if Some(..) is inside a macro def and the ? is not.
This commit is contained in:
parent
36aee1c526
commit
b42ec5e04d
4 changed files with 68 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::source::snippet;
|
||||
use clippy_utils::ty::is_type_diagnostic_item;
|
||||
use clippy_utils::{is_ok_ctor, is_some_ctor, meets_msrv};
|
||||
use clippy_utils::{differing_macro_contexts, is_ok_ctor, is_some_ctor, meets_msrv};
|
||||
use if_chain::if_chain;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{Body, Expr, ExprKind, LangItem, MatchSource, QPath};
|
||||
|
|
@ -173,6 +173,11 @@ fn is_some_or_ok_call<'a>(
|
|||
// question mark operator
|
||||
let inner_expr = &args[0];
|
||||
|
||||
// if the inner expr is inside macro but the outer one is not, do not lint (#6921)
|
||||
if differing_macro_contexts(expr.span, inner_expr.span) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let inner_ty = cx.typeck_results().expr_ty(inner_expr);
|
||||
let outer_ty = cx.typeck_results().expr_ty(expr);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue