Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/lib.rs')
| -rw-r--r-- | crates/hir/src/lib.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index ef17f2a75e..96424d087e 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -41,6 +41,7 @@ use hir_def::{ adt::{ReprKind, VariantData}, body::{BodyDiagnostic, SyntheticSyntax}, expr::{BindingAnnotation, LabelId, Pat, PatId}, + generics::{TypeOrConstParamData, TypeParamProvenance}, item_tree::ItemTreeNode, lang_item::LangItemTarget, nameres::{self, diagnostics::DefDiagnostic}, @@ -1707,6 +1708,26 @@ impl Trait { pub fn is_unsafe(&self, db: &dyn HirDatabase) -> bool { db.trait_data(self.id).is_unsafe } + + pub fn type_or_const_param_count( + &self, + db: &dyn HirDatabase, + count_required_only: bool, + ) -> usize { + db.generic_params(GenericDefId::from(self.id)) + .type_or_consts + .iter() + .filter(|(_, ty)| match ty { + TypeOrConstParamData::TypeParamData(ty) + if ty.provenance != TypeParamProvenance::TypeParamList => + { + false + } + _ => true, + }) + .filter(|(_, ty)| !count_required_only || !ty.has_default()) + .count() + } } impl HasVisibility for Trait { |