Skip to content

Commit 14d54f0

Browse files
committed
Use Span::from_expansion instead of in_macro
1 parent 84a4ab7 commit 14d54f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+137
-164
lines changed

clippy_lints/src/booleans.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
22
use clippy_utils::source::snippet_opt;
33
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
4-
use clippy_utils::{eq_expr_value, get_trait_def_id, in_macro, paths};
4+
use clippy_utils::{eq_expr_value, get_trait_def_id, paths};
55
use if_chain::if_chain;
66
use rustc_ast::ast::LitKind;
77
use rustc_errors::Applicability;
@@ -453,22 +453,20 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
453453
type Map = Map<'tcx>;
454454

455455
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
456-
if in_macro(e.span) {
457-
return;
458-
}
459-
match &e.kind {
460-
ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => {
461-
self.bool_expr(e);
462-
},
463-
ExprKind::Unary(UnOp::Not, inner) => {
464-
if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() {
456+
if !e.span.from_expansion() {
457+
match &e.kind {
458+
ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => {
465459
self.bool_expr(e);
466-
} else {
467-
walk_expr(self, e);
468-
}
469-
},
470-
_ => walk_expr(self, e),
460+
},
461+
ExprKind::Unary(UnOp::Not, inner) => {
462+
if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() {
463+
self.bool_expr(e);
464+
}
465+
},
466+
_ => {},
467+
}
471468
}
469+
walk_expr(self, e);
472470
}
473471
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
474472
NestedVisitorMap::None

clippy_lints/src/copies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_then};
22
use clippy_utils::source::{first_line_of_span, indent_of, reindent_multiline, snippet, snippet_opt};
33
use clippy_utils::{
4-
both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, in_macro, is_else_clause,
5-
is_lint_allowed, search_same, ContainsName, SpanlessEq, SpanlessHash,
4+
both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, is_else_clause, is_lint_allowed,
5+
search_same, ContainsName, SpanlessEq, SpanlessHash,
66
};
77
use if_chain::if_chain;
88
use rustc_data_structures::fx::FxHashSet;
@@ -623,7 +623,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) {
623623

624624
let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool {
625625
// Do not lint if any expr originates from a macro
626-
if in_macro(lhs.span) || in_macro(rhs.span) {
626+
if lhs.span.from_expansion() || rhs.span.from_expansion() {
627627
return false;
628628
}
629629
// Do not spawn warning if `IFS_SAME_COND` already produced it.

clippy_lints/src/default.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg};
22
use clippy_utils::source::snippet_with_macro_callsite;
33
use clippy_utils::ty::{has_drop, is_copy};
4-
use clippy_utils::{any_parent_is_automatically_derived, contains_name, in_macro, match_def_path, paths};
4+
use clippy_utils::{any_parent_is_automatically_derived, contains_name, match_def_path, paths};
55
use if_chain::if_chain;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_errors::Applicability;
@@ -78,7 +78,7 @@ impl_lint_pass!(Default => [DEFAULT_TRAIT_ACCESS, FIELD_REASSIGN_WITH_DEFAULT]);
7878
impl LateLintPass<'_> for Default {
7979
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
8080
if_chain! {
81-
if !in_macro(expr.span);
81+
if !expr.span.from_expansion();
8282
// Avoid cases already linted by `field_reassign_with_default`
8383
if !self.reassigned_linted.contains(&expr.span);
8484
if let ExprKind::Call(path, ..) = expr.kind;
@@ -125,7 +125,7 @@ impl LateLintPass<'_> for Default {
125125
if let StmtKind::Local(local) = stmt.kind;
126126
if let Some(expr) = local.init;
127127
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
128-
if !in_macro(expr.span);
128+
if !expr.span.from_expansion();
129129
// only take bindings to identifiers
130130
if let PatKind::Binding(_, binding_id, ident, _) = local.pat.kind;
131131
// only when assigning `... = Default::default()`

clippy_lints/src/dereference.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_context;
33
use clippy_utils::ty::peel_mid_ty_refs;
4-
use clippy_utils::{get_parent_node, in_macro, is_lint_allowed};
4+
use clippy_utils::{get_parent_node, is_lint_allowed};
55
use rustc_ast::util::parser::PREC_PREFIX;
66
use rustc_errors::Applicability;
77
use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, UnOp};
@@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
8484
}
8585

8686
// Stop processing sub expressions when a macro call is seen
87-
if in_macro(expr.span) {
87+
if expr.span.from_expansion() {
8888
if let Some((state, data)) = self.state.take() {
8989
report(cx, expr, state, data);
9090
}

clippy_lints/src/derivable_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::{in_macro, is_automatically_derived, is_default_equivalent, remove_blocks};
2+
use clippy_utils::{is_automatically_derived, is_default_equivalent, remove_blocks};
33
use rustc_hir::{
44
def::{DefKind, Res},
55
Body, Expr, ExprKind, GenericArg, Impl, ImplItemKind, Item, ItemKind, Node, PathSegment, QPath, TyKind,
@@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
7272
}) = item.kind;
7373
if let attrs = cx.tcx.hir().attrs(item.hir_id());
7474
if !is_automatically_derived(attrs);
75-
if !in_macro(item.span);
75+
if !item.span.from_expansion();
7676
if let Some(def_id) = trait_ref.trait_def_id();
7777
if cx.tcx.is_diagnostic_item(sym::Default, def_id);
7878
if let impl_item_hir = child.id.hir_id();

clippy_lints/src/eq_op.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use clippy_utils::diagnostics::{multispan_sugg, span_lint, span_lint_and_then};
22
use clippy_utils::source::snippet;
33
use clippy_utils::ty::{implements_trait, is_copy};
4-
use clippy_utils::{
5-
ast_utils::is_useless_with_eq_exprs, eq_expr_value, higher, in_macro, is_expn_of, is_in_test_function,
6-
};
4+
use clippy_utils::{ast_utils::is_useless_with_eq_exprs, eq_expr_value, higher, is_expn_of, is_in_test_function};
75
use if_chain::if_chain;
86
use rustc_errors::Applicability;
97
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, StmtKind};
@@ -102,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
102100
}
103101
let macro_with_not_op = |expr_kind: &ExprKind<'_>| {
104102
if let ExprKind::Unary(_, expr) = *expr_kind {
105-
in_macro(expr.span)
103+
expr.span.from_expansion()
106104
} else {
107105
false
108106
}

clippy_lints/src/excessive_bools.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::in_macro;
32
use rustc_ast::ast::{AssocItemKind, Extern, FnKind, FnSig, ImplKind, Item, ItemKind, TraitKind, Ty, TyKind};
43
use rustc_lint::{EarlyContext, EarlyLintPass};
54
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -135,7 +134,7 @@ fn is_bool_ty(ty: &Ty) -> bool {
135134

136135
impl EarlyLintPass for ExcessiveBools {
137136
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
138-
if in_macro(item.span) {
137+
if item.span.from_expansion() {
139138
return;
140139
}
141140
match &item.kind {

clippy_lints/src/implicit_saturating_sub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::higher;
3-
use clippy_utils::{in_macro, SpanlessEq};
3+
use clippy_utils::SpanlessEq;
44
use if_chain::if_chain;
55
use rustc_ast::ast::LitKind;
66
use rustc_errors::Applicability;
@@ -39,7 +39,7 @@ declare_lint_pass!(ImplicitSaturatingSub => [IMPLICIT_SATURATING_SUB]);
3939

4040
impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
4141
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
42-
if in_macro(expr.span) {
42+
if expr.span.from_expansion() {
4343
return;
4444
}
4545
if_chain! {

clippy_lints/src/inconsistent_struct_constructor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::in_macro;
32
use clippy_utils::source::snippet;
43
use if_chain::if_chain;
54
use rustc_data_structures::fx::FxHashMap;
@@ -66,7 +65,7 @@ declare_lint_pass!(InconsistentStructConstructor => [INCONSISTENT_STRUCT_CONSTRU
6665
impl LateLintPass<'_> for InconsistentStructConstructor {
6766
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
6867
if_chain! {
69-
if !in_macro(expr.span);
68+
if !expr.span.from_expansion();
7069
if let ExprKind::Struct(qpath, fields, base) = expr.kind;
7170
let ty = cx.typeck_results().expr_ty(expr);
7271
if let Some(adt_def) = ty.ty_adt_def();

clippy_lints/src/inherent_impl.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! lint on inherent implementations
22
33
use clippy_utils::diagnostics::span_lint_and_note;
4-
use clippy_utils::{in_macro, is_lint_allowed};
4+
use clippy_utils::is_lint_allowed;
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_hir::{def_id::LocalDefId, Item, ItemKind, Node};
77
use rustc_lint::{LateContext, LateLintPass};
@@ -123,8 +123,10 @@ fn get_impl_span(cx: &LateContext<'_>, id: LocalDefId) -> Option<Span> {
123123
..
124124
}) = cx.tcx.hir().get(id)
125125
{
126-
(!in_macro(span) && impl_item.generics.params.is_empty() && !is_lint_allowed(cx, MULTIPLE_INHERENT_IMPL, id))
127-
.then(|| span)
126+
(!span.from_expansion()
127+
&& impl_item.generics.params.is_empty()
128+
&& !is_lint_allowed(cx, MULTIPLE_INHERENT_IMPL, id))
129+
.then(|| span)
128130
} else {
129131
None
130132
}

0 commit comments

Comments
 (0)