|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_sugg;
|
2 | 2 | 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}; |
4 | 4 | use rustc_errors::Applicability;
|
5 | 5 | use rustc_hir::def::Res;
|
6 | 6 | use rustc_hir::{Block, Body, Closure, Expr, ExprKind, HirId, Node, Param, Pat, Path, QPath};
|
7 | 7 | use rustc_lint::{LateContext, LateLintPass};
|
| 8 | +use rustc_middle::lint::in_external_macro; |
8 | 9 | use rustc_session::declare_lint_pass;
|
9 | 10 | use rustc_span::Span;
|
10 | 11 |
|
@@ -39,11 +40,18 @@ declare_lint_pass!(AndThenThenSome => [AND_THEN_THEN_SOME]);
|
39 | 40 |
|
40 | 41 | impl<'tcx> LateLintPass<'tcx> for AndThenThenSome {
|
41 | 42 | 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 | + } |
42 | 46 | match expr.kind {
|
43 | 47 | ExprKind::MethodCall(_, recv_or_self, [arg], _) | ExprKind::Call(_, [recv_or_self, arg]) => {
|
44 | 48 | // TODO: check if type of reciever is diagnostic item Option?
|
45 | 49 | if is_and_then(cx, expr) {
|
46 | 50 | 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 | + } |
47 | 55 | show_sugg(cx, expr.span, recv_or_self, closure_args, predicate);
|
48 | 56 | }
|
49 | 57 | }
|
|
0 commit comments