diff options
Diffstat (limited to 'crates/ra_assists/src/ast_transform.rs')
-rw-r--r-- | crates/ra_assists/src/ast_transform.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 56b7588ef..c6d15af5f 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs | |||
@@ -1,7 +1,8 @@ | |||
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. |
2 | use rustc_hash::FxHashMap; | 2 | use rustc_hash::FxHashMap; |
3 | 3 | ||
4 | use hir::{db::HirDatabase, InFile, PathResolution}; | 4 | use hir::{InFile, PathResolution}; |
5 | use ra_ide_db::RootDatabase; | ||
5 | use ra_syntax::ast::{self, AstNode}; | 6 | use ra_syntax::ast::{self, AstNode}; |
6 | 7 | ||
7 | pub trait AstTransform<'a> { | 8 | pub trait AstTransform<'a> { |
@@ -33,18 +34,18 @@ impl<'a> AstTransform<'a> for NullTransformer { | |||
33 | } | 34 | } |
34 | } | 35 | } |
35 | 36 | ||
36 | pub struct SubstituteTypeParams<'a, DB: HirDatabase> { | 37 | pub struct SubstituteTypeParams<'a> { |
37 | db: &'a DB, | 38 | db: &'a RootDatabase, |
38 | substs: FxHashMap<hir::TypeParam, ast::TypeRef>, | 39 | substs: FxHashMap<hir::TypeParam, ast::TypeRef>, |
39 | previous: Box<dyn AstTransform<'a> + 'a>, | 40 | previous: Box<dyn AstTransform<'a> + 'a>, |
40 | } | 41 | } |
41 | 42 | ||
42 | impl<'a, DB: HirDatabase> SubstituteTypeParams<'a, DB> { | 43 | impl<'a> SubstituteTypeParams<'a> { |
43 | pub fn for_trait_impl( | 44 | pub fn for_trait_impl( |
44 | db: &'a DB, | 45 | db: &'a RootDatabase, |
45 | trait_: hir::Trait, | 46 | trait_: hir::Trait, |
46 | impl_block: ast::ImplBlock, | 47 | impl_block: ast::ImplBlock, |
47 | ) -> SubstituteTypeParams<'a, DB> { | 48 | ) -> SubstituteTypeParams<'a> { |
48 | let substs = get_syntactic_substs(impl_block).unwrap_or_default(); | 49 | let substs = get_syntactic_substs(impl_block).unwrap_or_default(); |
49 | let generic_def: hir::GenericDef = trait_.into(); | 50 | let generic_def: hir::GenericDef = trait_.into(); |
50 | let substs_by_param: FxHashMap<_, _> = generic_def | 51 | let substs_by_param: FxHashMap<_, _> = generic_def |
@@ -95,7 +96,7 @@ impl<'a, DB: HirDatabase> SubstituteTypeParams<'a, DB> { | |||
95 | } | 96 | } |
96 | } | 97 | } |
97 | 98 | ||
98 | impl<'a, DB: HirDatabase> AstTransform<'a> for SubstituteTypeParams<'a, DB> { | 99 | impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> { |
99 | fn get_substitution( | 100 | fn get_substitution( |
100 | &self, | 101 | &self, |
101 | node: InFile<&ra_syntax::SyntaxNode>, | 102 | node: InFile<&ra_syntax::SyntaxNode>, |
@@ -107,14 +108,14 @@ impl<'a, DB: HirDatabase> AstTransform<'a> for SubstituteTypeParams<'a, DB> { | |||
107 | } | 108 | } |
108 | } | 109 | } |
109 | 110 | ||
110 | pub struct QualifyPaths<'a, DB: HirDatabase> { | 111 | pub struct QualifyPaths<'a> { |
111 | db: &'a DB, | 112 | db: &'a RootDatabase, |
112 | from: Option<hir::Module>, | 113 | from: Option<hir::Module>, |
113 | previous: Box<dyn AstTransform<'a> + 'a>, | 114 | previous: Box<dyn AstTransform<'a> + 'a>, |
114 | } | 115 | } |
115 | 116 | ||
116 | impl<'a, DB: HirDatabase> QualifyPaths<'a, DB> { | 117 | impl<'a> QualifyPaths<'a> { |
117 | pub fn new(db: &'a DB, from: Option<hir::Module>) -> Self { | 118 | pub fn new(db: &'a RootDatabase, from: Option<hir::Module>) -> Self { |
118 | Self { db, from, previous: Box::new(NullTransformer) } | 119 | Self { db, from, previous: Box::new(NullTransformer) } |
119 | } | 120 | } |
120 | 121 | ||
@@ -168,7 +169,7 @@ pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: InFile<N> | |||
168 | N::cast(result).unwrap() | 169 | N::cast(result).unwrap() |
169 | } | 170 | } |
170 | 171 | ||
171 | impl<'a, DB: HirDatabase> AstTransform<'a> for QualifyPaths<'a, DB> { | 172 | impl<'a> AstTransform<'a> for QualifyPaths<'a> { |
172 | fn get_substitution( | 173 | fn get_substitution( |
173 | &self, | 174 | &self, |
174 | node: InFile<&ra_syntax::SyntaxNode>, | 175 | node: InFile<&ra_syntax::SyntaxNode>, |