mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 13:33: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_db",
|
||||||
"ra_fmt",
|
"ra_fmt",
|
||||||
"ra_hir",
|
"ra_hir",
|
||||||
"ra_hir_def",
|
|
||||||
"ra_ide_db",
|
"ra_ide_db",
|
||||||
"ra_prof",
|
"ra_prof",
|
||||||
"ra_syntax",
|
"ra_syntax",
|
||||||
|
|
|
@ -21,5 +21,4 @@ ra_prof = { path = "../ra_prof" }
|
||||||
ra_db = { path = "../ra_db" }
|
ra_db = { path = "../ra_db" }
|
||||||
ra_ide_db = { path = "../ra_ide_db" }
|
ra_ide_db = { path = "../ra_ide_db" }
|
||||||
hir = { path = "../ra_hir", package = "ra_hir" }
|
hir = { path = "../ra_hir", package = "ra_hir" }
|
||||||
hir_def = { path = "../ra_hir_def", package = "ra_hir_def" }
|
|
||||||
test_utils = { path = "../test_utils" }
|
test_utils = { path = "../test_utils" }
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
//! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined.
|
//! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined.
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use hir::{PathResolution, SemanticsScope};
|
use hir::{HirDisplay, PathResolution, SemanticsScope};
|
||||||
use hir_def::type_ref::TypeRef;
|
|
||||||
use ra_ide_db::RootDatabase;
|
use ra_ide_db::RootDatabase;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
algo::SyntaxRewriter,
|
algo::SyntaxRewriter,
|
||||||
|
@ -61,14 +60,18 @@ impl<'a> SubstituteTypeParams<'a> {
|
||||||
.zip(substs.into_iter().map(Some).chain(std::iter::repeat(None)))
|
.zip(substs.into_iter().map(Some).chain(std::iter::repeat(None)))
|
||||||
.filter_map(|(k, v)| match v {
|
.filter_map(|(k, v)| match v {
|
||||||
Some(v) => Some((k, v)),
|
Some(v) => Some((k, v)),
|
||||||
None => match k.default(source_scope.db)? {
|
None => {
|
||||||
TypeRef::Path(path) => Some((
|
let default = k.default(source_scope.db)?;
|
||||||
|
Some((
|
||||||
k,
|
k,
|
||||||
ast::make::type_arg(&format!("{}", path.mod_path().as_ident()?))
|
ast::make::type_arg(
|
||||||
|
&default
|
||||||
|
.display_source_code(source_scope.db, source_scope.module()?.into())
|
||||||
|
.ok()?,
|
||||||
|
)
|
||||||
.type_ref()?,
|
.type_ref()?,
|
||||||
)),
|
))
|
||||||
_ => None,
|
}
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
return SubstituteTypeParams {
|
return SubstituteTypeParams {
|
||||||
|
|
|
@ -990,9 +990,10 @@ impl TypeParam {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default(self, db: &dyn HirDatabase) -> Option<TypeRef> {
|
pub fn default(self, db: &dyn HirDatabase) -> Option<Ty> {
|
||||||
let params = db.generic_params(self.id.parent);
|
let params = db.generic_defaults(self.id.parent);
|
||||||
params.types[self.id.local_id].default.clone()
|
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