From 798f43da502e4b8d52e9b907420708d956faa054 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Jul 2020 15:44:37 +0200 Subject: [PATCH] Fix out of bounds panic in active parameter --- crates/ra_ide/src/call_info.rs | 4 ++++ crates/ra_ide/src/completion/presentation.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 14980afdd0..ff602202f2 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -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 }) diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index c7b74e6355..9a94ff4767 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -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(