File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,9 @@ use def_id::LOCAL_CRATE;
4
4
use rustc_errors:: Applicability ;
5
5
use rustc_hir:: def:: Res ;
6
6
use rustc_hir:: * ;
7
- use rustc_lint:: { LateContext , LateLintPass } ;
7
+ use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
8
8
use rustc_session:: declare_lint_pass;
9
+ use rustc_span:: { FileName , RealFileName } ;
9
10
10
11
declare_clippy_lint ! {
11
12
/// ### What it does
@@ -36,6 +37,17 @@ declare_lint_pass!(UseCratePrefixForSelfImports => [USE_CRATE_PREFIX_FOR_SELF_IM
36
37
37
38
impl LateLintPass < ' _ > for UseCratePrefixForSelfImports {
38
39
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & Item < ' _ > ) {
40
+ let FileName :: Real ( RealFileName :: LocalPath ( p) ) = cx. sess ( ) . source_map ( ) . span_to_filename ( item. span ) else {
41
+ return ;
42
+ } ;
43
+ let Some ( file_name) = p. file_name ( ) else {
44
+ return ;
45
+ } ;
46
+ // only check `main.rs` and `lib.rs`
47
+ if !( file_name == "main.rs" || file_name == "lib.rs" ) {
48
+ return ;
49
+ }
50
+
39
51
if let ItemKind :: Use ( use_path, _) = & item. kind {
40
52
if let Some ( segment) = use_path. segments . first ( )
41
53
&& let Res :: Def ( _, def_id) = segment. res
You can’t perform that action at this time.
0 commit comments