aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/ast_transform.rs
diff options
context:
space:
mode:
authorFedor Sakharov <[email protected]>2020-05-13 14:06:42 +0100
committerFedor Sakharov <[email protected]>2020-05-13 14:07:44 +0100
commit00f3b6c59ae3df9a7bfb1cd8b694d5f9b6a78be4 (patch)
tree847a60e19f55dd8da4e819bd1a76b23588fb9f76 /crates/ra_assists/src/ast_transform.rs
parent88d3959c33c3b8729cecbe062cff8474516df29f (diff)
Correctly fill default type parameters
Diffstat (limited to 'crates/ra_assists/src/ast_transform.rs')
-rw-r--r--crates/ra_assists/src/ast_transform.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs
index 9ac65ab39..d81218bc8 100644
--- a/crates/ra_assists/src/ast_transform.rs
+++ b/crates/ra_assists/src/ast_transform.rs
@@ -2,6 +2,7 @@
2use rustc_hash::FxHashMap; 2use rustc_hash::FxHashMap;
3 3
4use hir::{PathResolution, SemanticsScope}; 4use hir::{PathResolution, SemanticsScope};
5use hir_def::type_ref::TypeRef;
5use ra_ide_db::RootDatabase; 6use ra_ide_db::RootDatabase;
6use ra_syntax::{ 7use ra_syntax::{
7 algo::SyntaxRewriter, 8 algo::SyntaxRewriter,
@@ -51,7 +52,24 @@ impl<'a> SubstituteTypeParams<'a> {
51 .into_iter() 52 .into_iter()
52 // this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky 53 // this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky
53 .skip(1) 54 .skip(1)
54 .zip(substs.into_iter()) 55 // The actual list of trait type parameters may be longer than the one
56 // used in the `impl` block due to trailing default type parametrs.
57 // For that case we extend the `substs` with an empty iterator so we
58 // can still hit those trailing values and check if they actually have
59 // a default type. If they do, go for that type from `hir` to `ast` so
60 // the resulting change can be applied correctly.
61 .zip(substs.into_iter().map(Some).chain(std::iter::repeat(None)))
62 .filter_map(|(k, v)| match v {
63 Some(v) => Some((k, v)),
64 None => match k.default(source_scope.db)? {
65 TypeRef::Path(path) => Some((
66 k,
67 ast::make::type_arg(&format!("{}", path.mod_path().as_ident()?))
68 .type_ref()?,
69 )),
70 _ => None,
71 },
72 })
55 .collect(); 73 .collect();
56 return SubstituteTypeParams { 74 return SubstituteTypeParams {
57 source_scope, 75 source_scope,