Refactor
- Remove unnecessary references and derefs - Manual formatting
This commit is contained in:
parent
a6603fc21d
commit
443801755c
@ -128,7 +128,7 @@ impl ModuleId {
|
||||
}
|
||||
}
|
||||
|
||||
/// An ID of a module, **local** to a specific crate
|
||||
/// An ID of a module, **local** to a `DefMap`.
|
||||
pub type LocalModuleId = Idx<nameres::ModuleData>;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -342,7 +342,7 @@ impl DefMap {
|
||||
}
|
||||
|
||||
pub(crate) fn block_id(&self) -> Option<BlockId> {
|
||||
self.block.as_ref().map(|block| block.block)
|
||||
self.block.map(|block| block.block)
|
||||
}
|
||||
|
||||
pub(crate) fn prelude(&self) -> Option<ModuleId> {
|
||||
@ -354,7 +354,7 @@ impl DefMap {
|
||||
}
|
||||
|
||||
pub fn module_id(&self, local_id: LocalModuleId) -> ModuleId {
|
||||
let block = self.block.as_ref().map(|b| b.block);
|
||||
let block = self.block.map(|b| b.block);
|
||||
ModuleId { krate: self.krate, local_id, block }
|
||||
}
|
||||
|
||||
@ -432,9 +432,9 @@ impl DefMap {
|
||||
/// Returns the module containing `local_mod`, either the parent `mod`, or the module containing
|
||||
/// the block, if `self` corresponds to a block expression.
|
||||
pub fn containing_module(&self, local_mod: LocalModuleId) -> Option<ModuleId> {
|
||||
match &self[local_mod].parent {
|
||||
Some(parent) => Some(self.module_id(*parent)),
|
||||
None => self.block.as_ref().map(|block| block.parent),
|
||||
match self[local_mod].parent {
|
||||
Some(parent) => Some(self.module_id(parent)),
|
||||
None => self.block.map(|block| block.parent),
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,11 +444,11 @@ impl DefMap {
|
||||
let mut buf = String::new();
|
||||
let mut arc;
|
||||
let mut current_map = self;
|
||||
while let Some(block) = ¤t_map.block {
|
||||
while let Some(block) = current_map.block {
|
||||
go(&mut buf, current_map, "block scope", current_map.root);
|
||||
buf.push('\n');
|
||||
arc = block.parent.def_map(db);
|
||||
current_map = &*arc;
|
||||
current_map = &arc;
|
||||
}
|
||||
go(&mut buf, current_map, "crate", current_map.root);
|
||||
return buf;
|
||||
@ -472,10 +472,10 @@ impl DefMap {
|
||||
let mut buf = String::new();
|
||||
let mut arc;
|
||||
let mut current_map = self;
|
||||
while let Some(block) = ¤t_map.block {
|
||||
while let Some(block) = current_map.block {
|
||||
format_to!(buf, "{:?} in {:?}\n", block.block, block.parent);
|
||||
arc = block.parent.def_map(db);
|
||||
current_map = &*arc;
|
||||
current_map = &arc;
|
||||
}
|
||||
|
||||
format_to!(buf, "crate scope\n");
|
||||
|
@ -11,7 +11,7 @@ use crate::{
|
||||
nameres::DefMap,
|
||||
path::{ModPath, PathKind},
|
||||
resolver::HasResolver,
|
||||
ConstId, FunctionId, HasModule, LocalFieldId, ModuleId, VariantId,
|
||||
ConstId, FunctionId, HasModule, LocalFieldId, LocalModuleId, ModuleId, VariantId,
|
||||
};
|
||||
|
||||
/// Visibility of an item, not yet resolved.
|
||||
@ -142,7 +142,8 @@ impl Visibility {
|
||||
arc = to_module.def_map(db);
|
||||
&arc
|
||||
};
|
||||
let is_block_root = matches!(to_module.block, Some(_) if to_module_def_map[to_module.local_id].parent.is_none());
|
||||
let is_block_root =
|
||||
to_module.block.is_some() && 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();
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ impl HirDisplay for Function {
|
||||
|
||||
let write_self_param = |ty: &TypeRef, f: &mut HirFormatter<'_>| match ty {
|
||||
TypeRef::Path(p) if p.is_self_type() => f.write_str("self"),
|
||||
TypeRef::Reference(inner, lifetime, mut_) if matches!(&**inner,TypeRef::Path(p) if p.is_self_type()) =>
|
||||
TypeRef::Reference(inner, lifetime, mut_) if matches!(&**inner, TypeRef::Path(p) if p.is_self_type()) =>
|
||||
{
|
||||
f.write_char('&')?;
|
||||
if let Some(lifetime) = lifetime {
|
||||
|
Loading…
x
Reference in New Issue
Block a user