1+ use clippy_config:: msrvs:: { self , Msrv } ;
2+ use clippy_config:: Conf ;
13use clippy_utils:: diagnostics:: span_lint_and_sugg;
24use clippy_utils:: source:: snippet_opt;
35use rustc_errors:: Applicability ;
46use rustc_hir:: def:: { DefKind , Res } ;
57use rustc_hir:: { Item , ItemKind , UseKind } ;
68use rustc_lint:: { LateContext , LateLintPass } ;
79use rustc_middle:: ty:: Visibility ;
8- use rustc_session:: declare_lint_pass ;
10+ use rustc_session:: impl_lint_pass ;
911use rustc_span:: symbol:: kw;
1012
1113declare_clippy_lint ! {
@@ -42,11 +44,24 @@ declare_clippy_lint! {
4244 "use items that import a trait but only use it anonymously"
4345}
4446
45- declare_lint_pass ! ( AnonTraitImport => [ ANON_TRAIT_IMPORT ] ) ;
47+ pub struct AnonTraitImport {
48+ msrv : Msrv ,
49+ }
50+
51+ impl AnonTraitImport {
52+ pub fn new ( conf : & ' static Conf ) -> Self {
53+ Self {
54+ msrv : conf. msrv . clone ( ) ,
55+ }
56+ }
57+ }
58+
59+ impl_lint_pass ! ( AnonTraitImport => [ ANON_TRAIT_IMPORT ] ) ;
4660
4761impl < ' tcx > LateLintPass < ' tcx > for AnonTraitImport {
4862 fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) {
49- if let ItemKind :: Use ( path, UseKind :: Single ) = item. kind
63+ if self . msrv . meets ( msrvs:: UNDERSCORE_IMPORTS )
64+ && let ItemKind :: Use ( path, UseKind :: Single ) = item. kind
5065 // Ignore imports that already use Underscore
5166 && item. ident . name != kw:: Underscore
5267 // Only check traits
@@ -70,4 +85,6 @@ impl<'tcx> LateLintPass<'tcx> for AnonTraitImport {
7085 ) ;
7186 }
7287 }
88+
89+ extract_msrv_attr ! ( LateContext ) ;
7390}
0 commit comments