From 6a2127be28a837215801f4ac3cd7d46ef7c4485b Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Thu, 2 Apr 2020 18:42:30 +0100 Subject: Cleanup checking for existing impls in impl From assist Use the trait solver to check if there's an existing implementation of From for the enum. --- .../ra_assists/src/handlers/add_from_impl_for_enum.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'crates/ra_assists/src') 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 @@ -use hir::ImplDef; use ra_syntax::{ ast::{self, AstNode, NameOwner}, TextUnit, @@ -99,18 +98,7 @@ fn already_has_from_impl( }; let var_ty = hir_enum_var.fields(sema.db)[0].signature_ty(sema.db); - let krate = match scope.module() { - Some(s) => s.krate(), - _ => return false, - }; - let impls = ImplDef::for_trait(sema.db, krate, from_trait); - let imp = impls.iter().find(|imp| { - let targets_enum = imp.target_ty(sema.db) == e_ty; - let param_matches = imp.target_trait_substs_matches(sema.db, &[var_ty.clone()]); - targets_enum && param_matches - }); - - imp.is_some() + e_ty.impls_trait(sema.db, from_trait, &[var_ty.clone()]) } #[cfg(test)] @@ -192,7 +180,7 @@ impl From for A { A::Two(v) } } - + pub trait From { fn from(T) -> Self; }"#, @@ -209,7 +197,7 @@ impl From for A { A::Two(v) } } - + pub trait From { fn from(T) -> Self; }"#, -- cgit v1.2.3