Auto merge of #4417 - kraai:remove-in_macro_or_desugar, r=phansch
Remove in_macro_or_desugar `in_macro_or_desugar` is just a wrapper around `Span::from_expansion`, so remove the former and call the latter instead. changelog: Remove `in_macro_or_desugar`.
This commit is contained in:
commit
7810652310
@ -3,7 +3,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||
|
||||
use crate::consts::{constant, Constant};
|
||||
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, is_expn_of, span_help_and_lint};
|
||||
use crate::utils::{is_direct_expn_of, is_expn_of, span_help_and_lint};
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls.
|
||||
@ -55,12 +55,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
|
||||
}
|
||||
};
|
||||
if let Some(debug_assert_span) = is_expn_of(e.span, "debug_assert") {
|
||||
if in_macro_or_desugar(debug_assert_span) {
|
||||
if debug_assert_span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
lint_assert_cb(true);
|
||||
} else if let Some(assert_span) = is_direct_expn_of(e.span, "assert") {
|
||||
if in_macro_or_desugar(assert_span) {
|
||||
if assert_span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
lint_assert_cb(false);
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
use crate::reexport::*;
|
||||
use crate::utils::{
|
||||
in_macro_or_desugar, is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint,
|
||||
span_lint_and_sugg, span_lint_and_then, without_block_comments,
|
||||
is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg,
|
||||
span_lint_and_then, without_block_comments,
|
||||
};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::*;
|
||||
@ -412,7 +412,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_or_desugar(span) {
|
||||
if span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ impl<'a, 'tcx> 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_or_desugar(body.value.span) {
|
||||
if matches!(ex.node, ExprKind::Block(_, _)) && !body.value.span.from_expansion() {
|
||||
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_or_desugar(expr.span) || differing_macro_contexts(expr.span, ex.span) {
|
||||
if expr.span.from_expansion() || 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_or_desugar(span) || differing_macro_contexts(expr.span, span) {
|
||||
if span.from_expansion() || differing_macro_contexts(expr.span, span) {
|
||||
return;
|
||||
}
|
||||
// move block higher
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::utils::{
|
||||
get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt,
|
||||
span_lint_and_then, SpanlessEq,
|
||||
get_trait_def_id, implements_trait, in_macro, match_type, paths, snippet_opt, span_lint_and_then, SpanlessEq,
|
||||
};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::intravisit::*;
|
||||
@ -106,7 +105,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
|
||||
}
|
||||
|
||||
// prevent folding of `cfg!` macros and the like
|
||||
if !in_macro_or_desugar(e.span) {
|
||||
if !e.span.from_expansion() {
|
||||
match &e.node {
|
||||
ExprKind::Unary(UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)),
|
||||
ExprKind::Binary(binop, lhs, rhs) => match &binop.node {
|
||||
|
@ -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_or_desugar, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
|
||||
use crate::utils::{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>(&mut self, cx: &'a LateContext<'a, 'tcx>, body: &'tcx Body, span: Span) {
|
||||
if in_macro_or_desugar(span) {
|
||||
if span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
|
||||
use syntax::ast;
|
||||
|
||||
use crate::utils::sugg::Sugg;
|
||||
use crate::utils::{
|
||||
in_macro_or_desugar, snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then,
|
||||
};
|
||||
use crate::utils::{snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then};
|
||||
use rustc_errors::Applicability;
|
||||
|
||||
declare_clippy_lint! {
|
||||
@ -77,7 +75,7 @@ declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF]);
|
||||
|
||||
impl EarlyLintPass for CollapsibleIf {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||
if !in_macro_or_desugar(expr.span) {
|
||||
if !expr.span.from_expansion() {
|
||||
check_if(cx, expr)
|
||||
}
|
||||
}
|
||||
@ -108,7 +106,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_or_desugar(else_.span);
|
||||
if !else_.span.from_expansion();
|
||||
if let ast::ExprKind::If(..) = else_.node;
|
||||
then {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
|
@ -1,6 +1,4 @@
|
||||
use crate::utils::{
|
||||
get_parent_expr, higher, in_macro_or_desugar, same_tys, snippet, span_lint_and_then, span_note_and_lint,
|
||||
};
|
||||
use crate::utils::{get_parent_expr, higher, same_tys, snippet, span_lint_and_then, span_note_and_lint};
|
||||
use crate::utils::{SpanlessEq, SpanlessHash};
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
@ -109,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_or_desugar(expr.span) {
|
||||
if !expr.span.from_expansion() {
|
||||
// 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) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::utils::{in_macro_or_desugar, span_lint};
|
||||
use crate::utils::span_lint;
|
||||
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||
use syntax::ast::*;
|
||||
@ -27,7 +27,7 @@ declare_lint_pass!(DoubleParens => [DOUBLE_PARENS]);
|
||||
|
||||
impl EarlyLintPass for DoubleParens {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if in_macro_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! lint on enum variants that are prefixed or suffixed by the same characters
|
||||
|
||||
use crate::utils::{camel_case, in_macro_or_desugar, is_present_in_source};
|
||||
use crate::utils::{camel_case, 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};
|
||||
@ -248,7 +248,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_or_desugar(item.span) && is_present_in_source(cx, item.span) {
|
||||
if !item.span.from_expansion() && 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() {
|
||||
|
@ -1,6 +1,4 @@
|
||||
use crate::utils::{
|
||||
implements_trait, in_macro_or_desugar, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq,
|
||||
};
|
||||
use crate::utils::{implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq};
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||
@ -52,7 +50,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_or_desugar(e.span) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
|
||||
|
@ -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_or_desugar, span_lint};
|
||||
use crate::utils::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_or_desugar(e.span) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::utils::paths;
|
||||
use crate::utils::{
|
||||
in_macro_or_desugar, is_expn_of, last_path_segment, match_def_path, match_type, resolve_node, snippet,
|
||||
span_lint_and_then, walk_ptrs_ty,
|
||||
is_expn_of, last_path_segment, match_def_path, match_type, resolve_node, snippet, span_lint_and_then, walk_ptrs_ty,
|
||||
};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::*;
|
||||
@ -40,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_or_desugar(span) {
|
||||
if span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
match expr.node {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::utils::{differing_macro_contexts, in_macro_or_desugar, snippet_opt, span_note_and_lint};
|
||||
use crate::utils::{differing_macro_contexts, 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};
|
||||
@ -107,7 +107,7 @@ impl EarlyLintPass for Formatting {
|
||||
/// Implementation of the `SUSPICIOUS_ASSIGNMENT_FORMATTING` lint.
|
||||
fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if let ExprKind::Assign(ref lhs, ref rhs) = expr.node {
|
||||
if !differing_macro_contexts(lhs.span, rhs.span) && !in_macro_or_desugar(lhs.span) {
|
||||
if !differing_macro_contexts(lhs.span, rhs.span) && !lhs.span.from_expansion() {
|
||||
let eq_span = lhs.span.between(rhs.span);
|
||||
if let ExprKind::Unary(op, ref sub_rhs) = rhs.node {
|
||||
if let Some(eq_snippet) = snippet_opt(cx, eq_span) {
|
||||
@ -139,7 +139,7 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if let ExprKind::If(_, then, Some(else_)) = &expr.node;
|
||||
if is_block(else_) || is_if(else_);
|
||||
if !differing_macro_contexts(then.span, else_.span);
|
||||
if !in_macro_or_desugar(then.span) && !in_external_macro(cx.sess, expr.span);
|
||||
if !then.span.from_expansion() && !in_external_macro(cx.sess, expr.span);
|
||||
|
||||
// workaround for rust-lang/rust#43081
|
||||
if expr.span.lo().0 != 0 && expr.span.hi().0 != 0;
|
||||
@ -205,7 +205,7 @@ fn check_array(cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
|
||||
fn check_missing_else(cx: &EarlyContext<'_>, first: &Expr, second: &Expr) {
|
||||
if !differing_macro_contexts(first.span, second.span)
|
||||
&& !in_macro_or_desugar(first.span)
|
||||
&& !first.span.from_expansion()
|
||||
&& is_if(first)
|
||||
&& (is_block(second) || is_if(second))
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::utils::{
|
||||
in_macro_or_desugar, match_def_path, match_trait_method, same_tys, snippet, snippet_with_macro_callsite,
|
||||
span_lint_and_then,
|
||||
match_def_path, match_trait_method, same_tys, snippet, snippet_with_macro_callsite, span_lint_and_then,
|
||||
};
|
||||
use crate::utils::{paths, resolve_node};
|
||||
use rustc::hir::*;
|
||||
@ -34,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_or_desugar(e.span) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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_or_desugar, snippet, span_lint, unsext};
|
||||
use crate::utils::{clip, snippet, span_lint, unsext};
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks for identity operations, e.g., `x + 0`.
|
||||
@ -29,7 +29,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_or_desugar(e.span) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::utils::{
|
||||
in_macro_or_desugar, match_def_path,
|
||||
match_def_path,
|
||||
paths::{BEGIN_PANIC, BEGIN_PANIC_FMT},
|
||||
resolve_node, snippet_opt, span_lint_and_then,
|
||||
};
|
||||
@ -138,7 +138,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_or_desugar(span) {
|
||||
if !mir.return_ty().is_unit() && !span.from_expansion() {
|
||||
expr_match(cx, &body.value);
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||
|
||||
use crate::utils::{
|
||||
get_trait_def_id, implements_trait, in_macro_or_desugar, match_type, paths, return_ty, span_help_and_lint,
|
||||
trait_ref_of_method, walk_ptrs_ty,
|
||||
get_trait_def_id, implements_trait, match_type, paths, return_ty, span_help_and_lint, trait_ref_of_method,
|
||||
walk_ptrs_ty,
|
||||
};
|
||||
|
||||
declare_clippy_lint! {
|
||||
@ -94,7 +94,7 @@ declare_lint_pass!(InherentToString => [INHERENT_TO_STRING, INHERENT_TO_STRING_S
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString {
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem) {
|
||||
if in_macro_or_desugar(impl_item.span) {
|
||||
if impl_item.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! lint when items are used after statements
|
||||
|
||||
use crate::utils::{in_macro_or_desugar, span_lint};
|
||||
use crate::utils::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_or_desugar(item.span) {
|
||||
if item.span.from_expansion() {
|
||||
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_or_desugar(it.span) {
|
||||
if it.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if let ItemKind::MacroDef(..) = it.node {
|
||||
|
@ -1,6 +1,4 @@
|
||||
use crate::utils::{
|
||||
get_item_name, in_macro_or_desugar, snippet_with_applicability, span_lint, span_lint_and_sugg, walk_ptrs_ty,
|
||||
};
|
||||
use crate::utils::{get_item_name, 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};
|
||||
@ -75,7 +73,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_or_desugar(item.span) {
|
||||
if item.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -87,7 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if in_macro_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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_or_desugar, sext, sugg};
|
||||
use crate::utils::{sext, sugg};
|
||||
use rustc::middle::expr_use_visitor::*;
|
||||
use rustc::middle::mem_categorization::cmt_;
|
||||
use rustc::middle::mem_categorization::Categorization;
|
||||
@ -470,7 +470,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_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1034,7 +1034,7 @@ fn check_for_loop_range<'a, 'tcx>(
|
||||
body: &'tcx Expr,
|
||||
expr: &'tcx Expr,
|
||||
) {
|
||||
if in_macro_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::utils::paths;
|
||||
use crate::utils::{
|
||||
in_macro_or_desugar, is_copy, match_trait_method, match_type, remove_blocks, snippet_with_applicability,
|
||||
span_lint_and_sugg,
|
||||
is_copy, match_trait_method, match_type, remove_blocks, snippet_with_applicability, span_lint_and_sugg,
|
||||
};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir;
|
||||
@ -44,7 +43,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_or_desugar(e.span) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::utils::paths;
|
||||
use crate::utils::{in_macro_or_desugar, iter_input_pats, match_type, method_chain_args, snippet, span_lint_and_then};
|
||||
use crate::utils::{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};
|
||||
@ -257,7 +257,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_or_desugar(stmt.span) {
|
||||
if stmt.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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_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,
|
||||
expr_block, 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;
|
||||
@ -597,7 +597,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_or_desugar(expr.span) {
|
||||
if !expr.span.from_expansion() {
|
||||
multispan_sugg(db, msg.to_owned(), suggs);
|
||||
}
|
||||
});
|
||||
|
@ -21,11 +21,11 @@ use syntax::symbol::LocalInternedString;
|
||||
use crate::utils::sugg;
|
||||
use crate::utils::usage::mutated_variables;
|
||||
use crate::utils::{
|
||||
get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro, in_macro_or_desugar,
|
||||
is_copy, is_ctor_function, is_expn_of, iter_input_pats, last_path_segment, match_def_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,
|
||||
span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq,
|
||||
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, iter_input_pats, last_path_segment, match_def_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, span_lint_and_sugg,
|
||||
span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq,
|
||||
};
|
||||
use crate::utils::{paths, span_help_and_lint};
|
||||
|
||||
@ -2150,7 +2150,7 @@ fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &
|
||||
return;
|
||||
}
|
||||
|
||||
let some_inner_snip = if in_macro_or_desugar(inner_expr.span) {
|
||||
let some_inner_snip = if inner_expr.span.from_expansion() {
|
||||
snippet_with_macro_callsite(cx, inner_expr.span, "_")
|
||||
} else {
|
||||
snippet(cx, inner_expr.span, "_")
|
||||
|
@ -12,8 +12,8 @@ use syntax::source_map::{ExpnKind, 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_or_desugar, 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, 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,
|
||||
};
|
||||
|
||||
@ -641,7 +641,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 {
|
||||
if let def::Res::Local(id) = res {
|
||||
!in_macro_or_desugar(cx.tcx.hir().span(id))
|
||||
!cx.tcx.hir().span(id).from_expansion()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -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_or_desugar, span_lint};
|
||||
use crate::utils::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_or_desugar(sp) {
|
||||
if sp.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
//! This lint is **warn** by default
|
||||
|
||||
use crate::utils::sugg::Sugg;
|
||||
use crate::utils::{higher, in_macro_or_desugar, span_lint, span_lint_and_sugg};
|
||||
use crate::utils::{higher, span_lint, span_lint_and_sugg};
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||
@ -129,7 +129,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_or_desugar(e.span) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! This lint is **warn** by default
|
||||
|
||||
use crate::utils::{in_macro_or_desugar, snippet_opt, span_lint_and_then};
|
||||
use crate::utils::{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_or_desugar(e.span) || self.derived_item.is_some() {
|
||||
if e.span.from_expansion() || 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_or_desugar(pat.span) || self.derived_item.is_some() {
|
||||
if pat.span.from_expansion() || self.derived_item.is_some() {
|
||||
return;
|
||||
}
|
||||
if_chain! {
|
||||
|
@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! This lint is **warn** by default
|
||||
|
||||
use crate::utils::{in_macro_or_desugar, snippet, span_lint_and_then};
|
||||
use crate::utils::{snippet, span_lint_and_then};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::{BindingAnnotation, MutImmutable, Pat, PatKind};
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
@ -54,7 +54,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_or_desugar(pat.span) {
|
||||
if pat.span.from_expansion() {
|
||||
// OK, simple enough, lints doesn't check in macro.
|
||||
return;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ use std::borrow::Cow;
|
||||
use syntax::ast;
|
||||
use syntax::source_map::{original_sp, DUMMY_SP};
|
||||
|
||||
use crate::utils::{in_macro_or_desugar, snippet, snippet_block, span_help_and_lint, trim_multiline};
|
||||
use crate::utils::{snippet, snippet_block, span_help_and_lint, trim_multiline};
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** The lint checks for `if`-statements appearing in loops
|
||||
@ -120,7 +120,7 @@ declare_lint_pass!(NeedlessContinue => [NEEDLESS_CONTINUE]);
|
||||
|
||||
impl EarlyLintPass for NeedlessContinue {
|
||||
fn check_expr(&mut self, ctx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||
if !in_macro_or_desugar(expr.span) {
|
||||
if !expr.span.from_expansion() {
|
||||
check_and_warn(ctx, expr);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::utils::ptr::get_spans;
|
||||
use crate::utils::{
|
||||
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,
|
||||
get_trait_def_id, implements_trait, is_copy, is_self, match_type, multispan_sugg, paths, snippet, snippet_opt,
|
||||
span_lint_and_then,
|
||||
};
|
||||
use if_chain::if_chain;
|
||||
use matches::matches;
|
||||
@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
||||
span: Span,
|
||||
hir_id: HirId,
|
||||
) {
|
||||
if in_macro_or_desugar(span) {
|
||||
if span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::utils::{has_drop, in_macro_or_desugar, snippet_opt, span_lint, span_lint_and_sugg};
|
||||
use crate::utils::{has_drop, 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_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
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_or_desugar(e.span) {
|
||||
if e.span.from_expansion() {
|
||||
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_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
return None;
|
||||
}
|
||||
match expr.node {
|
||||
|
@ -14,7 +14,7 @@ use rustc_errors::Applicability;
|
||||
use rustc_typeck::hir_ty_to_ty;
|
||||
use syntax_pos::{InnerSpan, Span, DUMMY_SP};
|
||||
|
||||
use crate::utils::{in_constant, in_macro_or_desugar, is_copy, span_lint_and_then};
|
||||
use crate::utils::{in_constant, is_copy, span_lint_and_then};
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks for declaration of `const` items which is interior
|
||||
@ -119,7 +119,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_or_desugar(span) {
|
||||
if span.from_expansion() {
|
||||
return; // Don't give suggestions into macros.
|
||||
}
|
||||
match source {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::utils::{in_macro_or_desugar, snippet_with_applicability, span_lint_and_sugg};
|
||||
use crate::utils::{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_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::utils::{
|
||||
has_drop, in_macro_or_desugar, is_copy, match_def_path, match_type, paths, snippet_opt, span_lint_hir,
|
||||
span_lint_hir_and_then, walk_ptrs_ty_depth,
|
||||
has_drop, is_copy, match_def_path, match_type, paths, snippet_opt, span_lint_hir, span_lint_hir_and_then,
|
||||
walk_ptrs_ty_depth,
|
||||
};
|
||||
use if_chain::if_chain;
|
||||
use matches::matches;
|
||||
@ -91,7 +91,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_or_desugar(terminator.source_info.span) {
|
||||
if terminator.source_info.span.from_expansion() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::utils::{in_macro_or_desugar, snippet, span_lint_and_then};
|
||||
use crate::utils::{snippet, span_lint_and_then};
|
||||
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_errors::Applicability;
|
||||
@ -78,7 +78,7 @@ impl RedundantStaticLifetimes {
|
||||
|
||||
impl EarlyLintPass for RedundantStaticLifetimes {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
|
||||
if !in_macro_or_desugar(item.span) {
|
||||
if !item.span.from_expansion() {
|
||||
if let ItemKind::Const(ref var_type, _) = item.node {
|
||||
self.visit_type(var_type, cx, "Constants have by default a `'static` lifetime");
|
||||
// Don't check associated consts because `'static` cannot be elided on those (issue
|
||||
|
@ -7,7 +7,7 @@ use syntax::source_map::Span;
|
||||
use syntax::visit::FnKind;
|
||||
use syntax_pos::BytePos;
|
||||
|
||||
use crate::utils::{in_macro_or_desugar, match_path_ast, snippet_opt, span_lint_and_then};
|
||||
use crate::utils::{match_path_ast, snippet_opt, span_lint_and_then};
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks for return statements at the end of a block.
|
||||
@ -155,7 +155,7 @@ impl Return {
|
||||
) {
|
||||
match inner_span {
|
||||
Some(inner_span) => {
|
||||
if in_external_macro(cx.sess(), inner_span) || in_macro_or_desugar(inner_span) {
|
||||
if in_external_macro(cx.sess(), inner_span) || inner_span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -245,7 +245,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_or_desugar(ty.span) && get_def(span) == get_def(ty.span);
|
||||
if vals.is_empty() && !ty.span.from_expansion() && get_def(span) == get_def(ty.span);
|
||||
then {
|
||||
let (rspan, appl) = if let Ok(fn_source) =
|
||||
cx.sess().source_map()
|
||||
@ -277,7 +277,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_or_desugar(expr.span);
|
||||
if is_unit_expr(expr) && !expr.span.from_expansion();
|
||||
then {
|
||||
let sp = expr.span;
|
||||
span_lint_and_then(cx, UNUSED_UNIT, sp, "unneeded unit expression", |db| {
|
||||
@ -295,7 +295,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_or_desugar(expr.span) {
|
||||
if is_unit_expr(expr) && !expr.span.from_expansion() {
|
||||
span_lint_and_then(cx, UNUSED_UNIT, expr.span, "unneeded `()`", |db| {
|
||||
db.span_suggestion(
|
||||
expr.span,
|
||||
|
@ -145,7 +145,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_or_desugar, snippet, snippet_with_applicability};
|
||||
use crate::utils::{snippet, snippet_with_applicability};
|
||||
use syntax::ast::{LitKind, StrStyle};
|
||||
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = e.node {
|
||||
@ -177,7 +177,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
|
||||
} else if callsite == expanded
|
||||
&& lit_content.as_str().chars().all(|c| c.is_ascii())
|
||||
&& lit_content.as_str().len() <= MAX_LENGTH_BYTE_STRING_LIT
|
||||
&& !in_macro_or_desugar(args[0].span)
|
||||
&& !args[0].span.from_expansion()
|
||||
{
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::cmp;
|
||||
|
||||
use crate::utils::{in_macro_or_desugar, is_copy, is_self_ty, snippet, span_lint_and_sugg};
|
||||
use crate::utils::{is_copy, is_self_ty, snippet, span_lint_and_sugg};
|
||||
use if_chain::if_chain;
|
||||
use matches::matches;
|
||||
use rustc::hir;
|
||||
@ -127,7 +127,7 @@ impl_lint_pass!(TriviallyCopyPassByRef => [TRIVIALLY_COPY_PASS_BY_REF]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem) {
|
||||
if in_macro_or_desugar(item.span) {
|
||||
if item.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
|
||||
span: Span,
|
||||
hir_id: HirId,
|
||||
) {
|
||||
if in_macro_or_desugar(span) {
|
||||
if span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::utils::{in_macro_or_desugar, match_qpath, paths, snippet, snippet_with_macro_callsite, span_lint_and_sugg};
|
||||
use crate::utils::{match_qpath, paths, snippet, snippet_with_macro_callsite, span_lint_and_sugg};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
@ -67,7 +67,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr {
|
||||
|
||||
then {
|
||||
let err_type = cx.tables.expr_ty(err_arg);
|
||||
let origin_snippet = if in_macro_or_desugar(err_arg.span) {
|
||||
let origin_snippet = if err_arg.span.from_expansion() {
|
||||
snippet_with_macro_callsite(cx, err_arg.span, "_")
|
||||
} else {
|
||||
snippet(cx, err_arg.span, "_")
|
||||
|
@ -23,8 +23,8 @@ use syntax::symbol::sym;
|
||||
use crate::consts::{constant, Constant};
|
||||
use crate::utils::paths;
|
||||
use crate::utils::{
|
||||
clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro_or_desugar, int_bits, last_path_segment,
|
||||
match_def_path, match_path, multispan_sugg, same_tys, sext, snippet, snippet_opt, snippet_with_applicability,
|
||||
clip, comparisons, differing_macro_contexts, higher, in_constant, int_bits, last_path_segment, match_def_path,
|
||||
match_path, multispan_sugg, same_tys, sext, snippet, snippet_opt, snippet_with_applicability,
|
||||
snippet_with_macro_callsite, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext,
|
||||
};
|
||||
|
||||
@ -234,7 +234,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_or_desugar(hir_ty.span) {
|
||||
if hir_ty.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
match hir_ty.node {
|
||||
@ -462,7 +462,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_or_desugar(local.pat.span) {
|
||||
if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if higher::is_from_for_desugar(local) {
|
||||
@ -526,7 +526,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_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::Binary(ref cmp, ref left, _) = expr.node {
|
||||
@ -575,7 +575,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_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1115,7 +1115,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_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::Cast(ref ex, _) = expr.node {
|
||||
@ -1381,7 +1381,7 @@ impl<'a, 'tcx> TypeComplexity {
|
||||
}
|
||||
|
||||
fn check_type(&self, cx: &LateContext<'_, '_>, ty: &hir::Ty) {
|
||||
if in_macro_or_desugar(ty.span) {
|
||||
if ty.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
let score = {
|
||||
@ -1485,7 +1485,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_or_desugar(expr.span) {
|
||||
if ty::Uint(UintTy::U8) == cx.tables.expr_ty(expr).sty && !expr.span.from_expansion() {
|
||||
let msg = "casting character literal to u8. `char`s \
|
||||
are 4 bytes wide in rust, so casting to u8 \
|
||||
truncates them";
|
||||
@ -1646,7 +1646,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_or_desugar(expr.span) {
|
||||
if !expr.span.from_expansion() {
|
||||
let msg = "this comparison involving the minimum or maximum element for this \
|
||||
type contains a case that is always true or always false";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::utils::{in_macro_or_desugar, span_lint};
|
||||
use crate::utils::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_or_desugar(span) {
|
||||
if span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,7 @@ 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_or_desugar, match_type, paths, span_lint_and_then, usage::is_potentially_mutated,
|
||||
};
|
||||
use crate::utils::{higher::if_block, match_type, paths, span_lint_and_then, usage::is_potentially_mutated};
|
||||
use rustc::hir::intravisit::*;
|
||||
use rustc::hir::*;
|
||||
use syntax::source_map::Span;
|
||||
@ -197,7 +195,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Unwrap {
|
||||
span: Span,
|
||||
fn_id: HirId,
|
||||
) {
|
||||
if in_macro_or_desugar(span) {
|
||||
if span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -92,11 +92,6 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if this `span` was expanded by any macro or desugaring
|
||||
pub fn in_macro_or_desugar(span: Span) -> bool {
|
||||
span.from_expansion()
|
||||
}
|
||||
|
||||
/// Returns `true` if this `span` was expanded by any macro.
|
||||
pub fn in_macro(span: Span) -> bool {
|
||||
if span.from_expansion() {
|
||||
@ -349,7 +344,7 @@ pub fn method_calls(expr: &Expr, max_depth: usize) -> (Vec<Symbol>, Vec<&[Expr]>
|
||||
let mut current = expr;
|
||||
for _ in 0..max_depth {
|
||||
if let ExprKind::MethodCall(path, _, args) = ¤t.node {
|
||||
if args.iter().any(|e| in_macro_or_desugar(e.span)) {
|
||||
if args.iter().any(|e| e.span.from_expansion()) {
|
||||
break;
|
||||
}
|
||||
method_names.push(path.ident.name);
|
||||
@ -376,7 +371,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.as_str() == *method_name {
|
||||
if args.iter().any(|e| in_macro_or_desugar(e.span)) {
|
||||
if args.iter().any(|e| e.span.from_expansion()) {
|
||||
return None;
|
||||
}
|
||||
matched.push(&**args); // build up `matched` backwards
|
||||
@ -471,7 +466,7 @@ pub fn snippet_with_applicability<'a, T: LintContext>(
|
||||
default: &'a str,
|
||||
applicability: &mut Applicability,
|
||||
) -> Cow<'a, str> {
|
||||
if *applicability != Applicability::Unspecified && in_macro_or_desugar(span) {
|
||||
if *applicability != Applicability::Unspecified && span.from_expansion() {
|
||||
*applicability = Applicability::MaybeIncorrect;
|
||||
}
|
||||
snippet_opt(cx, span).map_or_else(
|
||||
@ -536,7 +531,7 @@ pub fn last_line_of_span<T: LintContext>(cx: &T, span: Span) -> Span {
|
||||
pub fn expr_block<'a, T: LintContext>(cx: &T, expr: &Expr, option: Option<String>, default: &'a str) -> Cow<'a, str> {
|
||||
let code = snippet_block(cx, expr.span, default);
|
||||
let string = option.unwrap_or_default();
|
||||
if in_macro_or_desugar(expr.span) {
|
||||
if expr.span.from_expansion() {
|
||||
Cow::Owned(format!("{{ {} }}", snippet_with_macro_callsite(cx, expr.span, default)))
|
||||
} else if let ExprKind::Block(_, _) = expr.node {
|
||||
Cow::Owned(format!("{}{}", code, string))
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Contains utility functions to generate suggestions.
|
||||
#![deny(clippy::missing_docs_in_private_items)]
|
||||
|
||||
use crate::utils::{higher, in_macro_or_desugar, snippet, snippet_opt, snippet_with_macro_callsite};
|
||||
use crate::utils::{higher, 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_or_desugar(expr.span) {
|
||||
if *applicability != Applicability::Unspecified && expr.span.from_expansion() {
|
||||
*applicability = Applicability::MaybeIncorrect;
|
||||
}
|
||||
Self::hir_opt(cx, expr).unwrap_or_else(|| {
|
||||
|
@ -392,7 +392,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_or_desugar`][in_macro_or_desugar] and [`in_external_macro`][in_external_macro]
|
||||
* [`from_expansion`][from_expansion] and [`in_external_macro`][in_external_macro]
|
||||
* [`Span`][span]
|
||||
* [`Applicability`][applicability]
|
||||
* [The rustc guide][rustc_guide] explains a lot of internal compiler concepts
|
||||
@ -432,7 +432,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_or_desugar]: https://github.com/rust-lang/rust-clippy/blob/d0717d1f9531a03d154aaeb0cad94c243915a146/clippy_lints/src/utils/mod.rs#L94
|
||||
[from_expansion]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax_pos/struct.Span.html#method.from_expansion
|
||||
[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
|
||||
|
Loading…
Reference in New Issue
Block a user