diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-04 15:23:53 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-04 15:23:53 +0000 |
commit | 6f8af890ed9e3998b034c52157baf21db2a78227 (patch) | |
tree | 8d2f4c209abe7428daf3467bfd345b903286da40 /crates/hir | |
parent | b4ab804dcad16f1eb1ac3f603889b101e4d55a68 (diff) | |
parent | 54b9b03ca2e90083fd1d1fe199c5dde595423b53 (diff) |
Merge #7154
7154: Show goto type actions for Const and TypeParams r=matklad a=Veykril
Shows goto type actions for type parameters:
![Code_6hn3rowu9M](https://user-images.githubusercontent.com/3757771/103547890-42aaeb00-4ea5-11eb-8ac7-f166869af5f8.png)
Shows goto type actions for const parameters:
![Code_8UFCcbZL3z](https://user-images.githubusercontent.com/3757771/103547891-43438180-4ea5-11eb-91e8-50681e4d831e.png)
Also shows implementations for `Self`:
![Code_eQj1pWfser](https://user-images.githubusercontent.com/3757771/103547892-43438180-4ea5-11eb-9122-461f2e0fdd01.png)
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/code_model.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index a2255508e..071e553a8 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -1276,6 +1276,18 @@ impl TypeParam { | |||
1276 | } | 1276 | } |
1277 | } | 1277 | } |
1278 | 1278 | ||
1279 | pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> { | ||
1280 | db.generic_predicates_for_param(self.id) | ||
1281 | .into_iter() | ||
1282 | .filter_map(|pred| match &pred.value { | ||
1283 | hir_ty::GenericPredicate::Implemented(trait_ref) => { | ||
1284 | Some(Trait::from(trait_ref.trait_)) | ||
1285 | } | ||
1286 | _ => None, | ||
1287 | }) | ||
1288 | .collect() | ||
1289 | } | ||
1290 | |||
1279 | pub fn default(self, db: &dyn HirDatabase) -> Option<Type> { | 1291 | pub fn default(self, db: &dyn HirDatabase) -> Option<Type> { |
1280 | let params = db.generic_defaults(self.id.parent); | 1292 | let params = db.generic_defaults(self.id.parent); |
1281 | let local_idx = hir_ty::param_idx(db, self.id)?; | 1293 | let local_idx = hir_ty::param_idx(db, self.id)?; |
@@ -1343,6 +1355,12 @@ impl ConstParam { | |||
1343 | pub fn parent(self, _db: &dyn HirDatabase) -> GenericDef { | 1355 | pub fn parent(self, _db: &dyn HirDatabase) -> GenericDef { |
1344 | self.id.parent.into() | 1356 | self.id.parent.into() |
1345 | } | 1357 | } |
1358 | |||
1359 | pub fn ty(self, db: &dyn HirDatabase) -> Type { | ||
1360 | let def = self.id.parent; | ||
1361 | let krate = def.module(db.upcast()).krate; | ||
1362 | Type::new(db, krate, def, db.const_param_ty(self.id)) | ||
1363 | } | ||
1346 | } | 1364 | } |
1347 | 1365 | ||
1348 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 1366 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |