Simplify
This commit is contained in:
parent
a6638af4a6
commit
6eb05c4a14
@ -37,7 +37,6 @@ pub struct SubstituteTypeParams<'a> {
|
||||
impl<'a> SubstituteTypeParams<'a> {
|
||||
pub fn for_trait_impl(
|
||||
source_scope: &'a SemanticsScope<'a, RootDatabase>,
|
||||
db: &'a RootDatabase,
|
||||
// FIXME: there's implicit invariant that `trait_` and `source_scope` match...
|
||||
trait_: hir::Trait,
|
||||
impl_def: ast::ImplDef,
|
||||
@ -45,7 +44,7 @@ pub fn for_trait_impl(
|
||||
let substs = get_syntactic_substs(impl_def).unwrap_or_default();
|
||||
let generic_def: hir::GenericDef = trait_.into();
|
||||
let substs_by_param: FxHashMap<_, _> = generic_def
|
||||
.params(db)
|
||||
.params(source_scope.db)
|
||||
.into_iter()
|
||||
// this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky
|
||||
.skip(1)
|
||||
@ -104,7 +103,6 @@ fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTrans
|
||||
pub struct QualifyPaths<'a> {
|
||||
target_scope: &'a SemanticsScope<'a, RootDatabase>,
|
||||
source_scope: &'a SemanticsScope<'a, RootDatabase>,
|
||||
db: &'a RootDatabase,
|
||||
previous: Box<dyn AstTransform<'a> + 'a>,
|
||||
}
|
||||
|
||||
@ -112,9 +110,8 @@ impl<'a> QualifyPaths<'a> {
|
||||
pub fn new(
|
||||
target_scope: &'a SemanticsScope<'a, RootDatabase>,
|
||||
source_scope: &'a SemanticsScope<'a, RootDatabase>,
|
||||
db: &'a RootDatabase,
|
||||
) -> Self {
|
||||
Self { target_scope, source_scope, db, previous: Box::new(NullTransformer) }
|
||||
Self { target_scope, source_scope, previous: Box::new(NullTransformer) }
|
||||
}
|
||||
|
||||
fn get_substitution_inner(
|
||||
@ -132,7 +129,7 @@ fn get_substitution_inner(
|
||||
let resolution = self.source_scope.resolve_hir_path(&hir_path?)?;
|
||||
match resolution {
|
||||
PathResolution::Def(def) => {
|
||||
let found_path = from.find_use_path(self.db, def)?;
|
||||
let found_path = from.find_use_path(self.source_scope.db, def)?;
|
||||
let mut path = path_to_ast(found_path);
|
||||
|
||||
let type_args = p
|
||||
|
@ -142,8 +142,8 @@ fn add_missing_impl_members_inner(
|
||||
let n_existing_items = impl_item_list.impl_items().count();
|
||||
let source_scope = sema.scope_for_def(trait_);
|
||||
let target_scope = sema.scope(impl_item_list.syntax());
|
||||
let ast_transform = QualifyPaths::new(&target_scope, &source_scope, sema.db)
|
||||
.or(SubstituteTypeParams::for_trait_impl(&source_scope, sema.db, trait_, impl_node));
|
||||
let ast_transform = QualifyPaths::new(&target_scope, &source_scope)
|
||||
.or(SubstituteTypeParams::for_trait_impl(&source_scope, trait_, impl_node));
|
||||
let items = missing_items
|
||||
.into_iter()
|
||||
.map(|it| ast_transform::apply(&*ast_transform, it))
|
||||
|
Loading…
Reference in New Issue
Block a user