3583: Simplify r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-03-13 17:02:32 +00:00 committed by GitHub
commit bf0c3ec67e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 37 deletions

View file

@ -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 @@ impl<'a> SubstituteTypeParams<'a> {
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 @@ impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> {
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 @@ impl<'a> QualifyPaths<'a> {
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

View file

@ -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))

View file

@ -2,7 +2,7 @@
use std::iter;
use hir::{db::HirDatabase, Adt, HasSource, Semantics};
use hir::{Adt, HasSource, Semantics};
use ra_syntax::ast::{self, edit::IndentLevel, make, AstNode, NameOwner};
use crate::{Assist, AssistCtx, AssistId};
@ -88,11 +88,7 @@ fn resolve_enum_def(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<
})
}
fn build_pat(
db: &impl HirDatabase,
module: hir::Module,
var: hir::EnumVariant,
) -> Option<ast::Pat> {
fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> Option<ast::Pat> {
let path = crate::ast_transform::path_to_ast(module.find_use_path(db, var.into())?);
// FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though

View file

@ -1,6 +1,6 @@
//! This modules takes care of rendering various definitions as completion items.
use hir::{db::HirDatabase, Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type};
use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type};
use join_to_string::join;
use ra_syntax::ast::NameOwner;
use test_utils::tested_by;
@ -9,7 +9,10 @@ use crate::completion::{
CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
};
use crate::display::{const_label, macro_label, type_label, FunctionSignature};
use crate::{
display::{const_label, macro_label, type_label, FunctionSignature},
RootDatabase,
};
impl Completions {
pub(crate) fn add_field(
@ -300,7 +303,7 @@ impl Completions {
}
}
fn is_deprecated(node: impl HasAttrs, db: &impl HirDatabase) -> bool {
fn is_deprecated(node: impl HasAttrs, db: &RootDatabase) -> bool {
node.attrs(db).by_key("deprecated").exists()
}

View file

@ -213,14 +213,14 @@ fn foo() {
type_char(
'.',
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
self.child_impl(db, name)
fn main() {
xs.foo()
<|>
}
",
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
self.child_impl(db, name)
fn main() {
xs.foo()
.
}
",
@ -228,8 +228,8 @@ fn foo() {
type_char_noop(
'.',
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
self.child_impl(db, name)
fn main() {
xs.foo()
<|>
}
",
@ -241,14 +241,14 @@ fn foo() {
type_char(
'.',
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
self.child_impl(db, name)
fn main() {
xs.foo()
<|>;
}
",
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
self.child_impl(db, name)
fn main() {
xs.foo()
.;
}
",
@ -256,8 +256,8 @@ fn foo() {
type_char_noop(
'.',
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
self.child_impl(db, name)
fn main() {
xs.foo()
<|>;
}
",
@ -269,15 +269,15 @@ fn foo() {
type_char(
'.',
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
self.child_impl(db, name)
fn main() {
xs.foo()
.first()
<|>
}
",
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
self.child_impl(db, name)
fn main() {
xs.foo()
.first()
.
}
@ -286,8 +286,8 @@ fn foo() {
type_char_noop(
'.',
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
self.child_impl(db, name)
fn main() {
xs.foo()
.first()
<|>
}
@ -334,7 +334,7 @@ fn foo() {
type_char_noop(
'.',
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
fn main() {
<|>
}
",
@ -342,7 +342,7 @@ fn foo() {
type_char_noop(
'.',
r"
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
fn main() {
<|>
}
",