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;
44use rustc_errors:: Applicability ;
55use rustc_hir:: def:: Res ;
66use rustc_hir:: * ;
7- use rustc_lint:: { LateContext , LateLintPass } ;
7+ use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
88use rustc_session:: declare_lint_pass;
9+ use rustc_span:: { FileName , RealFileName } ;
910
1011declare_clippy_lint ! {
1112 /// ### What it does
@@ -36,6 +37,17 @@ declare_lint_pass!(UseCratePrefixForSelfImports => [USE_CRATE_PREFIX_FOR_SELF_IM
3637
3738impl LateLintPass < ' _ > for UseCratePrefixForSelfImports {
3839 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+
3951 if let ItemKind :: Use ( use_path, _) = & item. kind {
4052 if let Some ( segment) = use_path. segments . first ( )
4153 && let Res :: Def ( _, def_id) = segment. res
You can’t perform that action at this time.
0 commit comments