diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/lang_item.rs | 54 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/autoderef.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits.rs | 2 |
7 files changed, 31 insertions, 38 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 4fbb1fc8f..6602d1220 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -788,8 +788,7 @@ impl Trait { | |||
788 | TraitItem::TypeAlias(t) => Some(*t), | 788 | TraitItem::TypeAlias(t) => Some(*t), |
789 | _ => None, | 789 | _ => None, |
790 | }) | 790 | }) |
791 | .filter(|t| t.name(db) == name) | 791 | .find(|t| t.name(db) == name) |
792 | .next() | ||
793 | } | 792 | } |
794 | 793 | ||
795 | pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc<TraitData> { | 794 | pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc<TraitData> { |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 651f0d4ca..c4dd54596 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -185,11 +185,11 @@ pub trait HirDatabase: DefDatabase + AstDatabase { | |||
185 | goal: crate::ty::Canonical<crate::ty::TraitRef>, | 185 | goal: crate::ty::Canonical<crate::ty::TraitRef>, |
186 | ) -> Option<crate::ty::traits::Solution>; | 186 | ) -> Option<crate::ty::traits::Solution>; |
187 | 187 | ||
188 | #[salsa::invoke(crate::ty::traits::normalize)] | 188 | #[salsa::invoke(crate::ty::traits::normalize_query)] |
189 | fn normalize( | 189 | fn normalize( |
190 | &self, | 190 | &self, |
191 | krate: Crate, | 191 | krate: Crate, |
192 | goal: crate::ty::Canonical<crate::ty::traits::ProjectionPredicate>, | 192 | goal: crate::ty::Canonical<crate::ty::ProjectionPredicate>, |
193 | ) -> Option<crate::ty::traits::Solution>; | 193 | ) -> Option<crate::ty::traits::Solution>; |
194 | } | 194 | } |
195 | 195 | ||
diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs index ada8aeb5b..18ac0fcf9 100644 --- a/crates/ra_hir/src/lang_item.rs +++ b/crates/ra_hir/src/lang_item.rs | |||
@@ -1,10 +1,11 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | use rustc_hash::FxHashMap; | 2 | use rustc_hash::FxHashMap; |
3 | 3 | ||
4 | use ra_syntax::{SmolStr, ast::AttrsOwner}; | 4 | use ra_syntax::{SmolStr, TreeArc, ast::AttrsOwner}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | Crate, DefDatabase, Enum, Function, HirDatabase, ImplBlock, Module, Static, Struct, Trait, ModuleDef, AstDatabase, HasSource | 7 | Crate, DefDatabase, Enum, Function, HirDatabase, ImplBlock, Module, |
8 | Static, Struct, Trait, ModuleDef, AstDatabase, HasSource | ||
8 | }; | 9 | }; |
9 | 10 | ||
10 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 11 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -93,39 +94,15 @@ impl LangItems { | |||
93 | } | 94 | } |
94 | } | 95 | } |
95 | 96 | ||
96 | // FIXME make this nicer | ||
97 | for def in module.declarations(db) { | 97 | for def in module.declarations(db) { |
98 | match def { | 98 | match def { |
99 | ModuleDef::Trait(trait_) => { | 99 | ModuleDef::Trait(trait_) => { |
100 | let node = trait_.source(db).ast; | 100 | self.collect_lang_item(db, trait_, LangItemTarget::Trait) |
101 | if let Some(lang_item_name) = lang_item_name(&*node) { | ||
102 | self.items.entry(lang_item_name).or_insert(LangItemTarget::Trait(trait_)); | ||
103 | } | ||
104 | } | ||
105 | ModuleDef::Enum(e) => { | ||
106 | let node = e.source(db).ast; | ||
107 | if let Some(lang_item_name) = lang_item_name(&*node) { | ||
108 | self.items.entry(lang_item_name).or_insert(LangItemTarget::Enum(e)); | ||
109 | } | ||
110 | } | ||
111 | ModuleDef::Struct(s) => { | ||
112 | let node = s.source(db).ast; | ||
113 | if let Some(lang_item_name) = lang_item_name(&*node) { | ||
114 | self.items.entry(lang_item_name).or_insert(LangItemTarget::Struct(s)); | ||
115 | } | ||
116 | } | ||
117 | ModuleDef::Function(f) => { | ||
118 | let node = f.source(db).ast; | ||
119 | if let Some(lang_item_name) = lang_item_name(&*node) { | ||
120 | self.items.entry(lang_item_name).or_insert(LangItemTarget::Function(f)); | ||
121 | } | ||
122 | } | ||
123 | ModuleDef::Static(s) => { | ||
124 | let node = s.source(db).ast; | ||
125 | if let Some(lang_item_name) = lang_item_name(&*node) { | ||
126 | self.items.entry(lang_item_name).or_insert(LangItemTarget::Static(s)); | ||
127 | } | ||
128 | } | 101 | } |
102 | ModuleDef::Enum(e) => self.collect_lang_item(db, e, LangItemTarget::Enum), | ||
103 | ModuleDef::Struct(s) => self.collect_lang_item(db, s, LangItemTarget::Struct), | ||
104 | ModuleDef::Function(f) => self.collect_lang_item(db, f, LangItemTarget::Function), | ||
105 | ModuleDef::Static(s) => self.collect_lang_item(db, s, LangItemTarget::Static), | ||
129 | _ => {} | 106 | _ => {} |
130 | } | 107 | } |
131 | } | 108 | } |
@@ -135,6 +112,21 @@ impl LangItems { | |||
135 | self.collect_lang_items_recursive(db, &child); | 112 | self.collect_lang_items_recursive(db, &child); |
136 | } | 113 | } |
137 | } | 114 | } |
115 | |||
116 | fn collect_lang_item<T, N>( | ||
117 | &mut self, | ||
118 | db: &(impl DefDatabase + AstDatabase), | ||
119 | item: T, | ||
120 | constructor: fn(T) -> LangItemTarget, | ||
121 | ) where | ||
122 | T: Copy + HasSource<Ast = TreeArc<N>>, | ||
123 | N: AttrsOwner, | ||
124 | { | ||
125 | let node = item.source(db).ast; | ||
126 | if let Some(lang_item_name) = lang_item_name(&*node) { | ||
127 | self.items.entry(lang_item_name).or_insert(constructor(item)); | ||
128 | } | ||
129 | } | ||
138 | } | 130 | } |
139 | 131 | ||
140 | fn lang_item_name<T: AttrsOwner>(node: &T) -> Option<SmolStr> { | 132 | fn lang_item_name<T: AttrsOwner>(node: &T) -> Option<SmolStr> { |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 4ed19f860..842d49e1f 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -23,6 +23,7 @@ pub(crate) use lower::{TypableDef, type_for_def, type_for_field, callable_item_s | |||
23 | pub(crate) use infer::{infer_query, InferenceResult, InferTy}; | 23 | pub(crate) use infer::{infer_query, InferenceResult, InferTy}; |
24 | pub use lower::CallableDef; | 24 | pub use lower::CallableDef; |
25 | pub(crate) use autoderef::autoderef; | 25 | pub(crate) use autoderef::autoderef; |
26 | pub(crate) use traits::ProjectionPredicate; | ||
26 | 27 | ||
27 | /// A type constructor or type name: this might be something like the primitive | 28 | /// A type constructor or type name: this might be something like the primitive |
28 | /// type `bool`, a struct like `Vec`, or things like function pointers or | 29 | /// type `bool`, a struct like `Vec`, or things like function pointers or |
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index e85e558b2..1f443d49b 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs | |||
@@ -10,12 +10,14 @@ use log::{info, warn}; | |||
10 | use crate::{HirDatabase, Name, Resolver, HasGenericParams}; | 10 | use crate::{HirDatabase, Name, Resolver, HasGenericParams}; |
11 | use super::{traits::Solution, Ty, Canonical}; | 11 | use super::{traits::Solution, Ty, Canonical}; |
12 | 12 | ||
13 | const AUTODEREF_RECURSION_LIMIT: usize = 10; | ||
14 | |||
13 | pub(crate) fn autoderef<'a>( | 15 | pub(crate) fn autoderef<'a>( |
14 | db: &'a impl HirDatabase, | 16 | db: &'a impl HirDatabase, |
15 | resolver: &'a Resolver, | 17 | resolver: &'a Resolver, |
16 | ty: Canonical<Ty>, | 18 | ty: Canonical<Ty>, |
17 | ) -> impl Iterator<Item = Canonical<Ty>> + 'a { | 19 | ) -> impl Iterator<Item = Canonical<Ty>> + 'a { |
18 | successors(Some(ty), move |ty| deref(db, resolver, ty)) | 20 | successors(Some(ty), move |ty| deref(db, resolver, ty)).take(AUTODEREF_RECURSION_LIMIT) |
19 | } | 21 | } |
20 | 22 | ||
21 | pub(crate) fn deref( | 23 | pub(crate) fn deref( |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 059a73900..7a101d981 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -2768,7 +2768,6 @@ fn test(s: Arc<S>) { | |||
2768 | 2768 | ||
2769 | #[test] | 2769 | #[test] |
2770 | fn deref_trait_with_inference_var() { | 2770 | fn deref_trait_with_inference_var() { |
2771 | // std::env::set_var("RUST_BACKTRACE", "1"); | ||
2772 | let t = type_at( | 2771 | let t = type_at( |
2773 | r#" | 2772 | r#" |
2774 | //- /main.rs | 2773 | //- /main.rs |
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index 6cf3dd70a..9a6349d4b 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs | |||
@@ -105,7 +105,7 @@ pub(crate) fn implements_query( | |||
105 | solution.map(|solution| solution_from_chalk(db, solution)) | 105 | solution.map(|solution| solution_from_chalk(db, solution)) |
106 | } | 106 | } |
107 | 107 | ||
108 | pub(crate) fn normalize( | 108 | pub(crate) fn normalize_query( |
109 | db: &impl HirDatabase, | 109 | db: &impl HirDatabase, |
110 | krate: Crate, | 110 | krate: Crate, |
111 | projection: Canonical<ProjectionPredicate>, | 111 | projection: Canonical<ProjectionPredicate>, |