diff options
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/code_model.rs | 11 | ||||
-rw-r--r-- | crates/hir/src/semantics.rs | 27 | ||||
-rw-r--r-- | crates/hir/src/source_analyzer.rs | 4 |
3 files changed, 34 insertions, 8 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index dc3a1699f..a2a166e0a 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -926,12 +926,12 @@ impl MacroDef { | |||
926 | 926 | ||
927 | /// Indicate it is a proc-macro | 927 | /// Indicate it is a proc-macro |
928 | pub fn is_proc_macro(&self) -> bool { | 928 | pub fn is_proc_macro(&self) -> bool { |
929 | matches!(self.id.kind, MacroDefKind::CustomDerive(_)) | 929 | matches!(self.id.kind, MacroDefKind::ProcMacro(_)) |
930 | } | 930 | } |
931 | 931 | ||
932 | /// Indicate it is a derive macro | 932 | /// Indicate it is a derive macro |
933 | pub fn is_derive_macro(&self) -> bool { | 933 | pub fn is_derive_macro(&self) -> bool { |
934 | matches!(self.id.kind, MacroDefKind::CustomDerive(_) | MacroDefKind::BuiltInDerive(_)) | 934 | matches!(self.id.kind, MacroDefKind::ProcMacro(_) | MacroDefKind::BuiltInDerive(_)) |
935 | } | 935 | } |
936 | } | 936 | } |
937 | 937 | ||
@@ -1309,6 +1309,8 @@ impl Type { | |||
1309 | /// Checks that particular type `ty` implements `std::future::Future`. | 1309 | /// Checks that particular type `ty` implements `std::future::Future`. |
1310 | /// This function is used in `.await` syntax completion. | 1310 | /// This function is used in `.await` syntax completion. |
1311 | pub fn impls_future(&self, db: &dyn HirDatabase) -> bool { | 1311 | pub fn impls_future(&self, db: &dyn HirDatabase) -> bool { |
1312 | // No special case for the type of async block, since Chalk can figure it out. | ||
1313 | |||
1312 | let krate = self.krate; | 1314 | let krate = self.krate; |
1313 | 1315 | ||
1314 | let std_future_trait = | 1316 | let std_future_trait = |
@@ -1626,6 +1628,11 @@ impl Type { | |||
1626 | cb(type_.derived(ty.clone())); | 1628 | cb(type_.derived(ty.clone())); |
1627 | } | 1629 | } |
1628 | } | 1630 | } |
1631 | TypeCtor::OpaqueType(..) => { | ||
1632 | if let Some(bounds) = ty.impl_trait_bounds(db) { | ||
1633 | walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb); | ||
1634 | } | ||
1635 | } | ||
1629 | _ => (), | 1636 | _ => (), |
1630 | } | 1637 | } |
1631 | 1638 | ||
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 1594d4f0f..c61a430e1 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs | |||
@@ -207,8 +207,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { | |||
207 | self.imp.resolve_record_field(field) | 207 | self.imp.resolve_record_field(field) |
208 | } | 208 | } |
209 | 209 | ||
210 | pub fn resolve_record_field_pat(&self, field: &ast::RecordPatField) -> Option<Field> { | 210 | pub fn resolve_record_pat_field(&self, field: &ast::RecordPatField) -> Option<Field> { |
211 | self.imp.resolve_record_field_pat(field) | 211 | self.imp.resolve_record_pat_field(field) |
212 | } | 212 | } |
213 | 213 | ||
214 | pub fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option<MacroDef> { | 214 | pub fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option<MacroDef> { |
@@ -433,8 +433,8 @@ impl<'db> SemanticsImpl<'db> { | |||
433 | self.analyze(field.syntax()).resolve_record_field(self.db, field) | 433 | self.analyze(field.syntax()).resolve_record_field(self.db, field) |
434 | } | 434 | } |
435 | 435 | ||
436 | fn resolve_record_field_pat(&self, field: &ast::RecordPatField) -> Option<Field> { | 436 | fn resolve_record_pat_field(&self, field: &ast::RecordPatField) -> Option<Field> { |
437 | self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) | 437 | self.analyze(field.syntax()).resolve_record_pat_field(self.db, field) |
438 | } | 438 | } |
439 | 439 | ||
440 | fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option<MacroDef> { | 440 | fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option<MacroDef> { |
@@ -697,6 +697,25 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode { | |||
697 | node.ancestors().last().unwrap() | 697 | node.ancestors().last().unwrap() |
698 | } | 698 | } |
699 | 699 | ||
700 | /// `SemanticScope` encapsulates the notion of a scope (the set of visible | ||
701 | /// names) at a particular program point. | ||
702 | /// | ||
703 | /// It is a bit tricky, as scopes do not really exist inside the compiler. | ||
704 | /// Rather, the compiler directly computes for each reference the definition it | ||
705 | /// refers to. It might transiently compute the explicit scope map while doing | ||
706 | /// so, but, generally, this is not something left after the analysis. | ||
707 | /// | ||
708 | /// However, we do very much need explicit scopes for IDE purposes -- | ||
709 | /// completion, at its core, lists the contents of the current scope. The notion | ||
710 | /// of scope is also useful to answer questions like "what would be the meaning | ||
711 | /// of this piece of code if we inserted it into this position?". | ||
712 | /// | ||
713 | /// So `SemanticsScope` is constructed from a specific program point (a syntax | ||
714 | /// node or just a raw offset) and provides access to the set of visible names | ||
715 | /// on a somewhat best-effort basis. | ||
716 | /// | ||
717 | /// Note that if you are wondering "what does this specific existing name mean?", | ||
718 | /// you'd better use the `resolve_` family of methods. | ||
700 | #[derive(Debug)] | 719 | #[derive(Debug)] |
701 | pub struct SemanticsScope<'a> { | 720 | pub struct SemanticsScope<'a> { |
702 | pub db: &'a dyn HirDatabase, | 721 | pub db: &'a dyn HirDatabase, |
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 1d13c4f1d..1aef0f33f 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs | |||
@@ -179,13 +179,13 @@ impl SourceAnalyzer { | |||
179 | Some((struct_field.into(), local)) | 179 | Some((struct_field.into(), local)) |
180 | } | 180 | } |
181 | 181 | ||
182 | pub(crate) fn resolve_record_field_pat( | 182 | pub(crate) fn resolve_record_pat_field( |
183 | &self, | 183 | &self, |
184 | _db: &dyn HirDatabase, | 184 | _db: &dyn HirDatabase, |
185 | field: &ast::RecordPatField, | 185 | field: &ast::RecordPatField, |
186 | ) -> Option<Field> { | 186 | ) -> Option<Field> { |
187 | let pat_id = self.pat_id(&field.pat()?)?; | 187 | let pat_id = self.pat_id(&field.pat()?)?; |
188 | let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?; | 188 | let struct_field = self.infer.as_ref()?.record_pat_field_resolution(pat_id)?; |
189 | Some(struct_field.into()) | 189 | Some(struct_field.into()) |
190 | } | 190 | } |
191 | 191 | ||