Skip to content

Commit b9790a2

Browse files
committed
Don't suggest extracting out 1-tuple enum variants
Fixes #6241.
1 parent f0412da commit b9790a2

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

crates/assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ pub(crate) fn extract_struct_from_enum_variant(
3737
ast::StructKind::Tuple(field_list) => field_list,
3838
_ => return None,
3939
};
40+
41+
// skip 1-tuple variants
42+
if field_list.fields().count() == 1 {
43+
return None;
44+
}
45+
4046
let variant_name = variant.name()?.to_string();
4147
let variant_hir = ctx.sema.to_def(&variant)?;
4248
if existing_struct_def(ctx.db(), &variant_name, &variant_hir) {
@@ -228,17 +234,6 @@ mod tests {
228234
"enum A { <|>One(u32, u32) }",
229235
r#"struct One(pub u32, pub u32);
230236
231-
enum A { One(One) }"#,
232-
);
233-
}
234-
235-
#[test]
236-
fn test_extract_struct_one_field() {
237-
check_assist(
238-
extract_struct_from_enum_variant,
239-
"enum A { <|>One(u32) }",
240-
r#"struct One(pub u32);
241-
242237
enum A { One(One) }"#,
243238
);
244239
}
@@ -324,4 +319,9 @@ fn another_fn() {
324319
enum A { <|>One(u8) }"#,
325320
);
326321
}
322+
323+
#[test]
324+
fn test_extract_not_applicable_one_field() {
325+
check_not_applicable(r"enum A { <|>One(u32) }");
326+
}
327327
}

0 commit comments

Comments
 (0)