From e63116c74f79a7909998b27615a308268f9093d6 Mon Sep 17 00:00:00 2001 From: Domantas Jadenkus Date: Sat, 13 Feb 2021 14:29:26 +0200 Subject: allow any field type --- .../src/handlers/generate_from_impl_for_enum.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'crates/assists') diff --git a/crates/assists/src/handlers/generate_from_impl_for_enum.rs b/crates/assists/src/handlers/generate_from_impl_for_enum.rs index 71897e6eb..ac9806368 100644 --- a/crates/assists/src/handlers/generate_from_impl_for_enum.rs +++ b/crates/assists/src/handlers/generate_from_impl_for_enum.rs @@ -34,10 +34,6 @@ pub(crate) fn generate_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext return None; } let field_type = field_list.fields().next()?.ty()?; - let path = match field_type { - ast::Type::PathType(it) => it, - _ => return None, - }; if existing_from_impl(&ctx.sema, &variant).is_some() { mark::hit!(test_add_from_impl_already_exists); @@ -59,7 +55,7 @@ impl From<{0}> for {1} {{ Self::{2}(v) }} }}"#, - path.syntax(), + field_type.syntax(), enum_name, variant_name ); @@ -195,6 +191,21 @@ impl From for A { pub trait From { fn from(T) -> Self; +}"#, + ); + } + + #[test] + fn test_add_from_impl_static_str() { + check_assist( + generate_from_impl_for_enum, + "enum A { $0One(&'static str) }", + r#"enum A { One(&'static str) } + +impl From<&'static str> for A { + fn from(v: &'static str) -> Self { + Self::One(v) + } }"#, ); } -- cgit v1.2.3