From a55ad203888b5e43cf6cbf015d562d7bd1abe0bb Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Thu, 14 May 2020 09:56:20 +0300 Subject: [PATCH] Use generic_defaults and display_source_code --- Cargo.lock | 1 - crates/ra_assists/Cargo.toml | 1 - crates/ra_assists/src/ast_transform.rs | 21 ++++++++++++--------- crates/ra_hir/src/code_model.rs | 7 ++++--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b28c6d98b8..3a34978b13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -936,7 +936,6 @@ dependencies = [ "ra_db", "ra_fmt", "ra_hir", - "ra_hir_def", "ra_ide_db", "ra_prof", "ra_syntax", diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index 488ab7bc87..3bcf58ba4b 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml @@ -21,5 +21,4 @@ ra_prof = { path = "../ra_prof" } ra_db = { path = "../ra_db" } ra_ide_db = { path = "../ra_ide_db" } hir = { path = "../ra_hir", package = "ra_hir" } -hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } test_utils = { path = "../test_utils" } diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index d81218bc80..4001ca73c3 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -1,8 +1,7 @@ //! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined. use rustc_hash::FxHashMap; -use hir::{PathResolution, SemanticsScope}; -use hir_def::type_ref::TypeRef; +use hir::{HirDisplay, PathResolution, SemanticsScope}; use ra_ide_db::RootDatabase; use ra_syntax::{ algo::SyntaxRewriter, @@ -61,14 +60,18 @@ impl<'a> SubstituteTypeParams<'a> { .zip(substs.into_iter().map(Some).chain(std::iter::repeat(None))) .filter_map(|(k, v)| match v { Some(v) => Some((k, v)), - None => match k.default(source_scope.db)? { - TypeRef::Path(path) => Some(( + None => { + let default = k.default(source_scope.db)?; + Some(( k, - ast::make::type_arg(&format!("{}", path.mod_path().as_ident()?)) - .type_ref()?, - )), - _ => None, - }, + ast::make::type_arg( + &default + .display_source_code(source_scope.db, source_scope.module()?.into()) + .ok()?, + ) + .type_ref()?, + )) + } }) .collect(); return SubstituteTypeParams { diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3c56f39c13..3936f5aaa0 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -990,9 +990,10 @@ impl TypeParam { } } - pub fn default(self, db: &dyn HirDatabase) -> Option { - let params = db.generic_params(self.id.parent); - params.types[self.id.local_id].default.clone() + pub fn default(self, db: &dyn HirDatabase) -> Option { + let params = db.generic_defaults(self.id.parent); + let local_idx: u32 = self.id.local_id.into_raw().into(); + params.get(local_idx as usize).map(|d| d.clone()) } }