Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir_def/src/visibility.rs')
-rw-r--r--crates/hir_def/src/visibility.rs32
1 files changed, 11 insertions, 21 deletions
diff --git a/crates/hir_def/src/visibility.rs b/crates/hir_def/src/visibility.rs
index 80009010c5..f76034a3e2 100644
--- a/crates/hir_def/src/visibility.rs
+++ b/crates/hir_def/src/visibility.rs
@@ -1,6 +1,6 @@
//! Defines hir-level representation of visibility (e.g. `pub` and `pub(crate)`).
-use std::sync::Arc;
+use std::{iter, sync::Arc};
use hir_expand::{hygiene::Hygiene, InFile};
use la_arena::ArenaMap;
@@ -25,7 +25,7 @@ pub enum RawVisibility {
}
impl RawVisibility {
- pub(crate) fn private() -> RawVisibility {
+ pub(crate) const fn private() -> RawVisibility {
RawVisibility::Module(ModPath::from_kind(PathKind::Super(0)))
}
@@ -113,10 +113,7 @@ impl Visibility {
}
pub(crate) fn is_visible_from_other_crate(self) -> bool {
- match self {
- Visibility::Module(_) => false,
- Visibility::Public => true,
- }
+ matches!(self, Visibility::Public)
}
pub(crate) fn is_visible_from_def_map(
@@ -145,10 +142,7 @@ impl Visibility {
arc = to_module.def_map(db);
&arc
};
- let is_block_root = match to_module.block {
- Some(_) => to_module_def_map[to_module.local_id].parent.is_none(),
- None => false,
- };
+ let is_block_root = matches!(to_module.block, Some(_) if to_module_def_map[to_module.local_id].parent.is_none());
if is_block_root {
to_module = to_module_def_map.containing_module(to_module.local_id).unwrap();
}
@@ -161,9 +155,7 @@ impl Visibility {
return true;
}
match def_map[from_module].parent {
- Some(parent) => {
- from_module = parent;
- }
+ Some(parent) => from_module = parent,
None => {
match def_map.parent() {
Some(module) => {
@@ -171,10 +163,8 @@ impl Visibility {
def_map = &*parent_arc;
from_module = module.local_id;
}
- None => {
- // Reached the root module, nothing left to check.
- return false;
- }
+ // Reached the root module, nothing left to check.
+ None => return false,
}
}
}
@@ -194,12 +184,12 @@ impl Visibility {
return None;
}
- let mut a_ancestors = std::iter::successors(Some(mod_a.local_id), |m| {
- let parent_id = def_map[*m].parent?;
+ let mut a_ancestors = iter::successors(Some(mod_a.local_id), |&m| {
+ let parent_id = def_map[m].parent?;
Some(parent_id)
});
- let mut b_ancestors = std::iter::successors(Some(mod_b.local_id), |m| {
- let parent_id = def_map[*m].parent?;
+ let mut b_ancestors = iter::successors(Some(mod_b.local_id), |&m| {
+ let parent_id = def_map[m].parent?;
Some(parent_id)
});