diff options
author | Benjamin Coenen <[email protected]> | 2020-04-21 13:32:02 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-04-21 13:32:02 +0100 |
commit | 7f143b154e7c47b1f5bdc558bb0b5d1f2bf74f8d (patch) | |
tree | 571b7d5bdfc84bdaeaa8235221fd96a87453fe05 /crates/ra_hir/src | |
parent | 1c3a1385a587f0713908c0ae888ffad31f13de11 (diff) | |
parent | a88887df0726cc3d390db4bfbbc1274195d87f91 (diff) |
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir/src/semantics.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 11 |
3 files changed, 26 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3801fce23..6e0d89466 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -759,6 +759,17 @@ impl MacroDef { | |||
759 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { | 759 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { |
760 | self.source(db).value.name().map(|it| it.as_name()) | 760 | self.source(db).value.name().map(|it| it.as_name()) |
761 | } | 761 | } |
762 | |||
763 | /// Indicate it is a proc-macro | ||
764 | pub fn is_proc_macro(&self) -> bool { | ||
765 | match self.id.kind { | ||
766 | hir_expand::MacroDefKind::Declarative => false, | ||
767 | hir_expand::MacroDefKind::BuiltIn(_) => false, | ||
768 | hir_expand::MacroDefKind::BuiltInDerive(_) => false, | ||
769 | hir_expand::MacroDefKind::BuiltInEager(_) => false, | ||
770 | hir_expand::MacroDefKind::CustomDerive(_) => true, | ||
771 | } | ||
772 | } | ||
762 | } | 773 | } |
763 | 774 | ||
764 | /// Invariant: `inner.as_assoc_item(db).is_some()` | 775 | /// Invariant: `inner.as_assoc_item(db).is_some()` |
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 0b477f0e9..5d6edc45c 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs | |||
@@ -195,6 +195,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
195 | self.analyze(field.syntax()).resolve_record_field(self.db, field) | 195 | self.analyze(field.syntax()).resolve_record_field(self.db, field) |
196 | } | 196 | } |
197 | 197 | ||
198 | pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<StructField> { | ||
199 | self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) | ||
200 | } | ||
201 | |||
198 | pub fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option<MacroDef> { | 202 | pub fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option<MacroDef> { |
199 | let sa = self.analyze(macro_call.syntax()); | 203 | let sa = self.analyze(macro_call.syntax()); |
200 | let macro_call = self.find_file(macro_call.syntax().clone()).with_value(macro_call); | 204 | let macro_call = self.find_file(macro_call.syntax().clone()).with_value(macro_call); |
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 23af400b8..0ed6d0958 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs | |||
@@ -95,6 +95,7 @@ impl SourceAnalyzer { | |||
95 | } | 95 | } |
96 | 96 | ||
97 | fn pat_id(&self, pat: &ast::Pat) -> Option<PatId> { | 97 | fn pat_id(&self, pat: &ast::Pat) -> Option<PatId> { |
98 | // FIXME: macros, see `expr_id` | ||
98 | let src = InFile { file_id: self.file_id, value: pat }; | 99 | let src = InFile { file_id: self.file_id, value: pat }; |
99 | self.body_source_map.as_ref()?.node_pat(src) | 100 | self.body_source_map.as_ref()?.node_pat(src) |
100 | } | 101 | } |
@@ -167,6 +168,16 @@ impl SourceAnalyzer { | |||
167 | Some((struct_field.into(), local)) | 168 | Some((struct_field.into(), local)) |
168 | } | 169 | } |
169 | 170 | ||
171 | pub(crate) fn resolve_record_field_pat( | ||
172 | &self, | ||
173 | _db: &dyn HirDatabase, | ||
174 | field: &ast::RecordFieldPat, | ||
175 | ) -> Option<StructField> { | ||
176 | let pat_id = self.pat_id(&field.pat()?)?; | ||
177 | let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?; | ||
178 | Some(struct_field.into()) | ||
179 | } | ||
180 | |||
170 | pub(crate) fn resolve_macro_call( | 181 | pub(crate) fn resolve_macro_call( |
171 | &self, | 182 | &self, |
172 | db: &dyn HirDatabase, | 183 | db: &dyn HirDatabase, |