aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
authorMatthew Hall <[email protected]>2020-04-02 18:42:30 +0100
committerMatthew Hall <[email protected]>2020-04-02 18:42:30 +0100
commit6a2127be28a837215801f4ac3cd7d46ef7c4485b (patch)
tree2bacfb7f92c7059a5975fd5f256122b08190f93d /crates/ra_assists
parent1fee60181fea56ebe6b5e4aeb11cf9df25a1d087 (diff)
Cleanup checking for existing impls in impl From assist
Use the trait solver to check if there's an existing implementation of From<type_in_enum_variant> for the enum.
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/handlers/add_from_impl_for_enum.rs18
1 files changed, 3 insertions, 15 deletions
diff --git a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
index cf94a214a..864373aa5 100644
--- a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
+++ b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
@@ -1,4 +1,3 @@
1use hir::ImplDef;
2use ra_syntax::{ 1use ra_syntax::{
3 ast::{self, AstNode, NameOwner}, 2 ast::{self, AstNode, NameOwner},
4 TextUnit, 3 TextUnit,
@@ -99,18 +98,7 @@ fn already_has_from_impl(
99 }; 98 };
100 let var_ty = hir_enum_var.fields(sema.db)[0].signature_ty(sema.db); 99 let var_ty = hir_enum_var.fields(sema.db)[0].signature_ty(sema.db);
101 100
102 let krate = match scope.module() { 101 e_ty.impls_trait(sema.db, from_trait, &[var_ty.clone()])
103 Some(s) => s.krate(),
104 _ => return false,
105 };
106 let impls = ImplDef::for_trait(sema.db, krate, from_trait);
107 let imp = impls.iter().find(|imp| {
108 let targets_enum = imp.target_ty(sema.db) == e_ty;
109 let param_matches = imp.target_trait_substs_matches(sema.db, &[var_ty.clone()]);
110 targets_enum && param_matches
111 });
112
113 imp.is_some()
114} 102}
115 103
116#[cfg(test)] 104#[cfg(test)]
@@ -192,7 +180,7 @@ impl From<String> for A {
192 A::Two(v) 180 A::Two(v)
193 } 181 }
194} 182}
195 183
196pub trait From<T> { 184pub trait From<T> {
197 fn from(T) -> Self; 185 fn from(T) -> Self;
198}"#, 186}"#,
@@ -209,7 +197,7 @@ impl From<String> for A {
209 A::Two(v) 197 A::Two(v)
210 } 198 }
211} 199}
212 200
213pub trait From<T> { 201pub trait From<T> {
214 fn from(T) -> Self; 202 fn from(T) -> Self;
215}"#, 203}"#,