Ignore automatically derived impls of Clone
and Debug
in dead code analysis
This commit is contained in:
parent
261e34d534
commit
81ce2fb167
@ -29,36 +29,21 @@ declare_clippy_lint! {
|
||||
"#[macro_use] is no longer needed"
|
||||
}
|
||||
|
||||
const BRACKETS: &[char] = &['<', '>'];
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
struct PathAndSpan {
|
||||
path: String,
|
||||
span: Span,
|
||||
}
|
||||
|
||||
/// `MacroRefData` includes the name of the macro
|
||||
/// and the path from `SourceMap::span_to_filename`.
|
||||
/// `MacroRefData` includes the name of the macro.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MacroRefData {
|
||||
name: String,
|
||||
path: String,
|
||||
}
|
||||
|
||||
impl MacroRefData {
|
||||
pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self {
|
||||
let sm = cx.sess().source_map();
|
||||
let mut path = sm.filename_for_diagnostics(&sm.span_to_filename(callee)).to_string();
|
||||
|
||||
// std lib paths are <::std::module::file type>
|
||||
// so remove brackets, space and type.
|
||||
if path.contains('<') {
|
||||
path = path.replace(BRACKETS, "");
|
||||
}
|
||||
if path.contains(' ') {
|
||||
path = path.split(' ').next().unwrap().to_string();
|
||||
}
|
||||
Self { name, path }
|
||||
pub fn new(name: String) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +63,7 @@ impl MacroUseImports {
|
||||
fn push_unique_macro(&mut self, cx: &LateContext<'_>, span: Span) {
|
||||
let call_site = span.source_callsite();
|
||||
let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_");
|
||||
if let Some(callee) = span.source_callee() {
|
||||
if let Some(_callee) = span.source_callee() {
|
||||
if !self.collected.contains(&call_site) {
|
||||
let name = if name.contains("::") {
|
||||
name.split("::").last().unwrap().to_string()
|
||||
@ -86,7 +71,7 @@ impl MacroUseImports {
|
||||
name.to_string()
|
||||
};
|
||||
|
||||
self.mac_refs.push(MacroRefData::new(name, callee.def_site, cx));
|
||||
self.mac_refs.push(MacroRefData::new(name));
|
||||
self.collected.insert(call_site);
|
||||
}
|
||||
}
|
||||
@ -95,10 +80,10 @@ impl MacroUseImports {
|
||||
fn push_unique_macro_pat_ty(&mut self, cx: &LateContext<'_>, span: Span) {
|
||||
let call_site = span.source_callsite();
|
||||
let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_");
|
||||
if let Some(callee) = span.source_callee() {
|
||||
if let Some(_callee) = span.source_callee() {
|
||||
if !self.collected.contains(&call_site) {
|
||||
self.mac_refs
|
||||
.push(MacroRefData::new(name.to_string(), callee.def_site, cx));
|
||||
.push(MacroRefData::new(name.to_string()));
|
||||
self.collected.insert(call_site);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
|
||||
use clippy_utils::{match_def_path, paths};
|
||||
use if_chain::if_chain;
|
||||
use rustc_ast::ast::{LitKind, StrStyle};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::{BorrowKind, Expr, ExprKind, HirId};
|
||||
use rustc_hir::{BorrowKind, Expr, ExprKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::source_map::{BytePos, Span};
|
||||
@ -53,10 +52,7 @@ declare_clippy_lint! {
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Regex {
|
||||
spans: FxHashSet<Span>,
|
||||
last: Option<HirId>,
|
||||
}
|
||||
pub struct Regex {}
|
||||
|
||||
impl_lint_pass!(Regex => [INVALID_REGEX, TRIVIAL_REGEX]);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(unused_imports)]
|
||||
#![allow(unused_imports,dead_code)]
|
||||
#![deny(clippy::default_trait_access)]
|
||||
|
||||
use std::default;
|
||||
|
@ -1,6 +1,6 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(unused_imports)]
|
||||
#![allow(unused_imports,dead_code)]
|
||||
#![deny(clippy::default_trait_access)]
|
||||
|
||||
use std::default;
|
||||
|
Loading…
x
Reference in New Issue
Block a user