Skip to content

Commit 4b934bb

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

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ impl Clean<Vec<Item>> for doctree::Item<'_> {
19391939
use hir::ItemKind;
19401940

19411941
let item = self.hir_item;
1942-
let mut name = self.name().clone();
1942+
let mut name = self.name();
19431943
let def_id = item.def_id.to_def_id();
19441944

19451945
cx.with_param_env(def_id, |cx| {

src/librustdoc/doctree.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ impl<'hir> Item<'hir> {
2626
Self { hir_item, renamed_name, from_glob }
2727
}
2828

29-
pub(crate) fn name(&'hir self) -> &'hir Symbol {
30-
self.renamed_name.as_ref().unwrap_or(&self.hir_item.ident.name)
29+
pub(crate) fn name(&self) -> Symbol {
30+
self.renamed_name.unwrap_or(self.hir_item.ident.name)
3131
}
3232
}
3333

@@ -44,7 +44,7 @@ crate struct Module<'hir> {
4444
/// whether the module is from a glob import
4545
/// if `from_glob` is true and we see another module with same name,
4646
/// then this item can be replaced with that one
47-
pub(crate) from_glob: bool,
47+
crate from_glob: bool,
4848
}
4949

5050
impl Module<'hir> {
@@ -64,34 +64,30 @@ impl Module<'hir> {
6464
}
6565

6666
pub(crate) fn push_item(&mut self, new_item: Item<'hir>) {
67-
if let Some(existed_item) =
67+
if let Some(existing_item) =
6868
self.items.iter_mut().find(|item| item.name() == new_item.name())
6969
{
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;
74-
return;
75-
} else if new_item.from_glob {
76-
return;
77-
}
70+
if existing_item.from_glob {
71+
debug!("push_item: {:?} shadowed by {:?}", *existing_item, new_item);
72+
*existing_item = new_item;
73+
return;
74+
} else if new_item.from_glob {
75+
return;
7876
}
79-
} else {
80-
self.items.push(new_item);
8177
}
78+
self.items.push(new_item);
8279
}
8380

8481
pub(crate) fn push_mod(&mut self, new_item: Module<'hir>) {
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;
82+
if let Some(existing_mod) = self.mods.iter_mut().find(|mod_| mod_.name == new_item.name) {
83+
if existing_mod.from_glob {
84+
debug!("push_mod: {:?} shadowed by {:?}", existing_mod.name, new_item.name);
85+
*existing_mod = new_item;
8986
return;
9087
} else if new_item.from_glob {
9188
return;
9289
}
93-
} else {
94-
self.mods.push(new_item);
9590
}
91+
self.mods.push(new_item);
9692
}
9793
}

src/test/rustdoc/glob-shadowing.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// @has 'glob_shadowing/index.html'
22
// @count - '//tr[@class="module-item"]' 2
33
// @has - '//tr[@class="module-item"]' 'mod::prelude'
4+
// @!has - '//tr[@class="module-item"]' 'sub1::describe'
45
// @has - '//tr[@class="module-item"]' 'sub2::describe'
56

67
// @has 'glob_shadowing/fn.describe.html'
7-
// @has - '//div[@class='docblock']' 'sub2::describe'
8+
// @has - '//div[@class="docblock"]' 'sub2::describe'
89

910
mod sub1 {
1011
/// sub1::describe

0 commit comments

Comments
 (0)