Skip to content

Commit bfa6bdb

Browse files
committed
only check main.rs and lib.rs
1 parent 5ef46eb commit bfa6bdb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

clippy_lints/src/use_crate_prefix_for_self_imports.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use def_id::LOCAL_CRATE;
44
use rustc_errors::Applicability;
55
use rustc_hir::def::Res;
66
use rustc_hir::*;
7-
use rustc_lint::{LateContext, LateLintPass};
7+
use rustc_lint::{LateContext, LateLintPass, LintContext};
88
use rustc_session::declare_lint_pass;
9+
use rustc_span::{FileName, RealFileName};
910

1011
declare_clippy_lint! {
1112
/// ### What it does
@@ -53,6 +54,17 @@ declare_lint_pass!(UseCratePrefixForSelfImports => [USE_CRATE_PREFIX_FOR_SELF_IM
5354

5455
impl 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

0 commit comments

Comments
 (0)