From 6f51f728a114078a0c3a029fc66cfb8c4daf9a28 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 1 Dec 2020 13:53:12 +0300 Subject: Type-safer API for dealing with parameter lists with optional self --- crates/hir/src/code_model.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index f06b5cd9f..ba121104b 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -744,14 +744,13 @@ impl Function { Some(SelfParam { func: self.id }) } - pub fn params(self, db: &dyn HirDatabase) -> Vec { + pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec { let resolver = self.id.resolver(db.upcast()); let ctx = hir_ty::TyLoweringContext::new(db, &resolver); let environment = TraitEnvironment::lower(db, &resolver); db.function_data(self.id) .params .iter() - .skip(if self.self_param(db).is_some() { 1 } else { 0 }) .map(|type_ref| { let ty = Type { krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, @@ -764,6 +763,14 @@ impl Function { }) .collect() } + pub fn method_params(self, db: &dyn HirDatabase) -> Option> { + if self.self_param(db).is_none() { + return None; + } + let mut res = self.assoc_fn_params(db); + res.remove(0); + Some(res) + } pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool { db.function_data(self.id).is_unsafe -- cgit v1.2.3