Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0df70d3

Browse files
committed
Minor refactoring
1 parent b75803a commit 0df70d3

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

crates/hir/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,15 +3139,15 @@ impl Type {
31393139
}
31403140

31413141
pub fn is_closure(&self) -> bool {
3142-
matches!(&self.ty.kind(Interner), TyKind::Closure { .. })
3142+
matches!(self.ty.kind(Interner), TyKind::Closure { .. })
31433143
}
31443144

31453145
pub fn is_fn(&self) -> bool {
3146-
matches!(&self.ty.kind(Interner), TyKind::FnDef(..) | TyKind::Function { .. })
3146+
matches!(self.ty.kind(Interner), TyKind::FnDef(..) | TyKind::Function { .. })
31473147
}
31483148

31493149
pub fn is_array(&self) -> bool {
3150-
matches!(&self.ty.kind(Interner), TyKind::Array(..))
3150+
matches!(self.ty.kind(Interner), TyKind::Array(..))
31513151
}
31523152

31533153
pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
@@ -3164,7 +3164,7 @@ impl Type {
31643164
}
31653165

31663166
pub fn is_raw_ptr(&self) -> bool {
3167-
matches!(&self.ty.kind(Interner), TyKind::Raw(..))
3167+
matches!(self.ty.kind(Interner), TyKind::Raw(..))
31683168
}
31693169

31703170
pub fn contains_unknown(&self) -> bool {

crates/hir/src/semantics.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,10 +1319,7 @@ impl<'db> SemanticsImpl<'db> {
13191319
let _p = profile::span("Semantics::analyze_impl");
13201320
let node = self.find_file(node);
13211321

1322-
let container = match self.with_ctx(|ctx| ctx.find_container(node)) {
1323-
Some(it) => it,
1324-
None => return None,
1325-
};
1322+
let container = self.with_ctx(|ctx| ctx.find_container(node))?;
13261323

13271324
let resolver = match container {
13281325
ChildContainer::DefWithBodyId(def) => {
@@ -1582,7 +1579,7 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode {
15821579
node.ancestors().last().unwrap()
15831580
}
15841581

1585-
/// `SemanticScope` encapsulates the notion of a scope (the set of visible
1582+
/// `SemanticsScope` encapsulates the notion of a scope (the set of visible
15861583
/// names) at a particular program point.
15871584
///
15881585
/// It is a bit tricky, as scopes do not really exist inside the compiler.

crates/ide-assists/src/handlers/generate_function.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use syntax::{
1616
};
1717

1818
use crate::{
19-
utils::convert_reference_type,
20-
utils::{find_struct_impl, render_snippet, Cursor},
19+
utils::{convert_reference_type, find_struct_impl, render_snippet, Cursor},
2120
AssistContext, AssistId, AssistKind, Assists,
2221
};
2322

@@ -107,7 +106,7 @@ fn fn_target_info(
107106
match path.qualifier() {
108107
Some(qualifier) => match ctx.sema.resolve_path(&qualifier) {
109108
Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) => {
110-
get_fn_target_info(ctx, &Some(module), call.clone())
109+
get_fn_target_info(ctx, Some(module), call.clone())
111110
}
112111
Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) => {
113112
if let hir::Adt::Enum(_) = adt {
@@ -125,7 +124,7 @@ fn fn_target_info(
125124
}
126125
_ => None,
127126
},
128-
_ => get_fn_target_info(ctx, &None, call.clone()),
127+
_ => get_fn_target_info(ctx, None, call.clone()),
129128
}
130129
}
131130

@@ -396,16 +395,16 @@ fn make_return_type(
396395

397396
fn get_fn_target_info(
398397
ctx: &AssistContext<'_>,
399-
target_module: &Option<Module>,
398+
target_module: Option<Module>,
400399
call: CallExpr,
401400
) -> Option<TargetInfo> {
402401
let (target, file, insert_offset) = get_fn_target(ctx, target_module, call)?;
403-
Some(TargetInfo::new(*target_module, None, target, file, insert_offset))
402+
Some(TargetInfo::new(target_module, None, target, file, insert_offset))
404403
}
405404

406405
fn get_fn_target(
407406
ctx: &AssistContext<'_>,
408-
target_module: &Option<Module>,
407+
target_module: Option<Module>,
409408
call: CallExpr,
410409
) -> Option<(GeneratedFunctionTarget, FileId, TextSize)> {
411410
let mut file = ctx.file_id();
@@ -640,10 +639,11 @@ fn next_space_for_fn_in_module(
640639
}
641640

642641
fn next_space_for_fn_in_impl(impl_: &ast::Impl) -> Option<GeneratedFunctionTarget> {
643-
if let Some(last_item) = impl_.assoc_item_list().and_then(|it| it.assoc_items().last()) {
642+
let assoc_item_list = impl_.assoc_item_list()?;
643+
if let Some(last_item) = assoc_item_list.assoc_items().last() {
644644
Some(GeneratedFunctionTarget::BehindItem(last_item.syntax().clone()))
645645
} else {
646-
Some(GeneratedFunctionTarget::InEmptyItemList(impl_.assoc_item_list()?.syntax().clone()))
646+
Some(GeneratedFunctionTarget::InEmptyItemList(assoc_item_list.syntax().clone()))
647647
}
648648
}
649649

0 commit comments

Comments
 (0)