Skip to content

Commit 09cb285

Browse files
committed
apply some suggestions from code review
Signed-off-by: longfangsong <[email protected]>
1 parent 0005dc3 commit 09cb285

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/librustdoc/doctree.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,34 @@ impl Module<'hir> {
6464
}
6565

6666
pub(crate) fn push_item(&mut self, new_item: Item<'hir>) {
67-
for item_iter in self.items.iter_mut() {
68-
if item_iter.name() == new_item.name() {
69-
if item_iter.from_glob {
70-
debug!("push_item: {:?} shadowed by {:?}", *item_iter, new_item);
71-
*item_iter = new_item;
67+
if let Some(existed_item) =
68+
self.items.iter_mut().find(|item| item.name() == new_item.name())
69+
{
70+
if existed_item.name() == new_item.name() {
71+
if existed_item.from_glob {
72+
debug!("push_item: {:?} shadowed by {:?}", *existed_item, new_item);
73+
*existed_item = new_item;
7274
return;
7375
} else if new_item.from_glob {
7476
return;
7577
}
7678
}
79+
} else {
80+
self.items.push(new_item);
7781
}
78-
self.items.push(new_item);
7982
}
8083

8184
pub(crate) fn push_mod(&mut self, new_item: Module<'hir>) {
82-
if let Some(shadowed_mod) = self.mods.iter_mut().find(|mod_| mod_.name == new_item.name) {
83-
if item_iter.from_glob {
84-
debug!("push_mod: {:?} shadowed by {:?}", item_iter.name, new_item.name);
85-
*item_iter = new_item;
86-
return;
87-
} else if new_item.from_glob {
88-
return;
89-
}
85+
if let Some(existed_mod) = self.mods.iter_mut().find(|mod_| mod_.name == new_item.name) {
86+
if existed_mod.from_glob {
87+
debug!("push_mod: {:?} shadowed by {:?}", existed_mod.name, new_item.name);
88+
*existed_mod = new_item;
89+
return;
90+
} else if new_item.from_glob {
91+
return;
9092
}
93+
} else {
94+
self.mods.push(new_item);
9195
}
92-
self.mods.push(new_item);
9396
}
9497
}

src/test/rustdoc/glob-shadowing.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// @has - '//tr[@class="module-item"]' 'mod::prelude'
44
// @has - '//tr[@class="module-item"]' 'sub2::describe'
55

6+
// @has 'glob_shadowing/fn.describe.html'
7+
// @has - '//div[@class='docblock']' 'sub2::describe'
8+
69
mod sub1 {
710
/// sub1::describe
811
pub fn describe() -> &'static str {
@@ -23,12 +26,7 @@ mod sub2 {
2326
}
2427

2528
/// mod::prelude
26-
pub mod prelude {
27-
/// mod::prelude::describe
28-
pub fn describe() -> &'static str {
29-
"mod::describe"
30-
}
31-
}
29+
pub mod prelude {}
3230

3331
#[doc(inline)]
3432
pub use sub2::describe;

0 commit comments

Comments
 (0)