self.kind == PathKind::Plain && self.segments.len() == 1
}
+ /// `true` if this path is just a standalone `self`
+ pub fn is_self(&self) -> bool {
+ self.kind == PathKind::Self_ && self.segments.len() == 0
+ }
+
/// If this path is a single identifier, like `foo`, return its name.
pub fn as_ident(&self) -> Option<&Name> {
if self.kind != PathKind::Plain || self.segments.len() > 1 {
struct InferenceContext<'a, D: HirDatabase> {
db: &'a D,
scopes: Arc<FnScopes>,
+ /// The self param for the current method, if it exists.
+ self_param: Option<LocalSyntaxPtr>,
module: Module,
var_unification_table: InPlaceUnificationTable<TypeVarId>,
type_of: FxHashMap<LocalSyntaxPtr, Ty>,
InferenceContext {
type_of: FxHashMap::default(),
var_unification_table: InPlaceUnificationTable::new(),
+ self_param: None, // set during parameter typing
db,
scopes,
module,
let ty = self.resolve_ty_as_possible(ty.clone());
return Ok(Some(ty));
};
+ } else if path.is_self() {
+ // resolve `self` param
+ let self_param = ctry!(self.self_param);
+ let ty = ctry!(self.type_of.get(&self_param));
+ let ty = self.resolve_ty_as_possible(ty.clone());
+ return Ok(Some(ty));
};
// resolve in module
ctx.new_type_var()
};
if let Some(self_kw) = self_param.self_kw() {
- ctx.type_of
- .insert(LocalSyntaxPtr::new(self_kw.syntax()), self_type);
+ let self_param = LocalSyntaxPtr::new(self_kw.syntax());
+ ctx.self_param = Some(self_param);
+ ctx.type_of.insert(self_param, self_type);
}
}
for param in param_list.params() {