From c2dc32c48e8a7027390738b63e88fe220e4e56d9 Mon Sep 17 00:00:00 2001 From: harudagondi Date: Wed, 21 Sep 2022 09:11:02 +0800 Subject: [PATCH] return None instead of assert --- crates/ide-assists/src/handlers/unwrap_tuple.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/ide-assists/src/handlers/unwrap_tuple.rs b/crates/ide-assists/src/handlers/unwrap_tuple.rs index 171e9214a4e..25c58d086e9 100644 --- a/crates/ide-assists/src/handlers/unwrap_tuple.rs +++ b/crates/ide-assists/src/handlers/unwrap_tuple.rs @@ -44,10 +44,14 @@ pub(crate) fn unwrap_tuple(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option _ => return None, }; - stdx::always!( - tuple_pat.fields().count() == tuple_init.fields().count(), - "Length of tuples in pattern and initializer do not match" - ); + if tuple_pat.fields().count() != tuple_init.fields().count() { + return None; + } + if let Some(tys) = &tuple_ty { + if tuple_pat.fields().count() != tys.fields().count() { + return None; + } + } let parent = let_kw.parent()?; @@ -61,11 +65,6 @@ pub(crate) fn unwrap_tuple(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option // If there is an ascribed type, insert that type for each declaration, // otherwise, omit that type. if let Some(tys) = tuple_ty { - stdx::always!( - tuple_pat.fields().count() == tys.fields().count(), - "Length of tuples in patterns and type do not match" - ); - let mut zipped_decls = String::new(); for (pat, ty, expr) in itertools::izip!(tuple_pat.fields(), tys.fields(), tuple_init.fields())