diff options
Diffstat (limited to 'crates/ra_hir/src/generics.rs')
-rw-r--r-- | crates/ra_hir/src/generics.rs | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index e75337cdf..d6728cc9f 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -11,7 +11,7 @@ use crate::{ | |||
11 | db::{AstDatabase, DefDatabase, HirDatabase}, | 11 | db::{AstDatabase, DefDatabase, HirDatabase}, |
12 | name::SELF_TYPE, | 12 | name::SELF_TYPE, |
13 | path::Path, | 13 | path::Path, |
14 | type_ref::TypeRef, | 14 | type_ref::{TypeBound, TypeRef}, |
15 | AdtDef, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, | 15 | AdtDef, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, |
16 | Trait, TypeAlias, Union, | 16 | Trait, TypeAlias, Union, |
17 | }; | 17 | }; |
@@ -35,10 +35,12 @@ pub struct GenericParams { | |||
35 | 35 | ||
36 | /// A single predicate from a where clause, i.e. `where Type: Trait`. Combined | 36 | /// A single predicate from a where clause, i.e. `where Type: Trait`. Combined |
37 | /// where clauses like `where T: Foo + Bar` are turned into multiple of these. | 37 | /// where clauses like `where T: Foo + Bar` are turned into multiple of these. |
38 | /// It might still result in multiple actual predicates though, because of | ||
39 | /// associated type bindings like `Iterator<Item = u32>`. | ||
38 | #[derive(Clone, PartialEq, Eq, Debug)] | 40 | #[derive(Clone, PartialEq, Eq, Debug)] |
39 | pub struct WherePredicate { | 41 | pub struct WherePredicate { |
40 | pub(crate) type_ref: TypeRef, | 42 | pub(crate) type_ref: TypeRef, |
41 | pub(crate) trait_ref: Path, | 43 | pub(crate) bound: TypeBound, |
42 | } | 44 | } |
43 | 45 | ||
44 | // FIXME: consts can have type parameters from their parents (i.e. associated consts of traits) | 46 | // FIXME: consts can have type parameters from their parents (i.e. associated consts of traits) |
@@ -143,18 +145,8 @@ impl GenericParams { | |||
143 | // FIXME: remove this bound | 145 | // FIXME: remove this bound |
144 | return; | 146 | return; |
145 | } | 147 | } |
146 | let path = bound | 148 | let bound = TypeBound::from_ast(bound); |
147 | .type_ref() | 149 | self.where_predicates.push(WherePredicate { type_ref, bound }); |
148 | .and_then(|tr| match tr { | ||
149 | ast::TypeRef::PathType(path) => path.path(), | ||
150 | _ => None, | ||
151 | }) | ||
152 | .and_then(Path::from_ast); | ||
153 | let path = match path { | ||
154 | Some(p) => p, | ||
155 | None => return, | ||
156 | }; | ||
157 | self.where_predicates.push(WherePredicate { type_ref, trait_ref: path }); | ||
158 | } | 150 | } |
159 | 151 | ||
160 | pub(crate) fn find_by_name(&self, name: &Name) -> Option<&GenericParam> { | 152 | pub(crate) fn find_by_name(&self, name: &Name) -> Option<&GenericParam> { |