Skip to content

Commit 313a480

Browse files
committed
Auto merge of rust-lang#14110 - dqkqd:auto-completion-for-missing-body, r=Veykril
Add completion for function without body Fix rust-lang#13802
2 parents eaed19c + 74cd8ec commit 313a480

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

crates/ide-completion/src/context/analysis.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,10 @@ fn classify_name_ref(
675675
{
676676
if let Some(item) = ast::Item::cast(n) {
677677
let is_inbetween = match &item {
678-
ast::Item::Const(it) => it.body().is_none(),
678+
ast::Item::Const(it) => it.body().is_none() && it.semicolon_token().is_none(),
679679
ast::Item::Enum(it) => it.variant_list().is_none(),
680680
ast::Item::ExternBlock(it) => it.extern_item_list().is_none(),
681-
ast::Item::Fn(it) => it.body().is_none(),
681+
ast::Item::Fn(it) => it.body().is_none() && it.semicolon_token().is_none(),
682682
ast::Item::Impl(it) => it.assoc_item_list().is_none(),
683683
ast::Item::Module(it) => {
684684
it.item_list().is_none() && it.semicolon_token().is_none()
@@ -688,7 +688,7 @@ fn classify_name_ref(
688688
it.field_list().is_none() && it.semicolon_token().is_none()
689689
}
690690
ast::Item::Trait(it) => it.assoc_item_list().is_none(),
691-
ast::Item::TypeAlias(it) => it.ty().is_none(),
691+
ast::Item::TypeAlias(it) => it.ty().is_none() && it.semicolon_token().is_none(),
692692
ast::Item::Union(it) => it.record_field_list().is_none(),
693693
_ => false,
694694
};

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,57 @@ fn in_trait_assoc_item_list() {
214214
);
215215
}
216216

217+
#[test]
218+
fn in_trait_assoc_fn_missing_body() {
219+
check(
220+
r#"trait Foo { fn function(); $0 }"#,
221+
expect![[r#"
222+
ma makro!(…) macro_rules! makro
223+
md module
224+
kw const
225+
kw crate::
226+
kw fn
227+
kw self::
228+
kw type
229+
kw unsafe
230+
"#]],
231+
);
232+
}
233+
234+
#[test]
235+
fn in_trait_assoc_const_missing_body() {
236+
check(
237+
r#"trait Foo { const CONST: (); $0 }"#,
238+
expect![[r#"
239+
ma makro!(…) macro_rules! makro
240+
md module
241+
kw const
242+
kw crate::
243+
kw fn
244+
kw self::
245+
kw type
246+
kw unsafe
247+
"#]],
248+
);
249+
}
250+
251+
#[test]
252+
fn in_trait_assoc_type_aliases_missing_ty() {
253+
check(
254+
r#"trait Foo { type Type; $0 }"#,
255+
expect![[r#"
256+
ma makro!(…) macro_rules! makro
257+
md module
258+
kw const
259+
kw crate::
260+
kw fn
261+
kw self::
262+
kw type
263+
kw unsafe
264+
"#]],
265+
);
266+
}
267+
217268
#[test]
218269
fn in_trait_impl_assoc_item_list() {
219270
check(

0 commit comments

Comments
 (0)