Fix out of bounds panic in active parameter

This commit is contained in:
Aleksey Kladov 2020-07-17 15:44:37 +02:00
parent 23df383433
commit 798f43da50
2 changed files with 20 additions and 0 deletions

View file

@ -161,6 +161,10 @@ impl ActiveParameter {
let idx = active_parameter?;
let mut params = signature.params(sema.db);
if !(idx < params.len()) {
mark::hit!(too_many_arguments);
return None;
}
let (pat, ty) = params.swap_remove(idx);
let name = pat?.to_string();
Some(ActiveParameter { ty, name })

View file

@ -1159,6 +1159,22 @@ fn go(world: &WorldSnapshot) { go(w<|>) }
);
}
#[test]
fn too_many_arguments() {
mark::check!(too_many_arguments);
check_scores(
r#"
struct Foo;
fn f(foo: &Foo) { f(foo, w<|>) }
"#,
expect![[r#"
st Foo []
fn f() []
bn foo []
"#]],
);
}
#[test]
fn guesses_macro_braces() {
check_edit(