aboutsummaryrefslogtreecommitdiff
path: root/crates/assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists')
-rw-r--r--crates/assists/src/handlers/extract_struct_from_enum_variant.rs22
-rw-r--r--crates/assists/src/lib.rs5
2 files changed, 14 insertions, 13 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}
diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs
index 70a651e10..b804e495d 100644
--- a/crates/assists/src/lib.rs
+++ b/crates/assists/src/lib.rs
@@ -200,7 +200,6 @@ mod handlers {
200 move_guard::move_guard_to_arm_body, 200 move_guard::move_guard_to_arm_body,
201 qualify_path::qualify_path, 201 qualify_path::qualify_path,
202 raw_string::add_hash, 202 raw_string::add_hash,
203 raw_string::make_raw_string,
204 raw_string::make_usual_string, 203 raw_string::make_usual_string,
205 raw_string::remove_hash, 204 raw_string::remove_hash,
206 remove_dbg::remove_dbg, 205 remove_dbg::remove_dbg,
@@ -211,13 +210,15 @@ mod handlers {
211 replace_impl_trait_with_generic::replace_impl_trait_with_generic, 210 replace_impl_trait_with_generic::replace_impl_trait_with_generic,
212 replace_let_with_if_let::replace_let_with_if_let, 211 replace_let_with_if_let::replace_let_with_if_let,
213 replace_qualified_name_with_use::replace_qualified_name_with_use, 212 replace_qualified_name_with_use::replace_qualified_name_with_use,
214 replace_string_with_char::replace_string_with_char,
215 replace_unwrap_with_match::replace_unwrap_with_match, 213 replace_unwrap_with_match::replace_unwrap_with_match,
216 split_import::split_import, 214 split_import::split_import,
217 unwrap_block::unwrap_block, 215 unwrap_block::unwrap_block,
218 // These are manually sorted for better priorities 216 // These are manually sorted for better priorities
219 add_missing_impl_members::add_missing_impl_members, 217 add_missing_impl_members::add_missing_impl_members,
220 add_missing_impl_members::add_missing_default_members, 218 add_missing_impl_members::add_missing_default_members,
219 //
220 replace_string_with_char::replace_string_with_char,
221 raw_string::make_raw_string,
221 // Are you sure you want to add new assist here, and not to the 222 // Are you sure you want to add new assist here, and not to the
222 // sorted list above? 223 // sorted list above?
223 ] 224 ]