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