Skip to content

Commit 81ce2fb

Browse files
committed
Ignore automatically derived impls of Clone and Debug in dead code analysis
1 parent 261e34d commit 81ce2fb

File tree

4 files changed

+11
-30
lines changed

4 files changed

+11
-30
lines changed

clippy_lints/src/macro_use.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,21 @@ declare_clippy_lint! {
2929
"#[macro_use] is no longer needed"
3030
}
3131

32-
const BRACKETS: &[char] = &['<', '>'];
33-
3432
#[derive(Clone, Debug, PartialEq, Eq)]
3533
struct PathAndSpan {
3634
path: String,
3735
span: Span,
3836
}
3937

40-
/// `MacroRefData` includes the name of the macro
41-
/// and the path from `SourceMap::span_to_filename`.
38+
/// `MacroRefData` includes the name of the macro.
4239
#[derive(Debug, Clone)]
4340
pub struct MacroRefData {
4441
name: String,
45-
path: String,
4642
}
4743

4844
impl MacroRefData {
49-
pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self {
50-
let sm = cx.sess().source_map();
51-
let mut path = sm.filename_for_diagnostics(&sm.span_to_filename(callee)).to_string();
52-
53-
// std lib paths are <::std::module::file type>
54-
// so remove brackets, space and type.
55-
if path.contains('<') {
56-
path = path.replace(BRACKETS, "");
57-
}
58-
if path.contains(' ') {
59-
path = path.split(' ').next().unwrap().to_string();
60-
}
61-
Self { name, path }
45+
pub fn new(name: String) -> Self {
46+
Self { name }
6247
}
6348
}
6449

@@ -78,15 +63,15 @@ impl MacroUseImports {
7863
fn push_unique_macro(&mut self, cx: &LateContext<'_>, span: Span) {
7964
let call_site = span.source_callsite();
8065
let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_");
81-
if let Some(callee) = span.source_callee() {
66+
if let Some(_callee) = span.source_callee() {
8267
if !self.collected.contains(&call_site) {
8368
let name = if name.contains("::") {
8469
name.split("::").last().unwrap().to_string()
8570
} else {
8671
name.to_string()
8772
};
8873

89-
self.mac_refs.push(MacroRefData::new(name, callee.def_site, cx));
74+
self.mac_refs.push(MacroRefData::new(name));
9075
self.collected.insert(call_site);
9176
}
9277
}
@@ -95,10 +80,10 @@ impl MacroUseImports {
9580
fn push_unique_macro_pat_ty(&mut self, cx: &LateContext<'_>, span: Span) {
9681
let call_site = span.source_callsite();
9782
let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_");
98-
if let Some(callee) = span.source_callee() {
83+
if let Some(_callee) = span.source_callee() {
9984
if !self.collected.contains(&call_site) {
10085
self.mac_refs
101-
.push(MacroRefData::new(name.to_string(), callee.def_site, cx));
86+
.push(MacroRefData::new(name.to_string()));
10287
self.collected.insert(call_site);
10388
}
10489
}

clippy_lints/src/regex.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
33
use clippy_utils::{match_def_path, paths};
44
use if_chain::if_chain;
55
use rustc_ast::ast::{LitKind, StrStyle};
6-
use rustc_data_structures::fx::FxHashSet;
7-
use rustc_hir::{BorrowKind, Expr, ExprKind, HirId};
6+
use rustc_hir::{BorrowKind, Expr, ExprKind};
87
use rustc_lint::{LateContext, LateLintPass};
98
use rustc_session::{declare_tool_lint, impl_lint_pass};
109
use rustc_span::source_map::{BytePos, Span};
@@ -53,10 +52,7 @@ declare_clippy_lint! {
5352
}
5453

5554
#[derive(Clone, Default)]
56-
pub struct Regex {
57-
spans: FxHashSet<Span>,
58-
last: Option<HirId>,
59-
}
55+
pub struct Regex {}
6056

6157
impl_lint_pass!(Regex => [INVALID_REGEX, TRIVIAL_REGEX]);
6258

tests/ui/default_trait_access.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22

3-
#![allow(unused_imports)]
3+
#![allow(unused_imports,dead_code)]
44
#![deny(clippy::default_trait_access)]
55

66
use std::default;

tests/ui/default_trait_access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22

3-
#![allow(unused_imports)]
3+
#![allow(unused_imports,dead_code)]
44
#![deny(clippy::default_trait_access)]
55

66
use std::default;

0 commit comments

Comments
 (0)