8000 Merge pull request #20729 from A4-Tacks/const-param-kwd · rust-lang/rust-analyzer@a55e2b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit a55e2b5

Browse files
authored
Merge pull request #20729 from A4-Tacks/const-param-kwd
Add const parameter keyword completion
2 parents e81202c + b39c7a8 commit a55e2b5

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

crates/ide-completion/src/completions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,9 @@ pub(super) fn complete_name(
691691
NameKind::RecordField => {
692692
field::complete_field_list_record_variant(acc, ctx);
693693
}
694+
NameKind::TypeParam => {
695+
acc.add_keyword_snippet(ctx, "const", "const $1: $0");
696+
}
694697
NameKind::ConstParam
695698
| NameKind::Enum
696699
| NameKind::MacroDef
@@ -700,7 +703,6 @@ pub(super) fn complete_name(
700703
| NameKind::Static
701704
| NameKind::Struct
702705
| NameKind::Trait
703-
| NameKind::TypeParam
704706
| NameKind::Union
705707
| NameKind::Variant => (),
706708
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,3 +1510,28 @@ fn foo<T>() {
15101510
"#]],
15111511
);
15121512
}
1513+
1514+
#[test]
1515+
fn fn_generic_params_const_param_snippet() {
1516+
check_edit("const", "fn foo<c$0>() {}", "fn foo<const $1: $0>() {}");
1517+
check_edit("const", "fn foo<T, c$0>() {}", "fn foo<T, const $1: $0>() {}");
1518+
check(
1519+
r#"
1520+
fn foo<T: $0>() {}
1521+
"#,
1522+
expect![[r#"
1523+
kw crate::
1524+
kw self::
1525+
"#]],
1526+
);
1527+
check(
1528+
r#"
1529+
fn foo<const N: $0>() {}
1530+
"#,
1531+
expect![[r#"
1532+
bt u32 u32
1533+
kw crate::
1534+
kw self::
1535+
"#]],
1536+
);
1537+
}

0 commit comments

Comments
 (0)
0