From 9405116d51b2d078557873fafbf3d91f19d332a7 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 10 May 2020 16:27:31 +0800 Subject: [PATCH 1/2] Hot fix panic for function_signature --- .../ra_ide/src/display/function_signature.rs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index f16d42276482..3d31472543ed 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -84,8 +84,8 @@ impl FunctionSignature { let ty = field.signature_ty(db); let raw_param = format!("{}", ty.display(db)); - if let Some(param_type) = raw_param.split(':').nth(1) { - parameter_types.push(param_type[1..].to_string()); + if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { + parameter_types.push(param_type.to_string()); } else { // useful when you have tuple struct parameter_types.push(raw_param.clone()); @@ -129,8 +129,9 @@ impl FunctionSignature { for field in variant.fields(db).into_iter() { let ty = field.signature_ty(db); let raw_param = format!("{}", ty.display(db)); - if let Some(param_type) = raw_param.split(':').nth(1) { - parameter_types.push(param_type[1..].to_string()); + dbg!(&raw_param); + if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { + parameter_types.push(param_type.to_string()); } else { // The unwrap_or_else is useful when you have tuple parameter_types.push(raw_param); @@ -197,7 +198,12 @@ impl From<&'_ ast::FnDef> for FunctionSignature { let raw_param = self_param.syntax().text().to_string(); res_types.push( - raw_param.split(':').nth(1).unwrap_or_else(|| " Self")[1..].to_string(), + raw_param + .split(':') + .nth(1) + .and_then(|it| it.get(1..)) + .unwrap_or_else(|| "Self") + .to_string(), ); res.push(raw_param); } @@ -205,8 +211,8 @@ impl From<&'_ ast::FnDef> for FunctionSignature { res.extend(param_list.params().map(|param| param.syntax().text().to_string())); res_types.extend(param_list.params().map(|param| { let param_text = param.syntax().text().to_string(); - match param_text.split(':').nth(1) { - Some(it) => it[1..].to_string(), + match param_text.split(':').nth(1).and_then(|it| it.get(1..)) { + Some(it) => it.to_string(), None => param_text, } })); From a3375c1a88848195a7fd83d29acdab4029ca1459 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 10 May 2020 18:03:44 +0800 Subject: [PATCH 2/2] Remove dbg --- crates/ra_ide/src/display/function_signature.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 3d31472543ed..9572debd822c 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -129,7 +129,6 @@ impl FunctionSignature { for field in variant.fields(db).into_iter() { let ty = field.signature_ty(db); let raw_param = format!("{}", ty.display(db)); - dbg!(&raw_param); if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { parameter_types.push(param_type.to_string()); } else {