Skip to content

Commit

Permalink
Add in_macro again
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed May 12, 2019
1 parent 7eb8018 commit abf6481
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 6 additions & 2 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit abf6481

Please sign in to comment.