aboutsummaryrefslogtreecommitdiff
path: root/crates/assists
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-26 21:40:56 +0000
committerGitHub <[email protected]>2020-10-26 21:40:56 +0000
commit7f346f9ae17ff9ebaeb24e5bfc4aa56f6ec13191 (patch)
tree1c6cc9763a333ba73c097956b926d4d90b05b163 /crates/assists
parentdb2c379baeeb2f676540368f89d77390c967541f (diff)
parentb9790a23bf4a424ad3ed71b95f36c2d639454381 (diff)
Merge #6257
6257: Don't suggest extracting out 1-tuple enum variants r=matklad a=repnop Fixes #6241. Co-authored-by: Wesley Norris <[email protected]>
Diffstat (limited to 'crates/assists')
-rw-r--r--crates/assists/src/handlers/extract_struct_from_enum_variant.rs22
1 files changed, 11 insertions, 11 deletions
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 48433feb9..178718c5e 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(
37 ast::StructKind::Tuple(field_list) => field_list, 37 ast::StructKind::Tuple(field_list) => field_list,
38 _ => return None, 38 _ => return None,
39 }; 39 };
40
41 // skip 1-tuple variants
42 if field_list.fields().count() == 1 {
43 return None;
44 }
45
40 let variant_name = variant.name()?.to_string(); 46 let variant_name = variant.name()?.to_string();
41 let variant_hir = ctx.sema.to_def(&variant)?; 47 let variant_hir = ctx.sema.to_def(&variant)?;
42 if existing_struct_def(ctx.db(), &variant_name, &variant_hir) { 48 if existing_struct_def(ctx.db(), &variant_name, &variant_hir) {
@@ -233,17 +239,6 @@ enum A { One(One) }"#,
233 } 239 }
234 240
235 #[test] 241 #[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
242enum A { One(One) }"#,
243 );
244 }
245
246 #[test]
247 fn test_extract_struct_pub_visibility() { 242 fn test_extract_struct_pub_visibility() {
248 check_assist( 243 check_assist(
249 extract_struct_from_enum_variant, 244 extract_struct_from_enum_variant,
@@ -324,4 +319,9 @@ fn another_fn() {
324 enum A { <|>One(u8) }"#, 319 enum A { <|>One(u8) }"#,
325 ); 320 );
326 } 321 }
322
323 #[test]
324 fn test_extract_not_applicable_one_field() {
325 check_not_applicable(r"enum A { <|>One(u32) }");
326 }
327} 327}