aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/generics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/generics.rs')
-rw-r--r--crates/ra_hir/src/generics.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 4ce7551c3..9d5d18564 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -5,15 +5,17 @@
5 5
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use hir_def::{
9 name::{self, AsName},
10 path::Path,
11 type_ref::{TypeBound, TypeRef},
12};
8use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; 13use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner};
9 14
10use crate::{ 15use crate::{
11 db::{AstDatabase, DefDatabase, HirDatabase}, 16 db::{AstDatabase, DefDatabase, HirDatabase},
12 name::SELF_TYPE, 17 Adt, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait,
13 path::Path, 18 TypeAlias, Union,
14 type_ref::{TypeBound, TypeRef},
15 Adt, AsName, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct,
16 Trait, TypeAlias, Union,
17}; 19};
18 20
19/// Data about a generic parameter (to a function, struct, impl, ...). 21/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -94,11 +96,15 @@ impl GenericParams {
94 GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start), 96 GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start),
95 GenericDef::Trait(it) => { 97 GenericDef::Trait(it) => {
96 // traits get the Self type as an implicit first type parameter 98 // traits get the Self type as an implicit first type parameter
97 generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); 99 generics.params.push(GenericParam {
100 idx: start,
101 name: name::SELF_TYPE,
102 default: None,
103 });
98 generics.fill(&it.source(db).ast, start + 1); 104 generics.fill(&it.source(db).ast, start + 1);
99 // add super traits as bounds on Self 105 // add super traits as bounds on Self
100 // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar 106 // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar
101 let self_param = TypeRef::Path(SELF_TYPE.into()); 107 let self_param = TypeRef::Path(name::SELF_TYPE.into());
102 generics.fill_bounds(&it.source(db).ast, self_param); 108 generics.fill_bounds(&it.source(db).ast, self_param);
103 } 109 }
104 GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start), 110 GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start),