1
1
use crate :: utils:: { in_macro, snippet, span_lint_and_sugg} ;
2
+ use hir:: def:: { DefKind , Res } ;
2
3
use if_chain:: if_chain;
4
+ use rustc_ast:: ast;
3
5
use rustc_data_structures:: fx:: FxHashMap ;
4
6
use rustc_errors:: Applicability ;
5
7
use rustc_hir as hir;
6
- use hir:: def:: { Res , DefKind } ;
7
- use rustc_lint:: { LintContext , LateLintPass , LateContext } ;
8
+ use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
8
9
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
9
10
use rustc_span:: { edition:: Edition , Span } ;
10
- use rustc_ast:: ast;
11
11
12
12
declare_clippy_lint ! {
13
13
/// **What it does:** Checks for `#[macro_use] use...`.
@@ -133,7 +133,6 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
133
133
let name = snippet ( lcx, lcx. sess ( ) . source_map ( ) . span_until_char ( call_site, '!' ) , "_" ) ;
134
134
if let Some ( callee) = expr. span . source_callee ( ) {
135
135
if !self . collected . contains_key ( & call_site) {
136
-
137
136
let name = if name. contains ( "::" ) {
138
137
name. split ( "::" ) . last ( ) . unwrap ( ) . to_string ( )
139
138
} else {
@@ -153,7 +152,6 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
153
152
let name = snippet ( lcx, lcx. sess ( ) . source_map ( ) . span_until_char ( call_site, '!' ) , "_" ) ;
154
153
if let Some ( callee) = stmt. span . source_callee ( ) {
155
154
if !self . collected . contains_key ( & call_site) {
156
-
157
155
let name = if name. contains ( "::" ) {
158
156
name. split ( "::" ) . last ( ) . unwrap ( ) . to_string ( )
159
157
} else {
@@ -196,8 +194,11 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
196
194
197
195
fn check_crate_post ( & mut self , lcx : & LateContext < ' _ , ' _ > , _krate : & hir:: Crate < ' _ > ) {
198
196
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 ( ) ;
201
202
202
203
if matched {
203
204
self . mac_refs . retain ( |( _span, mac) | !import. ends_with ( & mac. name ) ) ;
@@ -222,7 +223,6 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
222
223
}
223
224
}
224
225
225
-
226
226
const PRELUDE : & [ & str ] = & [
227
227
"marker" , "ops" , "convert" , "iter" , "option" , "result" , "borrow" , "boxed" , "string" , "vec" , "macros" ,
228
228
] ;
@@ -233,7 +233,10 @@ fn make_path(mac: &MacroRefData, use_path: &str) -> String {
233
233
let segs = mac. path . split ( "::" ) . filter ( |s| * s != "" ) . collect :: < Vec < _ > > ( ) ;
234
234
235
235
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
+ ) ;
237
240
}
238
241
239
242
if use_path. split ( "::" ) . count ( ) == 1 {
0 commit comments