aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFedor Sakharov <[email protected]>2020-05-14 07:56:20 +0100
committerFedor Sakharov <[email protected]>2020-05-14 07:56:20 +0100
commita55ad203888b5e43cf6cbf015d562d7bd1abe0bb (patch)
treeeda6928064d68ca69053de327ee74148ce8a64c0 /crates
parent00f3b6c59ae3df9a7bfb1cd8b694d5f9b6a78be4 (diff)
Use generic_defaults and display_source_code
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/Cargo.toml1
-rw-r--r--crates/ra_assists/src/ast_transform.rs21
-rw-r--r--crates/ra_hir/src/code_model.rs7
3 files changed, 16 insertions, 13 deletions
diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml
index 488ab7bc8..3bcf58ba4 100644
--- a/crates/ra_assists/Cargo.toml
+++ b/crates/ra_assists/Cargo.toml
@@ -21,5 +21,4 @@ ra_prof = { path = "../ra_prof" }
21ra_db = { path = "../ra_db" } 21ra_db = { path = "../ra_db" }
22ra_ide_db = { path = "../ra_ide_db" } 22ra_ide_db = { path = "../ra_ide_db" }
23hir = { path = "../ra_hir", package = "ra_hir" } 23hir = { path = "../ra_hir", package = "ra_hir" }
24hir_def = { path = "../ra_hir_def", package = "ra_hir_def" }
25test_utils = { path = "../test_utils" } 24test_utils = { path = "../test_utils" }
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs
index d81218bc8..4001ca73c 100644
--- a/crates/ra_assists/src/ast_transform.rs
+++ b/crates/ra_assists/src/ast_transform.rs
@@ -1,8 +1,7 @@
1//! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined. 1//! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined.
2use rustc_hash::FxHashMap; 2use rustc_hash::FxHashMap;
3 3
4use hir::{PathResolution, SemanticsScope}; 4use hir::{HirDisplay, PathResolution, SemanticsScope};
5use hir_def::type_ref::TypeRef;
6use ra_ide_db::RootDatabase; 5use ra_ide_db::RootDatabase;
7use ra_syntax::{ 6use ra_syntax::{
8 algo::SyntaxRewriter, 7 algo::SyntaxRewriter,
@@ -61,14 +60,18 @@ impl<'a> SubstituteTypeParams<'a> {
61 .zip(substs.into_iter().map(Some).chain(std::iter::repeat(None))) 60 .zip(substs.into_iter().map(Some).chain(std::iter::repeat(None)))
62 .filter_map(|(k, v)| match v { 61 .filter_map(|(k, v)| match v {
63 Some(v) => Some((k, v)), 62 Some(v) => Some((k, v)),
64 None => match k.default(source_scope.db)? { 63 None => {
65 TypeRef::Path(path) => Some(( 64 let default = k.default(source_scope.db)?;
65 Some((
66 k, 66 k,
67 ast::make::type_arg(&format!("{}", path.mod_path().as_ident()?)) 67 ast::make::type_arg(
68 .type_ref()?, 68 &default
69 )), 69 .display_source_code(source_scope.db, source_scope.module()?.into())
70 _ => None, 70 .ok()?,
71 }, 71 )
72 .type_ref()?,
73 ))
74 }
72 }) 75 })
73 .collect(); 76 .collect();
74 return SubstituteTypeParams { 77 return SubstituteTypeParams {
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 3c56f39c1..3936f5aaa 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -990,9 +990,10 @@ impl TypeParam {
990 } 990 }
991 } 991 }
992 992
993 pub fn default(self, db: &dyn HirDatabase) -> Option<TypeRef> { 993 pub fn default(self, db: &dyn HirDatabase) -> Option<Ty> {
994 let params = db.generic_params(self.id.parent); 994 let params = db.generic_defaults(self.id.parent);
995 params.types[self.id.local_id].default.clone() 995 let local_idx: u32 = self.id.local_id.into_raw().into();
996 params.get(local_idx as usize).map(|d| d.clone())
996 } 997 }
997} 998}
998 999