aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/data.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-04-12 11:28:24 +0100
committerFlorian Diebold <[email protected]>2020-04-13 14:57:28 +0100
commitc8b2ec8c20be44ae19d15e90ff812745f029899e (patch)
tree98ed585238a37d722159a489db24e0514ae562ce /crates/ra_hir_def/src/data.rs
parentc388130f5ffbcbe7d3131213a24d12d02f769b87 (diff)
Add support for bounds on associated types in trait definitions
E.g. ``` trait Trait { type Item: SomeOtherTrait; } ``` Note that these don't simply desugar to where clauses; as I understand it, where clauses have to be proved by the *user* of the trait, but these bounds are proved by the *implementor*. (Also, where clauses on associated types are unstable.)
Diffstat (limited to 'crates/ra_hir_def/src/data.rs')
-rw-r--r--crates/ra_hir_def/src/data.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index 56a20c5bd..5dfde75d9 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -9,7 +9,8 @@ use hir_expand::{
9}; 9};
10use ra_prof::profile; 10use ra_prof::profile;
11use ra_syntax::ast::{ 11use ra_syntax::ast::{
12 self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, VisibilityOwner, 12 self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, TypeBoundsOwner,
13 VisibilityOwner,
13}; 14};
14 15
15use crate::{ 16use crate::{
@@ -106,6 +107,7 @@ pub struct TypeAliasData {
106 pub name: Name, 107 pub name: Name,
107 pub type_ref: Option<TypeRef>, 108 pub type_ref: Option<TypeRef>,
108 pub visibility: RawVisibility, 109 pub visibility: RawVisibility,
110 pub bounds: Vec<TypeBound>,
109} 111}
110 112
111impl TypeAliasData { 113impl TypeAliasData {
@@ -118,9 +120,17 @@ impl TypeAliasData {
118 let name = node.value.name().map_or_else(Name::missing, |n| n.as_name()); 120 let name = node.value.name().map_or_else(Name::missing, |n| n.as_name());
119 let type_ref = node.value.type_ref().map(TypeRef::from_ast); 121 let type_ref = node.value.type_ref().map(TypeRef::from_ast);
120 let vis_default = RawVisibility::default_for_container(loc.container); 122 let vis_default = RawVisibility::default_for_container(loc.container);
121 let visibility = 123 let visibility = RawVisibility::from_ast_with_default(
122 RawVisibility::from_ast_with_default(db, vis_default, node.map(|n| n.visibility())); 124 db,
123 Arc::new(TypeAliasData { name, type_ref, visibility }) 125 vis_default,
126 node.as_ref().map(|n| n.visibility()),
127 );
128 let bounds = if let Some(bound_list) = node.value.type_bound_list() {
129 bound_list.bounds().map(TypeBound::from_ast).collect()
130 } else {
131 Vec::new()
132 };
133 Arc::new(TypeAliasData { name, type_ref, visibility, bounds })
124 } 134 }
125} 135}
126 136