use crate::reexport::*;
use crate::utils::{
- in_macro, last_line_of_span, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg, span_lint_and_then,
+ in_macro, 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;
use rustc::hir::*;
use rustc::lint::{
- CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass,
+ in_external_macro, CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray,
+ LintContext, LintPass,
};
-use rustc::ty::{self, TyCtxt};
-use rustc::{declare_tool_lint, lint_array};
+use rustc::ty;
+use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
use semver::Version;
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
"usage of `cfg_attr(rustfmt)` instead of `tool_attributes`"
}
-#[derive(Copy, Clone)]
-pub struct AttrPass;
+declare_lint_pass!(Attributes => [
+ INLINE_ALWAYS,
+ DEPRECATED_SEMVER,
+ USELESS_ATTRIBUTE,
+ EMPTY_LINE_AFTER_OUTER_ATTR,
+ UNKNOWN_CLIPPY_LINTS,
+]);
-impl LintPass for AttrPass {
- fn get_lints(&self) -> LintArray {
- lint_array!(
- INLINE_ALWAYS,
- DEPRECATED_SEMVER,
- USELESS_ATTRIBUTE,
- EMPTY_LINE_AFTER_OUTER_ATTR,
- UNKNOWN_CLIPPY_LINTS,
- )
- }
-
- fn name(&self) -> &'static str {
- "Attributes"
- }
-}
-
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
if let Some(items) = &attr.meta_item_list() {
- if let Some(ident) = attr.ident_str() {
- match ident {
+ if let Some(ident) = attr.ident() {
+ match &*ident.as_str() {
"allow" | "warn" | "deny" | "forbid" => {
check_clippy_lint_names(cx, items);
},
}
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
- if is_relevant_item(cx.tcx, item) {
+ if is_relevant_item(cx, item) {
check_attrs(cx, item.span, item.ident.name, &item.attrs)
}
match item.node {
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name("macro_use"));
for attr in &item.attrs {
+ if in_external_macro(cx.sess(), attr.span) {
+ return;
+ }
if let Some(lint_list) = &attr.meta_item_list() {
- if let Some(ident) = attr.ident_str() {
- match ident {
+ if let Some(ident) = attr.ident() {
+ match &*ident.as_str() {
"allow" | "warn" | "deny" | "forbid" => {
// whitelist `unused_imports` and `deprecated` for `use` items
// and `unused_imports` for `extern crate` items with `macro_use`
}
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
- if is_relevant_impl(cx.tcx, item) {
+ if is_relevant_impl(cx, item) {
check_attrs(cx, item.span, item.ident.name, &item.attrs)
}
}
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
- if is_relevant_trait(cx.tcx, item) {
+ if is_relevant_trait(cx, item) {
check_attrs(cx, item.span, item.ident.name, &item.attrs)
}
}
}
}
-fn is_relevant_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &Item) -> bool {
+fn is_relevant_item(cx: &LateContext<'_, '_>, item: &Item) -> bool {
if let ItemKind::Fn(_, _, _, eid) = item.node {
- is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir().body(eid).value)
+ is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
} else {
true
}
}
-fn is_relevant_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &ImplItem) -> bool {
+fn is_relevant_impl(cx: &LateContext<'_, '_>, item: &ImplItem) -> bool {
match item.node {
- ImplItemKind::Method(_, eid) => is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir().body(eid).value),
+ ImplItemKind::Method(_, eid) => is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value),
_ => false,
}
}
-fn is_relevant_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &TraitItem) -> bool {
+fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem) -> bool {
match item.node {
TraitItemKind::Method(_, TraitMethod::Required(_)) => true,
TraitItemKind::Method(_, TraitMethod::Provided(eid)) => {
- is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir().body(eid).value)
+ is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
},
_ => false,
}
}
-fn is_relevant_block<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
+fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
if let Some(stmt) = block.stmts.first() {
match &stmt.node {
StmtKind::Local(_) => true,
- StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(tcx, tables, expr),
+ StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, tables, expr),
_ => false,
}
} else {
- block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))
+ block.expr.as_ref().map_or(false, |e| is_relevant_expr(cx, tables, e))
}
}
-fn is_relevant_expr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
+fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
match &expr.node {
- ExprKind::Block(block, _) => is_relevant_block(tcx, tables, block),
- ExprKind::Ret(Some(e)) => is_relevant_expr(tcx, tables, e),
+ ExprKind::Block(block, _) => is_relevant_block(cx, tables, block),
+ ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e),
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
ExprKind::Call(path_expr, _) => {
if let ExprKind::Path(qpath) = &path_expr.node {
if let Some(fun_id) = tables.qpath_def(qpath, path_expr.hir_id).opt_def_id() {
- !match_def_path(tcx, fun_id, &paths::BEGIN_PANIC)
+ !cx.match_def_path(fun_id, &paths::BEGIN_PANIC)
} else {
true
}
true
}
-#[derive(Copy, Clone)]
-pub struct CfgAttrPass;
-
-impl LintPass for CfgAttrPass {
- fn get_lints(&self) -> LintArray {
- lint_array!(DEPRECATED_CFG_ATTR,)
- }
-
- fn name(&self) -> &'static str {
- "DeprecatedCfgAttribute"
- }
-}
+declare_lint_pass!(DeprecatedCfgAttribute => [DEPRECATED_CFG_ATTR]);
-impl EarlyLintPass for CfgAttrPass {
+impl EarlyLintPass for DeprecatedCfgAttribute {
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
if_chain! {
// check cfg_attr