Skip to content

Commit c99adbc

Browse files
committed
Delay several is_from_proc_macro checks
1 parent 6dd2adc commit c99adbc

7 files changed

+27
-25
lines changed

clippy_lints/src/as_conversions.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ declare_lint_pass!(AsConversions => [AS_CONVERSIONS]);
4848

4949
impl<'tcx> LateLintPass<'tcx> for AsConversions {
5050
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
51-
if in_external_macro(cx.sess(), expr.span) || is_from_proc_macro(cx, expr) {
52-
return;
53-
}
54-
55-
if let ExprKind::Cast(_, _) = expr.kind {
51+
if let ExprKind::Cast(_, _) = expr.kind
52+
&& !in_external_macro(cx.sess(), expr.span)
53+
&& !is_from_proc_macro(cx, expr)
54+
{
5655
span_lint_and_help(
5756
cx,
5857
AS_CONVERSIONS,

clippy_lints/src/borrow_deref_ref.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
5858
if !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..) );
5959
let ref_ty = cx.typeck_results().expr_ty(deref_target);
6060
if let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind();
61-
if !is_from_proc_macro(cx, e);
6261
then{
6362

6463
if let Some(parent_expr) = get_parent_expr(cx, e){
@@ -76,6 +75,9 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
7675
return;
7776
}
7877
}
78+
if is_from_proc_macro(cx, e) {
79+
return;
80+
}
7981

8082
span_lint_and_then(
8183
cx,

clippy_lints/src/manual_float_methods.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,16 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
105105
// case somebody does that for some reason
106106
&& (is_infinity(const_1) && is_neg_infinity(const_2)
107107
|| is_neg_infinity(const_1) && is_infinity(const_2))
108-
&& !is_from_proc_macro(cx, expr)
109108
&& let Some(local_snippet) = snippet_opt(cx, first.span)
110109
{
111110
let variant = match (kind.node, lhs_kind.node, rhs_kind.node) {
112111
(BinOpKind::Or, BinOpKind::Eq, BinOpKind::Eq) => Variant::ManualIsInfinite,
113112
(BinOpKind::And, BinOpKind::Ne, BinOpKind::Ne) => Variant::ManualIsFinite,
114113
_ => return,
115114
};
115+
if is_from_proc_macro(cx, expr) {
116+
return;
117+
}
116118

117119
span_lint_and_then(
118120
cx,

clippy_lints/src/methods/unnecessary_lazy_eval.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ pub(super) fn check<'tcx>(
1818
arg: &'tcx hir::Expr<'_>,
1919
simplify_using: &str,
2020
) {
21-
if is_from_proc_macro(cx, expr) {
22-
return;
23-
}
24-
2521
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option);
2622
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
2723
let is_bool = cx.typeck_results().expr_ty(recv).is_bool();
@@ -31,7 +27,7 @@ pub(super) fn check<'tcx>(
3127
let body = cx.tcx.hir().body(body);
3228
let body_expr = &body.value;
3329

34-
if usage::BindingUsageFinder::are_params_used(cx, body) {
30+
if usage::BindingUsageFinder::are_params_used(cx, body) || is_from_proc_macro(cx, expr) {
3531
return;
3632
}
3733

clippy_lints/src/needless_if.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ impl LateLintPass<'_> for NeedlessIf {
4444
&& block.stmts.is_empty()
4545
&& block.expr.is_none()
4646
&& !in_external_macro(cx.sess(), expr.span)
47-
&& !is_from_proc_macro(cx, expr)
4847
&& let Some(then_snippet) = snippet_opt(cx, then.span)
4948
// Ignore
5049
// - empty macro expansions
@@ -53,6 +52,7 @@ impl LateLintPass<'_> for NeedlessIf {
5352
// - #[cfg]'d out code
5453
&& then_snippet.chars().all(|ch| matches!(ch, '{' | '}') || ch.is_ascii_whitespace())
5554
&& let Some(cond_snippet) = snippet_opt(cx, cond.span)
55+
&& !is_from_proc_macro(cx, expr)
5656
{
5757
span_lint_and_sugg(
5858
cx,

clippy_lints/src/operators/arithmetic_side_effects.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ impl ArithmeticSideEffects {
132132
}
133133

134134
// Common entry-point to avoid code duplication.
135-
fn issue_lint(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
135+
fn issue_lint<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
136+
if is_from_proc_macro(cx, expr) {
137+
return;
138+
}
139+
136140
let msg = "arithmetic operation that can potentially result in unexpected side-effects";
137141
span_lint(cx, ARITHMETIC_SIDE_EFFECTS, expr.span, msg);
138142
self.expr_span = Some(expr.span);
@@ -158,10 +162,10 @@ impl ArithmeticSideEffects {
158162
fn manage_bin_ops<'tcx>(
159163
&mut self,
160164
cx: &LateContext<'tcx>,
161-
expr: &hir::Expr<'tcx>,
165+
expr: &'tcx hir::Expr<'_>,
162166
op: &Spanned<hir::BinOpKind>,
163-
lhs: &hir::Expr<'tcx>,
164-
rhs: &hir::Expr<'tcx>,
167+
lhs: &'tcx hir::Expr<'_>,
168+
rhs: &'tcx hir::Expr<'_>,
165169
) {
166170
if constant_simple(cx, cx.typeck_results(), expr).is_some() {
167171
return;
@@ -234,10 +238,10 @@ impl ArithmeticSideEffects {
234238
/// provided input.
235239
fn manage_method_call<'tcx>(
236240
&mut self,
237-
args: &[hir::Expr<'tcx>],
241+
args: &'tcx [hir::Expr<'_>],
238242
cx: &LateContext<'tcx>,
239-
ps: &hir::PathSegment<'tcx>,
240-
receiver: &hir::Expr<'tcx>,
243+
ps: &'tcx hir::PathSegment<'_>,
244+
receiver: &'tcx hir::Expr<'_>,
241245
) {
242246
let Some(arg) = args.first() else {
243247
return;
@@ -262,8 +266,8 @@ impl ArithmeticSideEffects {
262266
fn manage_unary_ops<'tcx>(
263267
&mut self,
264268
cx: &LateContext<'tcx>,
265-
expr: &hir::Expr<'tcx>,
266-
un_expr: &hir::Expr<'tcx>,
269+
expr: &'tcx hir::Expr<'_>,
270+
un_expr: &'tcx hir::Expr<'_>,
267271
un_op: hir::UnOp,
268272
) {
269273
let hir::UnOp::Neg = un_op else {
@@ -285,14 +289,13 @@ impl ArithmeticSideEffects {
285289

286290
fn should_skip_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'tcx>) -> bool {
287291
is_lint_allowed(cx, ARITHMETIC_SIDE_EFFECTS, expr.hir_id)
288-
|| is_from_proc_macro(cx, expr)
289292
|| self.expr_span.is_some()
290293
|| self.const_span.map_or(false, |sp| sp.contains(expr.span))
291294
}
292295
}
293296

294297
impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
295-
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'tcx>) {
298+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
296299
if self.should_skip_expr(cx, expr) {
297300
return;
298301
}

clippy_lints/src/single_call_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ impl<'tcx> LateLintPass<'tcx> for SingleCallFn {
7272
) {
7373
if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id)
7474
|| in_external_macro(cx.sess(), span)
75-
|| is_from_proc_macro(cx, &(&kind, body, cx.tcx.local_def_id_to_hir_id(def_id), span))
7675
|| is_in_test_function(cx.tcx, body.value.hir_id)
76+
|| is_from_proc_macro(cx, &(&kind, body, cx.tcx.local_def_id_to_hir_id(def_id), span))
7777
{
7878
return;
7979
}

0 commit comments

Comments
 (0)