From b9790a23bf4a424ad3ed71b95f36c2d639454381 Mon Sep 17 00:00:00 2001 From: Wesley Norris Date: Mon, 26 Oct 2020 17:38:23 -0400 Subject: Don't suggest extracting out 1-tuple enum variants Fixes #6241. --- .../handlers/extract_struct_from_enum_variant.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'crates/assists/src/handlers') diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 7f4f80b23..756aa03a2 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs @@ -37,6 +37,12 @@ pub(crate) fn extract_struct_from_enum_variant( ast::StructKind::Tuple(field_list) => field_list, _ => return None, }; + + // skip 1-tuple variants + if field_list.fields().count() == 1 { + return None; + } + let variant_name = variant.name()?.to_string(); let variant_hir = ctx.sema.to_def(&variant)?; if existing_struct_def(ctx.db(), &variant_name, &variant_hir) { @@ -228,17 +234,6 @@ mod tests { "enum A { <|>One(u32, u32) }", r#"struct One(pub u32, pub u32); -enum A { One(One) }"#, - ); - } - - #[test] - fn test_extract_struct_one_field() { - check_assist( - extract_struct_from_enum_variant, - "enum A { <|>One(u32) }", - r#"struct One(pub u32); - enum A { One(One) }"#, ); } @@ -324,4 +319,9 @@ fn another_fn() { enum A { <|>One(u8) }"#, ); } + + #[test] + fn test_extract_not_applicable_one_field() { + check_not_applicable(r"enum A { <|>One(u32) }"); + } } -- cgit v1.2.3