From cb863390f23bc2eac6561d55def9bd3ba54605fc Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 15 Jan 2021 18:57:32 +0100 Subject: Handle self/super/crate in PathSegment as NameRef --- crates/hir/src/semantics.rs | 1 + crates/hir/src/semantics/source_to_def.rs | 9 +++++++++ 2 files changed, 10 insertions(+) (limited to 'crates/hir') diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index cd689c869..ab213e04c 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -750,6 +750,7 @@ to_def_impls![ (crate::ConstParam, ast::ConstParam, const_param_to_def), (crate::MacroDef, ast::MacroRules, macro_rules_to_def), (crate::Local, ast::IdentPat, bind_pat_to_def), + (crate::Local, ast::SelfParam, self_param_to_def), (crate::Label, ast::Label, label_to_def), ]; diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 4b9ebff72..9bf60c72a 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -114,6 +114,15 @@ impl SourceToDefCtx<'_, '_> { let pat_id = source_map.node_pat(src.as_ref())?; Some((container, pat_id)) } + pub(super) fn self_param_to_def( + &mut self, + src: InFile, + ) -> Option<(DefWithBodyId, PatId)> { + let container = self.find_pat_or_label_container(src.as_ref().map(|it| it.syntax()))?; + let (_body, source_map) = self.db.body_with_source_map(container); + let pat_id = source_map.node_self_param(src.as_ref())?; + Some((container, pat_id)) + } pub(super) fn label_to_def( &mut self, src: InFile, -- cgit v1.2.3