diff options
| -rw-r--r-- | clippy_lints/src/booleans.rs | 6 | ||||
| -rw-r--r-- | clippy_lints/src/methods/mod.rs | 4 | ||||
| -rw-r--r-- | clippy_lints/src/utils/mod.rs | 8 |
3 files changed, 11 insertions, 7 deletions
diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 6dedc7d8775..5c19e232bc9 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -1,6 +1,6 @@ use crate::utils::{ - get_trait_def_id, implements_trait, in_macro_or_desugar, match_type, paths, snippet_opt, span_lint_and_then, - SpanlessEq, + get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt, + span_lint_and_then, SpanlessEq, }; use rustc::hir::intravisit::*; use rustc::hir::*; @@ -442,7 +442,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { fn visit_expr(&mut self, e: &'tcx Expr) { - if in_macro_or_desugar(e.span) { + if in_macro(e.span) { return; } match &e.node { diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index c96d05cef2f..f8cde663d89 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -20,7 +20,7 @@ use syntax::symbol::LocalInternedString; use crate::utils::paths; use crate::utils::sugg; use crate::utils::{ - get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro_or_desugar, is_copy, + get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro, is_copy, is_ctor_function, is_expn_of, is_self, is_self_ty, iter_input_pats, last_path_segment, match_path, match_qpath, match_trait_method, match_type, match_var, method_calls, method_chain_args, remove_blocks, return_ty, same_tys, single_segment_path, snippet, snippet_with_applicability, snippet_with_macro_callsite, span_lint, @@ -859,7 +859,7 @@ declare_lint_pass!(Methods => [ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { #[allow(clippy::cognitive_complexity)] fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { - if in_macro_or_desugar(expr.span) { + if in_macro(expr.span) { return; } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 34280e641db..bfc1233f9eb 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -89,8 +89,13 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool { } } -/// Returns `true` if this `expn_info` was expanded by any macro. +/// Returns `true` if this `expn_info` was expanded by any macro or desugaring pub fn in_macro_or_desugar(span: Span) -> bool { + span.ctxt().outer().expn_info().is_some() +} + +/// Returns `true` if this `expn_info` was expanded by any macro. +pub fn in_macro(span: Span) -> bool { if let Some(info) = span.ctxt().outer().expn_info() { if let ExpnFormat::CompilerDesugaring(..) = info.format { false @@ -101,7 +106,6 @@ pub fn in_macro_or_desugar(span: Span) -> bool { false } } - // If the snippet is empty, it's an attribute that was inserted during macro // expansion and we want to ignore those, because they could come from external // sources that the user has no control over. |
