Skip to content

Commit 016653f

Browse files
committed
add checks for macros
1 parent be39ee0 commit 016653f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

clippy_lints/src/and_then_then_some.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_applicability;
3-
use clippy_utils::{fn_def_id, match_def_path};
3+
use clippy_utils::{fn_def_id, is_from_proc_macro, match_def_path};
44
use rustc_errors::Applicability;
55
use rustc_hir::def::Res;
66
use rustc_hir::{Block, Body, Closure, Expr, ExprKind, HirId, Node, Param, Pat, Path, QPath};
77
use rustc_lint::{LateContext, LateLintPass};
8+
use rustc_middle::lint::in_external_macro;
89
use rustc_session::declare_lint_pass;
910
use rustc_span::Span;
1011

@@ -39,11 +40,18 @@ declare_lint_pass!(AndThenThenSome => [AND_THEN_THEN_SOME]);
3940

4041
impl<'tcx> LateLintPass<'tcx> for AndThenThenSome {
4142
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
43+
if in_external_macro(cx.tcx.sess, expr.span) {
44+
return;
45+
}
4246
match expr.kind {
4347
ExprKind::MethodCall(_, recv_or_self, [arg], _) | ExprKind::Call(_, [recv_or_self, arg]) => {
4448
// TODO: check if type of reciever is diagnostic item Option?
4549
if is_and_then(cx, expr) {
4650
if let Some((closure_args, predicate)) = then_some_closure_arg(cx, arg) {
51+
// this check is expensive, so we do it last.
52+
if is_from_proc_macro(cx, expr) {
53+
return;
54+
}
4755
show_sugg(cx, expr.span, recv_or_self, closure_args, predicate);
4856
}
4957
}

0 commit comments

Comments
 (0)