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
@@ -53,6 +54,17 @@ declare_lint_pass!(UseCratePrefixForSelfImports => [USE_CRATE_PREFIX_FOR_SELF_IM
5354
5455impl LateLintPass < ' _ > for UseCratePrefixForSelfImports {
5556 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+
5668 if let ItemKind :: Use ( use_path, _) = & item. kind {
5769 if let Some ( segment) = use_path. segments . first ( )
5870 && let Res :: Def ( _, def_id) = segment. res
You can’t perform that action at this time.
0 commit comments