aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/generics.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-08-13 22:09:08 +0100
committerFlorian Diebold <[email protected]>2019-08-22 18:33:00 +0100
commit16a7d8cc850002b427fdc8d21ccde81caaed7902 (patch)
tree7f3c43cf9e83d479edc7f9b4849dae5fbd0f356d /crates/ra_hir/src/generics.rs
parent08e5d394dfbca28b15ed5dc772d55d48f87c3f54 (diff)
Add `impl Trait` and `dyn Trait` types
- refactor bounds handling in the AST a bit - add HIR for bounds - add `Ty::Dyn` and `Ty::Opaque` variants and lower `dyn Trait` / `impl Trait` syntax to them
Diffstat (limited to 'crates/ra_hir/src/generics.rs')
-rw-r--r--crates/ra_hir/src/generics.rs20
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)]
39pub struct WherePredicate { 41pub 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> {