5424: Fix out of bounds panic in active parameter r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-17 13:45:25 +00:00 committed by GitHub
commit ae41505cad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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(