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

Commit d97a8ee

Browse files
committed
Remove superfluous early returns
1 parent 85b68b1 commit d97a8ee

File tree

8 files changed

+41
-59
lines changed

8 files changed

+41
-59
lines changed

crates/ide-completion/src/completions/attribute.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,15 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
8282
};
8383

8484
match qualified {
85-
Qualified::With { resolution, is_super_chain, .. } => {
85+
Qualified::With {
86+
resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),
87+
is_super_chain,
88+
..
89+
} => {
8690
if *is_super_chain {
8791
acc.add_keyword(ctx, "super::");
8892
}
8993

90-
let module = match resolution {
91-
Some(hir::PathResolution::Def(hir::ModuleDef::Module(it))) => it,
92-
_ => return,
93-
};
94-
9594
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
9695
if let Some(def) = module_or_attr(ctx.db, def) {
9796
acc.add_resolution(ctx, name, def);
@@ -110,7 +109,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
110109
});
111110
acc.add_nameref_keywords_with_colon(ctx);
112111
}
113-
Qualified::Infer => {}
112+
Qualified::Infer | Qualified::With { .. } => {}
114113
}
115114

116115
let attributes = annotated_item_kind.and_then(|kind| {

crates/ide-completion/src/completions/attribute/derive.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
2121
let core = ctx.famous_defs().core();
2222

2323
match qualified {
24-
Qualified::With { resolution, is_super_chain, .. } => {
24+
Qualified::With {
25+
resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),
26+
is_super_chain,
27+
..
28+
} => {
2529
if *is_super_chain {
2630
acc.add_keyword(ctx, "super::");
2731
}
2832

29-
let module = match resolution {
30-
Some(hir::PathResolution::Def(hir::ModuleDef::Module(it))) => it,
31-
_ => return,
32-
};
33-
3433
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
3534
let add_def = match def {
3635
ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac)) => {
@@ -101,7 +100,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
101100
});
102101
acc.add_nameref_keywords_with_colon(ctx);
103102
}
104-
Qualified::Infer => {}
103+
Qualified::Infer | Qualified::With { .. } => {}
105104
}
106105
}
107106

crates/ide-completion/src/completions/expr.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,8 @@ pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext)
6565
.into_iter()
6666
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
6767
.for_each(|item| add_assoc_item(acc, ctx, item)),
68-
Qualified::With { resolution, .. } => {
69-
let resolution = match resolution {
70-
Some(it) => it,
71-
None => return,
72-
};
68+
Qualified::With { resolution: None, .. } => {}
69+
Qualified::With { resolution: Some(resolution), .. } => {
7370
// Add associated types on type parameters and `Self`.
7471
ctx.scope.assoc_type_shorthand_candidates(resolution, |_, alias| {
7572
acc.add_type_alias(ctx, alias);

crates/ide-completion/src/completions/item_list.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
4444
}
4545

4646
match qualified {
47-
Qualified::With { resolution, is_super_chain, .. } => {
48-
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
49-
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
50-
if let Some(def) = module_or_fn_macro(ctx.db, def) {
51-
acc.add_resolution(ctx, name, def);
52-
}
47+
Qualified::With {
48+
resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),
49+
is_super_chain,
50+
..
51+
} => {
52+
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
53+
if let Some(def) = module_or_fn_macro(ctx.db, def) {
54+
acc.add_resolution(ctx, name, def);
5355
}
5456
}
5557

@@ -66,7 +68,7 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
6668
});
6769
acc.add_nameref_keywords_with_colon(ctx);
6870
}
69-
Qualified::Infer | Qualified::No => {}
71+
Qualified::Infer | Qualified::No | Qualified::With { .. } => {}
7072
}
7173
}
7274

crates/ide-completion/src/completions/pattern.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,11 @@ fn pattern_path_completion(
114114
PathCompletionCtx { qualified, .. }: &PathCompletionCtx,
115115
) {
116116
match qualified {
117-
Qualified::With { resolution, is_super_chain, .. } => {
117+
Qualified::With { resolution: Some(resolution), is_super_chain, .. } => {
118118
if *is_super_chain {
119119
acc.add_keyword(ctx, "super::");
120120
}
121121

122-
let resolution = match resolution {
123-
Some(it) => it,
124-
None => return,
125-
};
126-
127122
match resolution {
128123
hir::PathResolution::Def(hir::ModuleDef::Module(module)) => {
129124
let module_scope = module.scope(ctx.db, Some(ctx.module));
@@ -208,6 +203,6 @@ fn pattern_path_completion(
208203

209204
acc.add_nameref_keywords_with_colon(ctx);
210205
}
211-
Qualified::Infer => {}
206+
Qualified::Infer | Qualified::With { .. } => {}
212207
}
213208
}

crates/ide-completion/src/completions/type.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,8 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
5858
.into_iter()
5959
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
6060
.for_each(|item| add_assoc_item(acc, item)),
61-
Qualified::With { resolution, .. } => {
62-
let resolution = match resolution {
63-
Some(it) => it,
64-
None => return,
65-
};
61+
Qualified::With { resolution: None, .. } => {}
62+
Qualified::With { resolution: Some(resolution), .. } => {
6663
// Add associated types on type parameters and `Self`.
6764
ctx.scope.assoc_type_shorthand_candidates(resolution, |_, alias| {
6865
acc.add_type_alias(ctx, alias);

crates/ide-completion/src/completions/use_.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
2929
};
3030

3131
match qualified {
32-
Qualified::With { path, resolution, is_super_chain } => {
32+
Qualified::With { path, resolution: Some(resolution), is_super_chain } => {
3333
if *is_super_chain {
3434
acc.add_keyword(ctx, "super::");
3535
}
@@ -43,11 +43,6 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
4343
acc.add_keyword(ctx, "self");
4444
}
4545

46-
let resolution = match resolution {
47-
Some(it) => it,
48-
None => return,
49-
};
50-
5146
let mut already_imported_names = FxHashSet::default();
5247
if let Some(list) = ctx.token.parent_ancestors().find_map(ast::UseTreeList::cast) {
5348
let use_tree = list.parent_use_tree();
@@ -135,6 +130,6 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
135130
});
136131
acc.add_nameref_keywords_with_colon(ctx);
137132
}
138-
Qualified::Infer => {}
133+
Qualified::Infer | Qualified::With { resolution: None, .. } => {}
139134
}
140135
}

crates/ide-completion/src/completions/vis.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,26 @@ pub(crate) fn complete_vis_path(acc: &mut Completions, ctx: &CompletionContext)
1616
};
1717

1818
match qualified {
19-
Qualified::With { resolution, is_super_chain, .. } => {
19+
Qualified::With {
20+
resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),
21+
is_super_chain,
22+
..
23+
} => {
2024
// Try completing next child module of the path that is still a parent of the current module
21-
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
22-
let next_towards_current = ctx
23-
.module
24-
.path_to_root(ctx.db)
25-
.into_iter()
26-
.take_while(|it| it != module)
27-
.last();
28-
if let Some(next) = next_towards_current {
29-
if let Some(name) = next.name(ctx.db) {
30-
cov_mark::hit!(visibility_qualified);
31-
acc.add_resolution(ctx, name, ScopeDef::ModuleDef(next.into()));
32-
}
25+
let next_towards_current =
26+
ctx.module.path_to_root(ctx.db).into_iter().take_while(|it| it != module).last();
27+
if let Some(next) = next_towards_current {
28+
if let Some(name) = next.name(ctx.db) {
29+
cov_mark::hit!(visibility_qualified);
30+
acc.add_resolution(ctx, name, ScopeDef::ModuleDef(next.into()));
3331
}
3432
}
3533

3634
if *is_super_chain {
3735
acc.add_keyword(ctx, "super::");
3836
}
3937
}
40-
Qualified::Absolute | Qualified::Infer => {}
38+
Qualified::Absolute | Qualified::Infer | Qualified::With { .. } => {}
4139
Qualified::No => {
4240
if !has_in_token {
4341
cov_mark::hit!(kw_completion_in);

0 commit comments

Comments
 (0)