Skip to content

Commit 1f5f4cc

Browse files
bors[bot]Veykril
andauthored
Merge #11539
11539: minor: Simplify r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 789f2b9 + ffeec9d commit 1f5f4cc

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

crates/hir_def/src/nameres/collector.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,8 +1701,9 @@ impl ModCollector<'_, '_> {
17011701
{
17021702
Ok((file_id, is_mod_rs, mod_dir)) => {
17031703
let item_tree = db.file_item_tree(file_id.into());
1704+
let krate = self.def_collector.def_map.krate;
17041705
let is_enabled = item_tree
1705-
.top_level_attrs(db, self.def_collector.def_map.krate)
1706+
.top_level_attrs(db, krate)
17061707
.cfg()
17071708
.map_or(true, |cfg| self.is_cfg_enabled(&cfg));
17081709
if is_enabled {
@@ -1713,7 +1714,7 @@ impl ModCollector<'_, '_> {
17131714
&self.item_tree[module.visibility],
17141715
);
17151716
ModCollector {
1716-
def_collector: &mut *self.def_collector,
1717+
def_collector: self.def_collector,
17171718
macro_depth: self.macro_depth,
17181719
module_id,
17191720
tree_id: TreeId::new(file_id.into(), None),
@@ -1723,7 +1724,7 @@ impl ModCollector<'_, '_> {
17231724
.collect_in_top_module(item_tree.top_level_items());
17241725
let is_macro_use = is_macro_use
17251726
|| item_tree
1726-
.top_level_attrs(db, self.def_collector.def_map.krate)
1727+
.top_level_attrs(db, krate)
17271728
.by_key("macro_use")
17281729
.exists();
17291730
if is_macro_use {
@@ -1748,12 +1749,11 @@ impl ModCollector<'_, '_> {
17481749
definition: Option<(FileId, bool)>,
17491750
visibility: &crate::visibility::RawVisibility,
17501751
) -> LocalModuleId {
1751-
let vis = self
1752-
.def_collector
1753-
.def_map
1752+
let def_map = &mut self.def_collector.def_map;
1753+
let vis = def_map
17541754
.resolve_visibility(self.def_collector.db, self.module_id, visibility)
17551755
.unwrap_or(Visibility::Public);
1756-
let modules = &mut self.def_collector.def_map.modules;
1756+
let modules = &mut def_map.modules;
17571757
let origin = match definition {
17581758
None => ModuleOrigin::Inline { definition: declaration },
17591759
Some((definition, is_mod_rs)) => {
@@ -1768,10 +1768,10 @@ impl ModCollector<'_, '_> {
17681768
}
17691769
modules[self.module_id].children.insert(name.clone(), res);
17701770

1771-
let module = self.def_collector.def_map.module_id(res);
1771+
let module = def_map.module_id(res);
17721772
let def = ModuleDefId::from(module);
17731773

1774-
self.def_collector.def_map.modules[self.module_id].scope.declare(def);
1774+
def_map.modules[self.module_id].scope.declare(def);
17751775
self.def_collector.update(
17761776
self.module_id,
17771777
&[(Some(name), PerNs::from_def(def, vis, false))],

crates/hir_def/src/visibility.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Defines hir-level representation of visibility (e.g. `pub` and `pub(crate)`).
22
3-
use std::sync::Arc;
3+
use std::{iter, sync::Arc};
44

55
use hir_expand::{hygiene::Hygiene, InFile};
66
use la_arena::ArenaMap;
@@ -25,7 +25,7 @@ pub enum RawVisibility {
2525
}
2626

2727
impl RawVisibility {
28-
pub(crate) fn private() -> RawVisibility {
28+
pub(crate) const fn private() -> RawVisibility {
2929
RawVisibility::Module(ModPath::from_kind(PathKind::Super(0)))
3030
}
3131

@@ -113,10 +113,7 @@ impl Visibility {
113113
}
114114

115115
pub(crate) fn is_visible_from_other_crate(self) -> bool {
116-
match self {
117-
Visibility::Module(_) => false,
118-
Visibility::Public => true,
119-
}
116+
matches!(self, Visibility::Public)
120117
}
121118

122119
pub(crate) fn is_visible_from_def_map(
@@ -145,10 +142,7 @@ impl Visibility {
145142
arc = to_module.def_map(db);
146143
&arc
147144
};
148-
let is_block_root = match to_module.block {
149-
Some(_) => to_module_def_map[to_module.local_id].parent.is_none(),
150-
None => false,
151-
};
145+
let is_block_root = matches!(to_module.block, Some(_) if to_module_def_map[to_module.local_id].parent.is_none());
152146
if is_block_root {
153147
to_module = to_module_def_map.containing_module(to_module.local_id).unwrap();
154148
}
@@ -161,20 +155,16 @@ impl Visibility {
161155
return true;
162156
}
163157
match def_map[from_module].parent {
164-
Some(parent) => {
165-
from_module = parent;
166-
}
158+
Some(parent) => from_module = parent,
167159
None => {
168160
match def_map.parent() {
169161
Some(module) => {
170162
parent_arc = module.def_map(db);
171163
def_map = &*parent_arc;
172164
from_module = module.local_id;
173165
}
174-
None => {
175-
// Reached the root module, nothing left to check.
176-
return false;
177-
}
166+
// Reached the root module, nothing left to check.
167+
None => return false,
178168
}
179169
}
180170
}
@@ -194,12 +184,12 @@ impl Visibility {
194184
return None;
195185
}
196186

197-
let mut a_ancestors = std::iter::successors(Some(mod_a.local_id), |m| {
198-
let parent_id = def_map[*m].parent?;
187+
let mut a_ancestors = iter::successors(Some(mod_a.local_id), |&m| {
188+
let parent_id = def_map[m].parent?;
199189
Some(parent_id)
200190
});
201-
let mut b_ancestors = std::iter::successors(Some(mod_b.local_id), |m| {
202-
let parent_id = def_map[*m].parent?;
191+
let mut b_ancestors = iter::successors(Some(mod_b.local_id), |&m| {
192+
let parent_id = def_map[m].parent?;
203193
Some(parent_id)
204194
});
205195

0 commit comments

Comments
 (0)