Skip to content

Commit d19c2fd

Browse files
committed
Remove unused_trait_names's support inside macros
1 parent 0ac12fa commit d19c2fd

File tree

4 files changed

+6
-55
lines changed

4 files changed

+6
-55
lines changed

clippy_lints/src/unused_trait_names.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::source::snippet_opt;
66
use rustc_errors::Applicability;
77
use rustc_hir::def::{DefKind, Res};
88
use rustc_hir::{Item, ItemKind, UseKind};
9-
use rustc_lint::{LateContext, LateLintPass, LintContext as _};
9+
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::ty::Visibility;
1111
use rustc_session::impl_lint_pass;
1212
use rustc_span::symbol::kw;
@@ -59,7 +59,7 @@ impl_lint_pass!(UnusedTraitNames => [UNUSED_TRAIT_NAMES]);
5959

6060
impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames {
6161
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
62-
if !item.span.in_external_macro(cx.sess().source_map())
62+
if !item.span.from_expansion()
6363
&& let ItemKind::Use(path, UseKind::Single(ident)) = item.kind
6464
// Ignore imports that already use Underscore
6565
&& ident.name != kw::Underscore

tests/ui/unused_trait_names.fixed

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ fn msrv_1_33() {
200200
MyStruct.do_things();
201201
}
202202

203+
// Linting inside macro expansion is no longer supported
203204
mod lint_inside_macro_expansion_bad {
204205
macro_rules! foo {
205206
() => {
206-
use std::any::Any as _;
207-
//~^ unused_trait_names
207+
use std::any::Any;
208208
fn bar() {
209209
"bar".type_id();
210210
}
@@ -294,22 +294,3 @@ mod allow_lint_import {
294294
// "foo".type_id();
295295
// }
296296
// }
297-
298-
mod issue14924 {
299-
mod m {
300-
pub trait Tr {
301-
fn method(&self) {}
302-
}
303-
304-
impl Tr for u8 {}
305-
}
306-
307-
macro gen_import($Br: ident) {
308-
use m::Tr as $Br;
309-
}
310-
gen_import!(Br);
311-
312-
fn do_something() {
313-
0u8.method();
314-
}
315-
}

tests/ui/unused_trait_names.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ fn msrv_1_33() {
200200
MyStruct.do_things();
201201
}
202202

203+
// Linting inside macro expansion is no longer supported
203204
mod lint_inside_macro_expansion_bad {
204205
macro_rules! foo {
205206
() => {
206207
use std::any::Any;
207-
//~^ unused_trait_names
208208
fn bar() {
209209
"bar".type_id();
210210
}
@@ -294,22 +294,3 @@ mod allow_lint_import {
294294
// "foo".type_id();
295295
// }
296296
// }
297-
298-
mod issue14924 {
299-
mod m {
300-
pub trait Tr {
301-
fn method(&self) {}
302-
}
303-
304-
impl Tr for u8 {}
305-
}
306-
307-
macro gen_import($Br: ident) {
308-
use m::Tr as $Br;
309-
}
310-
gen_import!(Br);
311-
312-
fn do_something() {
313-
0u8.method();
314-
}
315-
}

tests/ui/unused_trait_names.stderr

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,5 @@ error: importing trait that is only used anonymously
5858
LL | use simple_trait::{MyStruct, MyTrait};
5959
| ^^^^^^^ help: use: `MyTrait as _`
6060

61-
error: importing trait that is only used anonymously
62-
--> tests/ui/unused_trait_names.rs:206:27
63-
|
64-
LL | use std::any::Any;
65-
| ^^^ help: use: `Any as _`
66-
...
67-
LL | foo!();
68-
| ------ in this macro invocation
69-
|
70-
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
71-
72-
error: aborting due to 10 previous errors
61+
error: aborting due to 9 previous errors
7362

0 commit comments

Comments
 (0)