Skip to content

Commit ae41505

Browse files
bors[bot]matklad
andauthored
Merge #5424
5424: Fix out of bounds panic in active parameter r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 23df383 + 798f43d commit ae41505

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

crates/ra_ide/src/call_info.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ impl ActiveParameter {
161161

162162
let idx = active_parameter?;
163163
let mut params = signature.params(sema.db);
164+
if !(idx < params.len()) {
165+
mark::hit!(too_many_arguments);
166+
return None;
167+
}
164168
let (pat, ty) = params.swap_remove(idx);
165169
let name = pat?.to_string();
166170
Some(ActiveParameter { ty, name })

crates/ra_ide/src/completion/presentation.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,22 @@ fn go(world: &WorldSnapshot) { go(w<|>) }
11591159
);
11601160
}
11611161

1162+
#[test]
1163+
fn too_many_arguments() {
1164+
mark::check!(too_many_arguments);
1165+
check_scores(
1166+
r#"
1167+
struct Foo;
1168+
fn f(foo: &Foo) { f(foo, w<|>) }
1169+
"#,
1170+
expect![[r#"
1171+
st Foo []
1172+
fn f(…) []
1173+
bn foo []
1174+
"#]],
1175+
);
1176+
}
1177+
11621178
#[test]
11631179
fn guesses_macro_braces() {
11641180
check_edit(

0 commit comments

Comments
 (0)