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
@@ -53,6 +54,17 @@ declare_lint_pass!(UseCratePrefixForSelfImports => [USE_CRATE_PREFIX_FOR_SELF_IM
53
54
54
55
impl LateLintPass < ' _ > for UseCratePrefixForSelfImports {
55
56
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & Item < ' _ > ) {
57
+ let FileName :: Real ( RealFileName :: LocalPath ( p) ) = cx. sess ( ) . source_map ( ) . span_to_filename ( item. span ) else {
58
+ return ;
59
+ } ;
60
+ let Some ( file_name) = p. file_name ( ) else {
61
+ return ;
62
+ } ;
63
+ // only check `main.rs` and `lib.rs`
64
+ if !( file_name == "main.rs" || file_name == "lib.rs" ) {
65
+ return ;
66
+ }
67
+
56
68
if let ItemKind :: Use ( use_path, _) = & item. kind {
57
69
if let Some ( segment) = use_path. segments . first ( )
58
70
&& let Res :: Def ( _, def_id) = segment. res
You can’t perform that action at this time.
0 commit comments