diff options
author | Aleksey Kladov <[email protected]> | 2020-07-17 14:44:37 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-17 14:44:37 +0100 |
commit | 798f43da502e4b8d52e9b907420708d956faa054 (patch) | |
tree | 8dd4ccf08afb5b1f0576242ba13d1d165c6bb3c3 /crates | |
parent | 23df3834333a4db1449b2ba52e878ade47d1dfb2 (diff) |
Fix out of bounds panic in active parameter
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/call_info.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 16 |
2 files changed, 20 insertions, 0 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 14980afdd..ff602202f 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs | |||
@@ -161,6 +161,10 @@ impl ActiveParameter { | |||
161 | 161 | ||
162 | let idx = active_parameter?; | 162 | let idx = active_parameter?; |
163 | let mut params = signature.params(sema.db); | 163 | let mut params = signature.params(sema.db); |
164 | if !(idx < params.len()) { | ||
165 | mark::hit!(too_many_arguments); | ||
166 | return None; | ||
167 | } | ||
164 | let (pat, ty) = params.swap_remove(idx); | 168 | let (pat, ty) = params.swap_remove(idx); |
165 | let name = pat?.to_string(); | 169 | let name = pat?.to_string(); |
166 | Some(ActiveParameter { ty, name }) | 170 | Some(ActiveParameter { ty, name }) |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index c7b74e635..9a94ff476 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -1160,6 +1160,22 @@ fn go(world: &WorldSnapshot) { go(w<|>) } | |||
1160 | } | 1160 | } |
1161 | 1161 | ||
1162 | #[test] | 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 | |||
1178 | #[test] | ||
1163 | fn guesses_macro_braces() { | 1179 | fn guesses_macro_braces() { |
1164 | check_edit( | 1180 | check_edit( |
1165 | "vec!", | 1181 | "vec!", |