Rename in_macro to in_macro_or_desugar

This commit is contained in:
Manish Goregaokar 2019-05-11 20:40:05 -07:00
parent 3710ec5996
commit 7eb8018554
45 changed files with 132 additions and 121 deletions

View file

@ -5,7 +5,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
use syntax_pos::Span;
use crate::consts::{constant, Constant};
use crate::utils::{in_macro, is_direct_expn_of, span_help_and_lint};
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, span_help_and_lint};
declare_clippy_lint! {
/// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls.
@ -34,16 +34,16 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
let mut is_debug_assert = false;
let debug_assert_not_in_macro = |span: Span| {
let debug_assert_not_in_macro_or_desugar = |span: Span| {
is_debug_assert = true;
// Check that `debug_assert!` itself is not inside a macro
!in_macro(span)
!in_macro_or_desugar(span)
};
if_chain! {
if let Some(assert_span) = is_direct_expn_of(e.span, "assert");
if !in_macro(assert_span)
if !in_macro_or_desugar(assert_span)
|| is_direct_expn_of(assert_span, "debug_assert")
.map_or(false, debug_assert_not_in_macro);
.map_or(false, debug_assert_not_in_macro_or_desugar);
if let ExprKind::Unary(_, ref lit) = e.node;
if let Some(bool_const) = constant(cx, cx.tables, lit);
then {

View file

@ -2,7 +2,7 @@
use crate::reexport::*;
use crate::utils::{
in_macro, is_present_in_source, last_line_of_span, paths, snippet_opt, span_lint, span_lint_and_sugg,
in_macro_or_desugar, is_present_in_source, last_line_of_span, paths, snippet_opt, span_lint, span_lint_and_sugg,
span_lint_and_then, without_block_comments,
};
use if_chain::if_chain;
@ -408,7 +408,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
}
fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attribute]) {
if in_macro(span) {
if in_macro_or_desugar(span) {
return;
}

View file

@ -54,7 +54,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
if let ExprKind::Closure(_, _, eid, _, _) = expr.node {
let body = self.cx.tcx.hir().body(eid);
let ex = &body.value;
if matches!(ex.node, ExprKind::Block(_, _)) && !in_macro(body.value.span) {
if matches!(ex.node, ExprKind::Block(_, _)) && !in_macro_or_desugar(body.value.span) {
self.found_block = Some(ex);
return;
}
@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
if let Some(ex) = &block.expr {
// don't dig into the expression here, just suggest that they remove
// the block
if in_macro(expr.span) || differing_macro_contexts(expr.span, ex.span) {
if in_macro_or_desugar(expr.span) || differing_macro_contexts(expr.span, ex.span) {
return;
}
span_help_and_lint(
@ -96,7 +96,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
}
} else {
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
if in_macro(span) || differing_macro_contexts(expr.span, span) {
if in_macro_or_desugar(span) || differing_macro_contexts(expr.span, span) {
return;
}
// move block higher

View file

@ -1,5 +1,6 @@
use crate::utils::{
get_trait_def_id, implements_trait, in_macro, match_type, paths, snippet_opt, span_lint_and_then, SpanlessEq,
get_trait_def_id, implements_trait, in_macro_or_desugar, match_type, paths, snippet_opt, span_lint_and_then,
SpanlessEq,
};
use rustc::hir::intravisit::*;
use rustc::hir::*;
@ -93,7 +94,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
// prevent folding of `cfg!` macros and the like
if !in_macro(e.span) {
if !in_macro_or_desugar(e.span) {
match &e.node {
ExprKind::Unary(UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)),
ExprKind::Binary(binop, lhs, rhs) => match &binop.node {
@ -441,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(e.span) {
if in_macro_or_desugar(e.span) {
return;
}
match &e.node {

View file

@ -9,7 +9,7 @@ use rustc::{declare_tool_lint, impl_lint_pass};
use syntax::ast::Attribute;
use syntax::source_map::Span;
use crate::utils::{in_macro, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
use crate::utils::{in_macro_or_desugar, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
declare_clippy_lint! {
/// **What it does:** Checks for methods with high cognitive complexity.
@ -42,7 +42,7 @@ impl_lint_pass!(CognitiveComplexity => [COGNITIVE_COMPLEXITY]);
impl CognitiveComplexity {
fn check<'a, 'tcx: 'a>(&mut self, cx: &'a LateContext<'a, 'tcx>, body: &'tcx Body, span: Span) {
if in_macro(span) {
if in_macro_or_desugar(span) {
return;
}

View file

@ -18,7 +18,9 @@ use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::ast;
use crate::utils::sugg::Sugg;
use crate::utils::{in_macro, snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then};
use crate::utils::{
in_macro_or_desugar, snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then,
};
use rustc_errors::Applicability;
declare_clippy_lint! {
@ -75,7 +77,7 @@ declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF]);
impl EarlyLintPass for CollapsibleIf {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
if !in_macro(expr.span) {
if !in_macro_or_desugar(expr.span) {
check_if(cx, expr)
}
}
@ -110,7 +112,7 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
if let ast::ExprKind::Block(ref block, _) = else_.node;
if !block_starts_with_comment(cx, block);
if let Some(else_) = expr_block(block);
if !in_macro(else_.span);
if !in_macro_or_desugar(else_.span);
then {
match else_.node {
ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) => {

View file

@ -1,4 +1,4 @@
use crate::utils::{in_macro, snippet, span_lint_and_then};
use crate::utils::{in_macro_or_desugar, snippet, span_lint_and_then};
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
@ -81,7 +81,7 @@ impl StaticConst {
impl EarlyLintPass for StaticConst {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
if !in_macro(item.span) {
if !in_macro_or_desugar(item.span) {
// Match only constants...
if let ItemKind::Const(ref var_type, _) = item.node {
self.visit_type(var_type, cx);

View file

@ -1,4 +1,4 @@
use crate::utils::{get_parent_expr, higher, in_macro, snippet, span_lint_and_then, span_note_and_lint};
use crate::utils::{get_parent_expr, higher, in_macro_or_desugar, snippet, span_lint_and_then, span_note_and_lint};
use crate::utils::{SpanlessEq, SpanlessHash};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@ -107,7 +107,7 @@ declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, IF_SAME_THEN_ELSE, MATCH_SAME
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if !in_macro(expr.span) {
if !in_macro_or_desugar(expr.span) {
// skip ifs directly in else, it will be checked in the parent if
if let Some(expr) = get_parent_expr(cx, expr) {
if let Some((_, _, Some(ref else_expr))) = higher::if_block(&expr) {

View file

@ -1,4 +1,4 @@
use crate::utils::{in_macro, span_lint};
use crate::utils::{in_macro_or_desugar, span_lint};
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::ast::*;
@ -26,7 +26,7 @@ declare_lint_pass!(DoubleParens => [DOUBLE_PARENS]);
impl EarlyLintPass for DoubleParens {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
return;
}

View file

@ -1,6 +1,6 @@
//! lint on enum variants that are prefixed or suffixed by the same characters
use crate::utils::{camel_case, in_macro, is_present_in_source};
use crate::utils::{camel_case, in_macro_or_desugar, is_present_in_source};
use crate::utils::{span_help_and_lint, span_lint};
use rustc::lint::{EarlyContext, EarlyLintPass, Lint, LintArray, LintPass};
use rustc::{declare_tool_lint, impl_lint_pass};
@ -244,7 +244,7 @@ impl EarlyLintPass for EnumVariantNames {
let item_name = item.ident.as_str();
let item_name_chars = item_name.chars().count();
let item_camel = to_camel_case(&item_name);
if !in_macro(item.span) && is_present_in_source(cx, item.span) {
if !in_macro_or_desugar(item.span) && is_present_in_source(cx, item.span) {
if let Some(&(ref mod_name, ref mod_camel)) = self.modules.last() {
// constants don't have surrounding modules
if !mod_camel.is_empty() {

View file

@ -1,5 +1,5 @@
use crate::utils::{
implements_trait, in_macro, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq,
implements_trait, in_macro_or_desugar, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq,
};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@ -52,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
#[allow(clippy::similar_names, clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Binary(op, ref left, ref right) = e.node {
if in_macro(e.span) {
if in_macro_or_desugar(e.span) {
return;
}
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {

View file

@ -4,7 +4,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::source_map::Span;
use crate::consts::{constant_simple, Constant};
use crate::utils::{in_macro, span_lint};
use crate::utils::{in_macro_or_desugar, span_lint};
declare_clippy_lint! {
/// **What it does:** Checks for erasing operations, e.g., `x * 0`.
@ -31,7 +31,7 @@ declare_lint_pass!(ErasingOp => [ERASING_OP]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if in_macro(e.span) {
if in_macro_or_desugar(e.span) {
return;
}
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {

View file

@ -1,6 +1,7 @@
use crate::utils::paths;
use crate::utils::{
in_macro, is_expn_of, last_path_segment, match_type, resolve_node, snippet, span_lint_and_then, walk_ptrs_ty,
in_macro_or_desugar, is_expn_of, last_path_segment, match_type, resolve_node, snippet, span_lint_and_then,
walk_ptrs_ty,
};
use if_chain::if_chain;
use rustc::hir::*;
@ -38,7 +39,7 @@ declare_lint_pass!(UselessFormat => [USELESS_FORMAT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessFormat {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let Some(span) = is_expn_of(expr.span, "format") {
if in_macro(span) {
if in_macro_or_desugar(span) {
return;
}
match expr.node {

View file

@ -1,4 +1,4 @@
use crate::utils::{differing_macro_contexts, in_macro, snippet_opt, span_note_and_lint};
use crate::utils::{differing_macro_contexts, in_macro_or_desugar, snippet_opt, span_note_and_lint};
use if_chain::if_chain;
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
@ -108,7 +108,7 @@ impl EarlyLintPass for Formatting {
/// Implementation of the `SUSPICIOUS_ASSIGNMENT_FORMATTING` lint.
fn check_assign(cx: &EarlyContext<'_>, expr: &ast::Expr) {
if let ast::ExprKind::Assign(ref lhs, ref rhs) = expr.node {
if !differing_macro_contexts(lhs.span, rhs.span) && !in_macro(lhs.span) {
if !differing_macro_contexts(lhs.span, rhs.span) && !in_macro_or_desugar(lhs.span) {
let eq_span = lhs.span.between(rhs.span);
if let ast::ExprKind::Unary(op, ref sub_rhs) = rhs.node {
if let Some(eq_snippet) = snippet_opt(cx, eq_span) {
@ -140,7 +140,7 @@ fn check_else(cx: &EarlyContext<'_>, expr: &ast::Expr) {
if let Some((then, &Some(ref else_))) = unsugar_if(expr);
if is_block(else_) || unsugar_if(else_).is_some();
if !differing_macro_contexts(then.span, else_.span);
if !in_macro(then.span) && !in_external_macro(cx.sess, expr.span);
if !in_macro_or_desugar(then.span) && !in_external_macro(cx.sess, expr.span);
// workaround for rust-lang/rust#43081
if expr.span.lo().0 != 0 && expr.span.hi().0 != 0;
@ -206,7 +206,7 @@ fn check_array(cx: &EarlyContext<'_>, expr: &ast::Expr) {
fn check_missing_else(cx: &EarlyContext<'_>, first: &ast::Expr, second: &ast::Expr) {
if !differing_macro_contexts(first.span, second.span)
&& !in_macro(first.span)
&& !in_macro_or_desugar(first.span)
&& unsugar_if(first).is_some()
&& (is_block(second) || unsugar_if(second).is_some())
{

View file

@ -1,4 +1,6 @@
use crate::utils::{in_macro, match_trait_method, same_tys, snippet, snippet_with_macro_callsite, span_lint_and_then};
use crate::utils::{
in_macro_or_desugar, match_trait_method, same_tys, snippet, snippet_with_macro_callsite, span_lint_and_then,
};
use crate::utils::{paths, resolve_node};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@ -31,7 +33,7 @@ impl_lint_pass!(IdentityConversion => [IDENTITY_CONVERSION]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if in_macro(e.span) {
if in_macro_or_desugar(e.span) {
return;
}

View file

@ -5,7 +5,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::source_map::Span;
use crate::consts::{constant_simple, Constant};
use crate::utils::{clip, in_macro, snippet, span_lint, unsext};
use crate::utils::{clip, in_macro_or_desugar, snippet, span_lint, unsext};
declare_clippy_lint! {
/// **What it does:** Checks for identity operations, e.g., `x + 0`.
@ -28,7 +28,7 @@ declare_lint_pass!(IdentityOp => [IDENTITY_OP]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if in_macro(e.span) {
if in_macro_or_desugar(e.span) {
return;
}
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {

View file

@ -1,4 +1,4 @@
use crate::utils::{in_macro, is_expn_of, snippet_opt, span_lint_and_then};
use crate::utils::{in_macro_or_desugar, is_expn_of, snippet_opt, span_lint_and_then};
use rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl, HirId, MatchSource};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
@ -118,7 +118,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitReturn {
// checking return type through MIR, HIR is not able to determine inferred closure return types
// make sure it's not a macro
if !mir.return_ty().is_unit() && !in_macro(span) {
if !mir.return_ty().is_unit() && !in_macro_or_desugar(span) {
Self::expr_match(cx, &body.value);
}
}

View file

@ -1,6 +1,6 @@
//! lint when items are used after statements
use crate::utils::{in_macro, span_lint};
use crate::utils::{in_macro_or_desugar, span_lint};
use matches::matches;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
@ -38,7 +38,7 @@ declare_lint_pass!(ItemsAfterStatements => [ITEMS_AFTER_STATEMENTS]);
impl EarlyLintPass for ItemsAfterStatements {
fn check_block(&mut self, cx: &EarlyContext<'_>, item: &Block) {
if in_macro(item.span) {
if in_macro_or_desugar(item.span) {
return;
}
@ -52,7 +52,7 @@ impl EarlyLintPass for ItemsAfterStatements {
// lint on all further items
for stmt in stmts {
if let StmtKind::Item(ref it) = *stmt {
if in_macro(it.span) {
if in_macro_or_desugar(it.span) {
return;
}
if let ItemKind::MacroDef(..) = it.node {

View file

@ -1,4 +1,6 @@
use crate::utils::{get_item_name, in_macro, snippet_with_applicability, span_lint, span_lint_and_sugg, walk_ptrs_ty};
use crate::utils::{
get_item_name, in_macro_or_desugar, snippet_with_applicability, span_lint, span_lint_and_sugg, walk_ptrs_ty,
};
use rustc::hir::def_id::DefId;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@ -73,7 +75,7 @@ declare_lint_pass!(LenZero => [LEN_ZERO, LEN_WITHOUT_IS_EMPTY]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if in_macro(item.span) {
if in_macro_or_desugar(item.span) {
return;
}
@ -85,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
}
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
return;
}

View file

@ -11,7 +11,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
// use rustc::middle::region::CodeExtent;
use crate::consts::{constant, Constant};
use crate::utils::usage::mutated_variables;
use crate::utils::{in_macro, sext, sugg};
use crate::utils::{in_macro_or_desugar, sext, sugg};
use rustc::middle::expr_use_visitor::*;
use rustc::middle::mem_categorization::cmt_;
use rustc::middle::mem_categorization::Categorization;
@ -464,7 +464,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
#[allow(clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
// we don't want to check expanded macros
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
return;
}
@ -1057,7 +1057,7 @@ fn check_for_loop_range<'a, 'tcx>(
body: &'tcx Expr,
expr: &'tcx Expr,
) {
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
return;
}

View file

@ -1,6 +1,7 @@
use crate::utils::paths;
use crate::utils::{
in_macro, is_copy, match_trait_method, match_type, remove_blocks, snippet_with_applicability, span_lint_and_sugg,
in_macro_or_desugar, is_copy, match_trait_method, match_type, remove_blocks, snippet_with_applicability,
span_lint_and_sugg,
};
use if_chain::if_chain;
use rustc::hir;
@ -43,7 +44,7 @@ declare_lint_pass!(MapClone => [MAP_CLONE]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) {
if in_macro(e.span) {
if in_macro_or_desugar(e.span) {
return;
}

View file

@ -1,5 +1,5 @@
use crate::utils::paths;
use crate::utils::{in_macro, iter_input_pats, match_type, method_chain_args, snippet, span_lint_and_then};
use crate::utils::{in_macro_or_desugar, iter_input_pats, match_type, method_chain_args, snippet, span_lint_and_then};
use if_chain::if_chain;
use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@ -240,7 +240,7 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapUnit {
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt) {
if in_macro(stmt.span) {
if in_macro_or_desugar(stmt.span) {
return;
}

View file

@ -2,8 +2,8 @@ use crate::consts::{constant, Constant};
use crate::utils::paths;
use crate::utils::sugg::Sugg;
use crate::utils::{
expr_block, in_macro, is_allowed, is_expn_of, match_qpath, match_type, multispan_sugg, remove_blocks, snippet,
snippet_with_applicability, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty,
expr_block, in_macro_or_desugar, is_allowed, is_expn_of, match_qpath, match_type, multispan_sugg, remove_blocks,
snippet, snippet_with_applicability, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty,
};
use if_chain::if_chain;
use rustc::hir::def::CtorKind;
@ -589,7 +589,7 @@ fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr:
}));
span_lint_and_then(cx, MATCH_REF_PATS, expr.span, title, |db| {
if !in_macro(expr.span) {
if !in_macro_or_desugar(expr.span) {
multispan_sugg(db, msg.to_owned(), suggs);
}
});

View file

@ -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, is_copy,
get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro_or_desugar, 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(expr.span) {
if in_macro_or_desugar(expr.span) {
return;
}

View file

@ -12,8 +12,8 @@ use syntax::source_map::{ExpnFormat, Span};
use crate::consts::{constant, Constant};
use crate::utils::sugg::Sugg;
use crate::utils::{
get_item_name, get_parent_expr, implements_trait, in_constant, in_macro, is_integer_literal, iter_input_pats,
last_path_segment, match_qpath, match_trait_method, paths, snippet, span_lint, span_lint_and_then,
get_item_name, get_parent_expr, implements_trait, in_constant, in_macro_or_desugar, is_integer_literal,
iter_input_pats, last_path_segment, match_qpath, match_trait_method, paths, snippet, span_lint, span_lint_and_then,
span_lint_hir_and_then, walk_ptrs_ty, SpanlessEq,
};
@ -602,7 +602,7 @@ fn in_attributes_expansion(expr: &Expr) -> bool {
/// Tests whether `res` is a variable defined outside a macro.
fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool {
match res {
def::Res::Local(id) | def::Res::Upvar(id, ..) => !in_macro(cx.tcx.hir().span_by_hir_id(id)),
def::Res::Local(id) | def::Res::Upvar(id, ..) => !in_macro_or_desugar(cx.tcx.hir().span_by_hir_id(id)),
_ => false,
}
}

View file

@ -5,7 +5,7 @@
// [`missing_doc`]: https://github.com/rust-lang/rust/blob/d6d05904697d89099b55da3331155392f1db9c00/src/librustc_lint/builtin.rs#L246
//
use crate::utils::{in_macro, span_lint};
use crate::utils::{in_macro_or_desugar, span_lint};
use if_chain::if_chain;
use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
@ -85,7 +85,7 @@ impl MissingDoc {
return;
}
if in_macro(sp) {
if in_macro_or_desugar(sp) {
return;
}

View file

@ -3,7 +3,7 @@
//! This lint is **warn** by default
use crate::utils::sugg::Sugg;
use crate::utils::{higher, in_macro, span_lint, span_lint_and_sugg};
use crate::utils::{higher, in_macro_or_desugar, span_lint, span_lint_and_sugg};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
@ -131,7 +131,7 @@ declare_lint_pass!(BoolComparison => [BOOL_COMPARISON]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if in_macro(e.span) {
if in_macro_or_desugar(e.span) {
return;
}

View file

@ -2,7 +2,7 @@
//!
//! This lint is **warn** by default
use crate::utils::{in_macro, snippet_opt, span_lint_and_then};
use crate::utils::{in_macro_or_desugar, snippet_opt, span_lint_and_then};
use if_chain::if_chain;
use rustc::hir::{BindingAnnotation, Expr, ExprKind, HirId, Item, MutImmutable, Pat, PatKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@ -38,7 +38,7 @@ impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if in_macro(e.span) || self.derived_item.is_some() {
if in_macro_or_desugar(e.span) || self.derived_item.is_some() {
return;
}
if let ExprKind::AddrOf(MutImmutable, ref inner) = e.node {
@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
}
}
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
if in_macro(pat.span) || self.derived_item.is_some() {
if in_macro_or_desugar(pat.span) || self.derived_item.is_some() {
return;
}
if_chain! {

View file

@ -2,7 +2,7 @@
//!
//! This lint is **warn** by default
use crate::utils::{in_macro, snippet, span_lint_and_then};
use crate::utils::{in_macro_or_desugar, snippet, span_lint_and_then};
use if_chain::if_chain;
use rustc::hir::{BindingAnnotation, MutImmutable, Pat, PatKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@ -55,7 +55,7 @@ declare_lint_pass!(NeedlessBorrowedRef => [NEEDLESS_BORROWED_REFERENCE]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
if in_macro(pat.span) {
if in_macro_or_desugar(pat.span) {
// OK, simple enough, lints doesn't check in macro.
return;
}

View file

@ -39,7 +39,7 @@ use std::borrow::Cow;
use syntax::ast;
use syntax::source_map::{original_sp, DUMMY_SP};
use crate::utils::{in_macro, snippet, snippet_block, span_help_and_lint, trim_multiline};
use crate::utils::{in_macro_or_desugar, snippet, snippet_block, span_help_and_lint, trim_multiline};
declare_clippy_lint! {
/// **What it does:** The lint checks for `if`-statements appearing in loops
@ -110,7 +110,7 @@ declare_lint_pass!(NeedlessContinue => [NEEDLESS_CONTINUE]);
impl EarlyLintPass for NeedlessContinue {
fn check_expr(&mut self, ctx: &EarlyContext<'_>, expr: &ast::Expr) {
if !in_macro(expr.span) {
if !in_macro_or_desugar(expr.span) {
check_and_warn(ctx, expr);
}
}

View file

@ -1,7 +1,7 @@
use crate::utils::ptr::get_spans;
use crate::utils::{
get_trait_def_id, implements_trait, in_macro, is_copy, is_self, match_type, multispan_sugg, paths, snippet,
snippet_opt, span_lint_and_then,
get_trait_def_id, implements_trait, in_macro_or_desugar, is_copy, is_self, match_type, multispan_sugg, paths,
snippet, snippet_opt, span_lint_and_then,
};
use if_chain::if_chain;
use matches::matches;
@ -73,7 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
span: Span,
hir_id: HirId,
) {
if in_macro(span) {
if in_macro_or_desugar(span) {
return;
}

View file

@ -1,4 +1,4 @@
use crate::utils::{has_drop, in_macro, snippet_opt, span_lint, span_lint_and_sugg};
use crate::utils::{has_drop, in_macro_or_desugar, snippet_opt, span_lint, span_lint_and_sugg};
use rustc::hir::def::{DefKind, Res};
use rustc::hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@ -43,7 +43,7 @@ declare_clippy_lint! {
}
fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
return false;
}
match expr.node {
@ -103,7 +103,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect {
} else if let Some(reduced) = reduce_expression(cx, expr) {
let mut snippet = String::new();
for e in reduced {
if in_macro(e.span) {
if in_macro_or_desugar(e.span) {
return;
}
if let Some(snip) = snippet_opt(cx, e.span) {
@ -128,7 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect {
}
fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<Vec<&'a Expr>> {
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
return None;
}
match expr.node {

View file

@ -14,7 +14,7 @@ use rustc_errors::Applicability;
use rustc_typeck::hir_ty_to_ty;
use syntax_pos::{Span, DUMMY_SP};
use crate::utils::{in_constant, in_macro, is_copy, span_lint_and_then};
use crate::utils::{in_constant, in_macro_or_desugar, is_copy, span_lint_and_then};
declare_clippy_lint! {
/// **What it does:** Checks for declaration of `const` items which is interior
@ -118,7 +118,7 @@ fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, source: S
let (lint, msg, span) = source.lint();
span_lint_and_then(cx, lint, span, msg, |db| {
if in_macro(span) {
if in_macro_or_desugar(span) {
return; // Don't give suggestions into macros.
}
match source {

View file

@ -1,4 +1,4 @@
use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg};
use crate::utils::{in_macro_or_desugar, snippet_with_applicability, span_lint_and_sugg};
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
@ -32,7 +32,7 @@ declare_lint_pass!(Precedence => [PRECEDENCE]);
impl EarlyLintPass for Precedence {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
return;
}

View file

@ -1,5 +1,5 @@
use crate::utils::{
has_drop, in_macro, is_copy, match_type, paths, snippet_opt, span_lint_hir, span_lint_hir_and_then,
has_drop, in_macro_or_desugar, is_copy, match_type, paths, snippet_opt, span_lint_hir, span_lint_hir_and_then,
walk_ptrs_ty_depth,
};
use if_chain::if_chain;
@ -83,7 +83,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
for (bb, bbdata) in mir.basic_blocks().iter_enumerated() {
let terminator = bbdata.terminator();
if in_macro(terminator.source_info.span) {
if in_macro_or_desugar(terminator.source_info.span) {
continue;
}

View file

@ -7,7 +7,7 @@ use syntax::source_map::Span;
use syntax::visit::FnKind;
use syntax_pos::BytePos;
use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then, span_note_and_lint};
use crate::utils::{in_macro_or_desugar, match_path_ast, snippet_opt, span_lint_and_then, span_note_and_lint};
declare_clippy_lint! {
/// **What it does:** Checks for return statements at the end of a block.
@ -130,7 +130,7 @@ impl Return {
}
fn emit_return_lint(&mut self, cx: &EarlyContext<'_>, ret_span: Span, inner_span: Span) {
if in_external_macro(cx.sess(), inner_span) || in_macro(inner_span) {
if in_external_macro(cx.sess(), inner_span) || in_macro_or_desugar(inner_span) {
return;
}
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
@ -185,7 +185,7 @@ impl EarlyLintPass for Return {
if_chain! {
if let ast::FunctionRetTy::Ty(ref ty) = decl.output;
if let ast::TyKind::Tup(ref vals) = ty.node;
if vals.is_empty() && !in_macro(ty.span) && get_def(span) == get_def(ty.span);
if vals.is_empty() && !in_macro_or_desugar(ty.span) && get_def(span) == get_def(ty.span);
then {
let (rspan, appl) = if let Ok(fn_source) =
cx.sess().source_map()
@ -217,7 +217,7 @@ impl EarlyLintPass for Return {
if_chain! {
if let Some(ref stmt) = block.stmts.last();
if let ast::StmtKind::Expr(ref expr) = stmt.node;
if is_unit_expr(expr) && !in_macro(expr.span);
if is_unit_expr(expr) && !in_macro_or_desugar(expr.span);
then {
let sp = expr.span;
span_lint_and_then(cx, UNUSED_UNIT, sp, "unneeded unit expression", |db| {
@ -235,7 +235,7 @@ impl EarlyLintPass for Return {
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
match e.node {
ast::ExprKind::Ret(Some(ref expr)) | ast::ExprKind::Break(_, Some(ref expr)) => {
if is_unit_expr(expr) && !in_macro(expr.span) {
if is_unit_expr(expr) && !in_macro_or_desugar(expr.span) {
span_lint_and_then(cx, UNUSED_UNIT, expr.span, "unneeded `()`", |db| {
db.span_suggestion(
expr.span,

View file

@ -142,7 +142,7 @@ declare_lint_pass!(StringLitAsBytes => [STRING_LIT_AS_BYTES]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
use crate::utils::{in_macro, snippet, snippet_with_applicability};
use crate::utils::{in_macro_or_desugar, snippet, snippet_with_applicability};
use syntax::ast::{LitKind, StrStyle};
if let ExprKind::MethodCall(ref path, _, ref args) = e.node {
@ -173,7 +173,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
);
} else if callsite == expanded
&& lit_content.as_str().chars().all(|c| c.is_ascii())
&& !in_macro(args[0].span)
&& !in_macro_or_desugar(args[0].span)
{
span_lint_and_sugg(
cx,

View file

@ -1,6 +1,6 @@
use std::cmp;
use crate::utils::{in_macro, is_copy, is_self_ty, snippet, span_lint_and_sugg};
use crate::utils::{in_macro_or_desugar, is_copy, is_self_ty, snippet, span_lint_and_sugg};
use if_chain::if_chain;
use matches::matches;
use rustc::hir;
@ -141,7 +141,7 @@ impl_lint_pass!(TriviallyCopyPassByRef => [TRIVIALLY_COPY_PASS_BY_REF]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if in_macro(item.span) {
if in_macro_or_desugar(item.span) {
return;
}
if let ItemKind::Trait(_, _, _, _, ref trait_items) = item.node {
@ -158,7 +158,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
span: Span,
hir_id: HirId,
) {
if in_macro(span) {
if in_macro_or_desugar(span) {
return;
}

View file

@ -22,7 +22,7 @@ use syntax::source_map::Span;
use crate::consts::{constant, Constant};
use crate::utils::paths;
use crate::utils::{
clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro, int_bits, last_path_segment,
clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro_or_desugar, int_bits, last_path_segment,
match_path, multispan_sugg, same_tys, sext, snippet, snippet_opt, snippet_with_applicability, span_help_and_lint,
span_lint, span_lint_and_sugg, span_lint_and_then, unsext,
};
@ -232,7 +232,7 @@ fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[&str])
/// local bindings should only be checked for the `BORROWED_BOX` lint.
#[allow(clippy::too_many_lines)]
fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
if in_macro(hir_ty.span) {
if in_macro_or_desugar(hir_ty.span) {
return;
}
match hir_ty.node {
@ -460,7 +460,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnitValue {
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
if let StmtKind::Local(ref local) = stmt.node {
if is_unit(cx.tables.pat_ty(&local.pat)) {
if in_external_macro(cx.sess(), stmt.span) || in_macro(local.pat.span) {
if in_external_macro(cx.sess(), stmt.span) || in_macro_or_desugar(local.pat.span) {
return;
}
if higher::is_from_for_desugar(local) {
@ -522,7 +522,7 @@ declare_lint_pass!(UnitCmp => [UNIT_CMP]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
return;
}
if let ExprKind::Binary(ref cmp, ref left, _) = expr.node {
@ -571,7 +571,7 @@ declare_lint_pass!(UnitArg => [UNIT_ARG]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
return;
}
@ -1110,7 +1110,7 @@ fn fp_ty_mantissa_nbits(typ: Ty<'_>) -> u32 {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
return;
}
if let ExprKind::Cast(ref ex, _) = expr.node {
@ -1367,7 +1367,7 @@ impl<'a, 'tcx> TypeComplexity {
}
fn check_type(&self, cx: &LateContext<'_, '_>, ty: &hir::Ty) {
if in_macro(ty.span) {
if in_macro_or_desugar(ty.span) {
return;
}
let score = {
@ -1471,7 +1471,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 {
if let ExprKind::Cast(ref e, _) = expr.node {
if let ExprKind::Lit(ref l) = e.node {
if let LitKind::Char(_) = l.node {
if ty::Uint(UintTy::U8) == cx.tables.expr_ty(expr).sty && !in_macro(expr.span) {
if ty::Uint(UintTy::U8) == cx.tables.expr_ty(expr).sty && !in_macro_or_desugar(expr.span) {
let msg = "casting character literal to u8. `char`s \
are 4 bytes wide in rust, so casting to u8 \
truncates them";
@ -1632,7 +1632,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons {
if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.node {
if let Some((culprit, result)) = detect_absurd_comparison(cx, cmp.node, lhs, rhs) {
if !in_macro(expr.span) {
if !in_macro_or_desugar(expr.span) {
let msg = "this comparison involving the minimum or maximum element for this \
type contains a case that is always true or always false";

View file

@ -1,4 +1,4 @@
use crate::utils::{in_macro, span_lint};
use crate::utils::{in_macro_or_desugar, span_lint};
use rustc::hir;
use rustc::hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel {
span: Span,
fn_id: hir::HirId,
) {
if in_macro(span) {
if in_macro_or_desugar(span) {
return;
}

View file

@ -2,7 +2,9 @@ use if_chain::if_chain;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use crate::utils::{higher::if_block, in_macro, match_type, paths, span_lint_and_then, usage::is_potentially_mutated};
use crate::utils::{
higher::if_block, in_macro_or_desugar, match_type, paths, span_lint_and_then, usage::is_potentially_mutated,
};
use rustc::hir::intravisit::*;
use rustc::hir::*;
use syntax::source_map::Span;
@ -189,7 +191,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Unwrap {
span: Span,
fn_id: HirId,
) {
if in_macro(span) {
if in_macro_or_desugar(span) {
return;
}

View file

@ -90,7 +90,7 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
}
/// Returns `true` if this `expn_info` was expanded by any macro.
pub fn in_macro(span: Span) -> bool {
pub fn in_macro_or_desugar(span: Span) -> bool {
if let Some(info) = span.ctxt().outer().expn_info() {
if let ExpnFormat::CompilerDesugaring(..) = info.format {
false
@ -339,7 +339,7 @@ pub fn method_calls<'a>(expr: &'a Expr, max_depth: usize) -> (Vec<Symbol>, Vec<&
let mut current = expr;
for _ in 0..max_depth {
if let ExprKind::MethodCall(path, _, args) = &current.node {
if args.iter().any(|e| in_macro(e.span)) {
if args.iter().any(|e| in_macro_or_desugar(e.span)) {
break;
}
method_names.push(path.ident.name);
@ -366,7 +366,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr, methods: &[&str]) -> Option<Vec<&'a
// method chains are stored last -> first
if let ExprKind::MethodCall(ref path, _, ref args) = current.node {
if path.ident.name == *method_name {
if args.iter().any(|e| in_macro(e.span)) {
if args.iter().any(|e| in_macro_or_desugar(e.span)) {
return None;
}
matched.push(&**args); // build up `matched` backwards
@ -461,7 +461,7 @@ pub fn snippet_with_applicability<'a, 'b, T: LintContext<'b>>(
default: &'a str,
applicability: &mut Applicability,
) -> Cow<'a, str> {
if *applicability != Applicability::Unspecified && in_macro(span) {
if *applicability != Applicability::Unspecified && in_macro_or_desugar(span) {
*applicability = Applicability::MaybeIncorrect;
}
snippet_opt(cx, span).map_or_else(
@ -531,7 +531,7 @@ pub fn expr_block<'a, 'b, T: LintContext<'b>>(
) -> Cow<'a, str> {
let code = snippet_block(cx, expr.span, default);
let string = option.unwrap_or_default();
if in_macro(expr.span) {
if in_macro_or_desugar(expr.span) {
Cow::Owned(format!("{{ {} }}", snippet_with_macro_callsite(cx, expr.span, default)))
} else if let ExprKind::Block(_, _) = expr.node {
Cow::Owned(format!("{}{}", code, string))

View file

@ -1,7 +1,7 @@
//! Contains utility functions to generate suggestions.
#![deny(clippy::missing_docs_in_private_items)]
use crate::utils::{higher, in_macro, snippet, snippet_opt, snippet_with_macro_callsite};
use crate::utils::{higher, in_macro_or_desugar, snippet, snippet_opt, snippet_with_macro_callsite};
use matches::matches;
use rustc::hir;
use rustc::lint::{EarlyContext, LateContext, LintContext};
@ -69,7 +69,7 @@ impl<'a> Sugg<'a> {
default: &'a str,
applicability: &mut Applicability,
) -> Self {
if *applicability != Applicability::Unspecified && in_macro(expr.span) {
if *applicability != Applicability::Unspecified && in_macro_or_desugar(expr.span) {
*applicability = Applicability::MaybeIncorrect;
}
Self::hir_opt(cx, expr).unwrap_or_else(|| {

View file

@ -381,7 +381,7 @@ Here are some pointers to things you are likely going to need for every lint:
is already in here (`implements_trait`, `match_path`, `snippet`, etc)
* [Clippy diagnostics][diagnostics]
* [The `if_chain` macro][if_chain]
* [`in_macro`][in_macro] and [`in_external_macro`][in_external_macro]
* [`in_macro_or_desugar`][in_macro_or_desugar] and [`in_external_macro`][in_external_macro]
* [`Span`][span]
* [`Applicability`][applicability]
* [The rustc guide][rustc_guide] explains a lot of internal compiler concepts
@ -421,7 +421,7 @@ don't hesitate to ask on Discord, IRC or in the issue/PR.
[if_chain]: https://docs.rs/if_chain/0.1.2/if_chain/
[ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/sty/index.html
[ast]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/index.html
[in_macro]: https://github.com/rust-lang/rust-clippy/blob/d0717d1f9531a03d154aaeb0cad94c243915a146/clippy_lints/src/utils/mod.rs#L94
[in_macro_or_desugar]: https://github.com/rust-lang/rust-clippy/blob/d0717d1f9531a03d154aaeb0cad94c243915a146/clippy_lints/src/utils/mod.rs#L94
[in_external_macro]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/lint/fn.in_external_macro.html
[play]: https://play.rust-lang.org
[author_example]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f093b986e80ad62f3b67a1f24f5e66e2

View file

@ -25,7 +25,7 @@ fn prefix_underscore(_foo: u32) -> u32 {
}
/// Tests that we lint if we use a `_`-variable defined outside within a macro expansion
fn in_macro(_foo: u32) {
fn in_macro_or_desugar(_foo: u32) {
println!("{}", _foo);
assert_eq!(_foo, _foo);
@ -90,7 +90,7 @@ fn main() {
let foo = 0u32;
// tests of unused_underscore lint
let _ = prefix_underscore(foo);
in_macro(foo);
in_macro_or_desugar(foo);
in_struct_field();
// possible false positives
let _ = non_prefix_underscore(foo);