mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Type-safer API for dealing with parameter lists with optional self
This commit is contained in:
parent
455a0cfda2
commit
6f51f728a1
4 changed files with 21 additions and 10 deletions
|
@ -744,14 +744,13 @@ impl Function {
|
|||
Some(SelfParam { func: self.id })
|
||||
}
|
||||
|
||||
pub fn params(self, db: &dyn HirDatabase) -> Vec<Param> {
|
||||
pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param> {
|
||||
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<Vec<Param>> {
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue