mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Use generic_defaults and display_source_code
This commit is contained in:
parent
00f3b6c59a
commit
a55ad20388
4 changed files with 16 additions and 14 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -936,7 +936,6 @@ dependencies = [
|
|||
"ra_db",
|
||||
"ra_fmt",
|
||||
"ra_hir",
|
||||
"ra_hir_def",
|
||||
"ra_ide_db",
|
||||
"ra_prof",
|
||||
"ra_syntax",
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -990,9 +990,10 @@ impl TypeParam {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn default(self, db: &dyn HirDatabase) -> Option<TypeRef> {
|
||||
let params = db.generic_params(self.id.parent);
|
||||
params.types[self.id.local_id].default.clone()
|
||||
pub fn default(self, db: &dyn HirDatabase) -> Option<Ty> {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue