aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-14 12:20:42 +0100
committerGitHub <[email protected]>2020-05-14 12:20:42 +0100
commitf1587ac26332c3378c41d3cc552b270ee6a45cc4 (patch)
treea3a0d688da9315f72cad557af7598779e3937f19 /crates/ra_hir
parent5148d6dc66d80b375a98143dfbb556ec675bbffc (diff)
parentccd526837459724211c8281926aa86522b2506d5 (diff)
Merge #4445
4445: Correctly fill default type parameters r=flodiebold a=montekki Fixes #3877 So, basically even if the parameters are omitted from the `impl` block, check the parameters in `trait` if they have a default type, and if they do go from `hir` to `ast::TypeArg`. I've added a helper for that but I am not sure that it's a proper way to go from `hir` to `ast` here. Co-authored-by: Fedor Sakharov <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index e8e3211fc..840cfdfc8 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -989,6 +989,17 @@ impl TypeParam {
989 ty: InEnvironment { value: ty, environment }, 989 ty: InEnvironment { value: ty, environment },
990 } 990 }
991 } 991 }
992
993 pub fn default(self, db: &dyn HirDatabase) -> Option<Type> {
994 let params = db.generic_defaults(self.id.parent);
995 let local_idx = hir_ty::param_idx(db, self.id)?;
996 let resolver = self.id.parent.resolver(db.upcast());
997 let environment = TraitEnvironment::lower(db, &resolver);
998 params.get(local_idx).cloned().map(|ty| Type {
999 krate: self.id.parent.module(db.upcast()).krate,
1000 ty: InEnvironment { value: ty, environment },
1001 })
1002 }
992} 1003}
993 1004
994// FIXME: rename from `ImplDef` to `Impl` 1005// FIXME: rename from `ImplDef` to `Impl`