6257: Don't suggest extracting out 1-tuple enum variants r=matklad a=repnop

Fixes #6241.

Co-authored-by: Wesley Norris <repnop@outlook.com>
This commit is contained in:
bors[bot] 2020-10-26 21:40:56 +00:00 committed by GitHub
commit 7f346f9ae1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) }");
}
}