Skip to content

Commit d45be57

Browse files
committed
another test
1 parent 2546447 commit d45be57

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

clippy_lints/src/use_crate_prefix_for_self_imports.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,32 @@ impl<'a, 'tcx> LateLintPass<'tcx> for UseCratePrefixForSelfImports<'a, 'tcx> {
8080
_ => return,
8181
}
8282

83-
match self.use_block.last() {
84-
Some(prev_item) => {
85-
if item.span.lo() - prev_item.span.hi() == BytePos(1) {
86-
self.use_block.push(item);
87-
} else {
88-
self.deal(cx);
89-
self.use_block.clear();
90-
self.use_block.push(item);
91-
}
92-
},
93-
None => {
94-
self.use_block.push(item);
95-
},
83+
if self.in_same_block(item) {
84+
self.use_block.push(item);
85+
} else {
86+
self.deal(cx);
87+
self.use_block.clear();
88+
self.use_block.push(item);
9689
}
9790
}
9891
}
9992

10093
impl<'tcx> UseCratePrefixForSelfImports<'_, 'tcx> {
94+
fn in_same_block(&self, item: &Item<'tcx>) -> bool {
95+
if self.use_block.is_empty() {
96+
return true;
97+
}
98+
if self.use_block.iter().any(|x| x.span.contains(item.span)) {
99+
return true;
100+
}
101+
if let Some(prev_item) = self.use_block.last()
102+
&& item.span.lo() - prev_item.span.hi() == BytePos(1)
103+
{
104+
return true;
105+
}
106+
false
107+
}
108+
101109
fn deal(&self, cx: &LateContext<'tcx>) {
102110
let mod_names: FxHashSet<Symbol> = self
103111
.use_block
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "pass_sibling_3"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub struct Foo;
2+
pub struct Bar;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mod foo;
2+
pub use foo::{Bar, Foo};
3+
4+
fn main() {
5+
let _foo = Foo;
6+
let _bar = Bar;
7+
}

0 commit comments

Comments
 (0)