11use crate :: utils:: { in_macro, snippet, span_lint_and_sugg} ;
2+ use hir:: def:: { DefKind , Res } ;
23use if_chain:: if_chain;
4+ use rustc_ast:: ast;
35use rustc_data_structures:: fx:: FxHashMap ;
46use rustc_errors:: Applicability ;
57use rustc_hir as hir;
6- use hir:: def:: { Res , DefKind } ;
7- use rustc_lint:: { LintContext , LateLintPass , LateContext } ;
8+ use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
89use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
910use rustc_span:: { edition:: Edition , Span } ;
10- use rustc_ast:: ast;
1111
1212declare_clippy_lint ! {
1313 /// **What it does:** Checks for `#[macro_use] use...`.
@@ -133,7 +133,6 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
133133 let name = snippet ( lcx, lcx. sess ( ) . source_map ( ) . span_until_char ( call_site, '!' ) , "_" ) ;
134134 if let Some ( callee) = expr. span . source_callee ( ) {
135135 if !self . collected . contains_key ( & call_site) {
136-
137136 let name = if name. contains ( "::" ) {
138137 name. split ( "::" ) . last ( ) . unwrap ( ) . to_string ( )
139138 } else {
@@ -153,7 +152,6 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
153152 let name = snippet ( lcx, lcx. sess ( ) . source_map ( ) . span_until_char ( call_site, '!' ) , "_" ) ;
154153 if let Some ( callee) = stmt. span . source_callee ( ) {
155154 if !self . collected . contains_key ( & call_site) {
156-
157155 let name = if name. contains ( "::" ) {
158156 name. split ( "::" ) . last ( ) . unwrap ( ) . to_string ( )
159157 } else {
@@ -196,8 +194,11 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
196194
197195 fn check_crate_post ( & mut self , lcx : & LateContext < ' _ , ' _ > , _krate : & hir:: Crate < ' _ > ) {
198196 for ( import, span) in self . imports . iter ( ) {
199-
200- let matched = self . mac_refs . iter ( ) . find ( |( _span, mac) | import. ends_with ( & mac. name ) ) . is_some ( ) ;
197+ let matched = self
198+ . mac_refs
199+ . iter ( )
200+ . find ( |( _span, mac) | import. ends_with ( & mac. name ) )
201+ . is_some ( ) ;
201202
202203 if matched {
203204 self . mac_refs . retain ( |( _span, mac) | !import. ends_with ( & mac. name ) ) ;
@@ -222,7 +223,6 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
222223 }
223224}
224225
225-
226226const PRELUDE : & [ & str ] = & [
227227 "marker" , "ops" , "convert" , "iter" , "option" , "result" , "borrow" , "boxed" , "string" , "vec" , "macros" ,
228228] ;
@@ -233,7 +233,10 @@ fn make_path(mac: &MacroRefData, use_path: &str) -> String {
233233 let segs = mac. path . split ( "::" ) . filter ( |s| * s != "" ) . collect :: < Vec < _ > > ( ) ;
234234
235235 if segs. starts_with ( & [ "std" ] ) && PRELUDE . iter ( ) . any ( |m| segs. contains ( m) ) {
236- return format ! ( "std::prelude::{} is imported by default, remove `use` statement" , mac. name) ;
236+ return format ! (
237+ "std::prelude::{} is imported by default, remove `use` statement" ,
238+ mac. name
239+ ) ;
237240 }
238241
239242 if use_path. split ( "::" ) . count ( ) == 1 {
0 commit comments