Skip to content

Commit c063ba1

Browse files
committed
Add in_macro again
1 parent 3909abd commit c063ba1

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

clippy_lints/src/booleans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{
2-
get_trait_def_id, implements_trait, in_macro_or_desugar, match_type, paths, snippet_opt, span_lint_and_then, SpanlessEq,
2+
get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt, span_lint_and_then, SpanlessEq,
33
};
44
use rustc::hir::intravisit::*;
55
use rustc::hir::*;
@@ -441,7 +441,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
441441

442442
impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
443443
fn visit_expr(&mut self, e: &'tcx Expr) {
444-
if in_macro_or_desugar(e.span) {
444+
if in_macro(e.span) {
445445
return;
446446
}
447447
match &e.node {

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use syntax::symbol::LocalInternedString;
2020
use crate::utils::paths;
2121
use crate::utils::sugg;
2222
use crate::utils::{
23-
get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro_or_desugar, is_copy,
23+
get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro, is_copy,
2424
is_ctor_function, is_expn_of, is_self, is_self_ty, iter_input_pats, last_path_segment, match_path, match_qpath,
2525
match_trait_method, match_type, match_var, method_calls, method_chain_args, remove_blocks, return_ty, same_tys,
2626
single_segment_path, snippet, snippet_with_applicability, snippet_with_macro_callsite, span_lint,
@@ -859,7 +859,7 @@ declare_lint_pass!(Methods => [
859859
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
860860
#[allow(clippy::cognitive_complexity)]
861861
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
862-
if in_macro_or_desugar(expr.span) {
862+
if in_macro(expr.span) {
863863
return;
864864
}
865865

clippy_lints/src/utils/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
8989
}
9090
}
9191

92-
/// Returns `true` if this `expn_info` was expanded by any macro.
92+
/// Returns `true` if this `expn_info` was expanded by any macro or desugaring
9393
pub fn in_macro_or_desugar(span: Span) -> bool {
94+
span.ctxt().outer().expn_info().is_some()
95+
}
96+
97+
/// Returns `true` if this `expn_info` was expanded by any macro.
98+
pub fn in_macro(span: Span) -> bool {
9499
if let Some(info) = span.ctxt().outer().expn_info() {
95100
if let ExpnFormat::CompilerDesugaring(..) = info.format {
96101
false
@@ -101,7 +106,6 @@ pub fn in_macro_or_desugar(span: Span) -> bool {
101106
false
102107
}
103108
}
104-
105109
// If the snippet is empty, it's an attribute that was inserted during macro
106110
// expansion and we want to ignore those, because they could come from external
107111
// sources that the user has no control over.

0 commit comments

Comments
 (0)