mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 00:47:18 +00:00
Merge #6257
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:
commit
7f346f9ae1
1 changed files with 11 additions and 11 deletions
|
@ -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) }");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue