diff options
Diffstat (limited to 'crates/assists')
-rw-r--r-- | crates/assists/src/handlers/generate_from_impl_for_enum.rs | 21 |
1 files changed, 16 insertions, 5 deletions
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 | |||
34 | return None; | 34 | return None; |
35 | } | 35 | } |
36 | let field_type = field_list.fields().next()?.ty()?; | 36 | let field_type = field_list.fields().next()?.ty()?; |
37 | let path = match field_type { | ||
38 | ast::Type::PathType(it) => it, | ||
39 | _ => return None, | ||
40 | }; | ||
41 | 37 | ||
42 | if existing_from_impl(&ctx.sema, &variant).is_some() { | 38 | if existing_from_impl(&ctx.sema, &variant).is_some() { |
43 | mark::hit!(test_add_from_impl_already_exists); | 39 | mark::hit!(test_add_from_impl_already_exists); |
@@ -59,7 +55,7 @@ impl From<{0}> for {1} {{ | |||
59 | Self::{2}(v) | 55 | Self::{2}(v) |
60 | }} | 56 | }} |
61 | }}"#, | 57 | }}"#, |
62 | path.syntax(), | 58 | field_type.syntax(), |
63 | enum_name, | 59 | enum_name, |
64 | variant_name | 60 | variant_name |
65 | ); | 61 | ); |
@@ -198,4 +194,19 @@ pub trait From<T> { | |||
198 | }"#, | 194 | }"#, |
199 | ); | 195 | ); |
200 | } | 196 | } |
197 | |||
198 | #[test] | ||
199 | fn test_add_from_impl_static_str() { | ||
200 | check_assist( | ||
201 | generate_from_impl_for_enum, | ||
202 | "enum A { $0One(&'static str) }", | ||
203 | r#"enum A { One(&'static str) } | ||
204 | |||
205 | impl From<&'static str> for A { | ||
206 | fn from(v: &'static str) -> Self { | ||
207 | Self::One(v) | ||
208 | } | ||
209 | }"#, | ||
210 | ); | ||
211 | } | ||
201 | } | 212 | } |