From 739edfd5cf6d1f5ac1ec6dbc28fc7943b3936e24 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 15 Apr 2021 23:31:42 +0300 Subject: Exclude inherent traits from flyimports --- crates/hir/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/hir/src') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index eba46a056..0acfa582a 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -2066,6 +2066,18 @@ impl Type { self.ty.dyn_trait().map(Into::into) } + /// If a type can be represented as `dyn Trait`, returns all traits accessible via this type, + /// or an empty iterator otherwise. + pub fn applicable_inherent_traits<'a>( + &'a self, + db: &'a dyn HirDatabase, + ) -> impl Iterator + 'a { + self.autoderef(db) + .filter_map(|derefed_type| derefed_type.ty.dyn_trait()) + .flat_map(move |dyn_trait_id| hir_ty::all_super_traits(db.upcast(), dyn_trait_id)) + .map(Trait::from) + } + pub fn as_impl_traits(&self, db: &dyn HirDatabase) -> Option> { self.ty.impl_trait_bounds(db).map(|it| { it.into_iter() -- cgit v1.2.3