Skip to content

Commit 4438017

Browse files
committed
Refactor
- Remove unnecessary references and derefs - Manual formatting
1 parent a6603fc commit 4438017

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

crates/hir-def/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl ModuleId {
128128
}
129129
}
130130

131-
/// An ID of a module, **local** to a specific crate
131+
/// An ID of a module, **local** to a `DefMap`.
132132
pub type LocalModuleId = Idx<nameres::ModuleData>;
133133

134134
#[derive(Debug)]

crates/hir-def/src/nameres.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl DefMap {
342342
}
343343

344344
pub(crate) fn block_id(&self) -> Option<BlockId> {
345-
self.block.as_ref().map(|block| block.block)
345+
self.block.map(|block| block.block)
346346
}
347347

348348
pub(crate) fn prelude(&self) -> Option<ModuleId> {
@@ -354,7 +354,7 @@ impl DefMap {
354354
}
355355

356356
pub fn module_id(&self, local_id: LocalModuleId) -> ModuleId {
357-
let block = self.block.as_ref().map(|b| b.block);
357+
let block = self.block.map(|b| b.block);
358358
ModuleId { krate: self.krate, local_id, block }
359359
}
360360

@@ -432,9 +432,9 @@ impl DefMap {
432432
/// Returns the module containing `local_mod`, either the parent `mod`, or the module containing
433433
/// the block, if `self` corresponds to a block expression.
434434
pub fn containing_module(&self, local_mod: LocalModuleId) -> Option<ModuleId> {
435-
match &self[local_mod].parent {
436-
Some(parent) => Some(self.module_id(*parent)),
437-
None => self.block.as_ref().map(|block| block.parent),
435+
match self[local_mod].parent {
436+
Some(parent) => Some(self.module_id(parent)),
437+
None => self.block.map(|block| block.parent),
438438
}
439439
}
440440

@@ -444,11 +444,11 @@ impl DefMap {
444444
let mut buf = String::new();
445445
let mut arc;
446446
let mut current_map = self;
447-
while let Some(block) = &current_map.block {
447+
while let Some(block) = current_map.block {
448448
go(&mut buf, current_map, "block scope", current_map.root);
449449
buf.push('\n');
450450
arc = block.parent.def_map(db);
451-
current_map = &*arc;
451+
current_map = &arc;
452452
}
453453
go(&mut buf, current_map, "crate", current_map.root);
454454
return buf;
@@ -472,10 +472,10 @@ impl DefMap {
472472
let mut buf = String::new();
473473
let mut arc;
474474
let mut current_map = self;
475-
while let Some(block) = &current_map.block {
475+
while let Some(block) = current_map.block {
476476
format_to!(buf, "{:?} in {:?}\n", block.block, block.parent);
477477
arc = block.parent.def_map(db);
478-
current_map = &*arc;
478+
current_map = &arc;
479479
}
480480

481481
format_to!(buf, "crate scope\n");

crates/hir-def/src/visibility.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
nameres::DefMap,
1212
path::{ModPath, PathKind},
1313
resolver::HasResolver,
14-
ConstId, FunctionId, HasModule, LocalFieldId, ModuleId, VariantId,
14+
ConstId, FunctionId, HasModule, LocalFieldId, LocalModuleId, ModuleId, VariantId,
1515
};
1616

1717
/// Visibility of an item, not yet resolved.
@@ -142,7 +142,8 @@ impl Visibility {
142142
arc = to_module.def_map(db);
143143
&arc
144144
};
145-
let is_block_root = matches!(to_module.block, Some(_) if to_module_def_map[to_module.local_id].parent.is_none());
145+
let is_block_root =
146+
to_module.block.is_some() && to_module_def_map[to_module.local_id].parent.is_none();
146147
if is_block_root {
147148
to_module = to_module_def_map.containing_module(to_module.local_id).unwrap();
148149
}

crates/hir/src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl HirDisplay for Function {
5050

5151
let write_self_param = |ty: &TypeRef, f: &mut HirFormatter<'_>| match ty {
5252
TypeRef::Path(p) if p.is_self_type() => f.write_str("self"),
53-
TypeRef::Reference(inner, lifetime, mut_) if matches!(&**inner,TypeRef::Path(p) if p.is_self_type()) =>
53+
TypeRef::Reference(inner, lifetime, mut_) if matches!(&**inner, TypeRef::Path(p) if p.is_self_type()) =>
5454
{
5555
f.write_char('&')?;
5656
if let Some(lifetime) = lifetime {

0 commit comments

Comments
 (0)