Skip to content

Commit bf0c3ec

Browse files
bors[bot]matklad
andauthored
Merge #3583
3583: Simplify r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 4c85e53 + 6eb05c4 commit bf0c3ec

File tree

5 files changed

+33
-37
lines changed

5 files changed

+33
-37
lines changed

crates/ra_assists/src/ast_transform.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ pub struct SubstituteTypeParams<'a> {
3737
impl<'a> SubstituteTypeParams<'a> {
3838
pub fn for_trait_impl(
3939
source_scope: &'a SemanticsScope<'a, RootDatabase>,
40-
db: &'a RootDatabase,
4140
// FIXME: there's implicit invariant that `trait_` and `source_scope` match...
4241
trait_: hir::Trait,
4342
impl_def: ast::ImplDef,
4443
) -> SubstituteTypeParams<'a> {
4544
let substs = get_syntactic_substs(impl_def).unwrap_or_default();
4645
let generic_def: hir::GenericDef = trait_.into();
4746
let substs_by_param: FxHashMap<_, _> = generic_def
48-
.params(db)
47+
.params(source_scope.db)
4948
.into_iter()
5049
// this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky
5150
.skip(1)
@@ -104,17 +103,15 @@ impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> {
104103
pub struct QualifyPaths<'a> {
105104
target_scope: &'a SemanticsScope<'a, RootDatabase>,
106105
source_scope: &'a SemanticsScope<'a, RootDatabase>,
107-
db: &'a RootDatabase,
108106
previous: Box<dyn AstTransform<'a> + 'a>,
109107
}
110108

111109
impl<'a> QualifyPaths<'a> {
112110
pub fn new(
113111
target_scope: &'a SemanticsScope<'a, RootDatabase>,
114112
source_scope: &'a SemanticsScope<'a, RootDatabase>,
115-
db: &'a RootDatabase,
116113
) -> Self {
117-
Self { target_scope, source_scope, db, previous: Box::new(NullTransformer) }
114+
Self { target_scope, source_scope, previous: Box::new(NullTransformer) }
118115
}
119116

120117
fn get_substitution_inner(
@@ -132,7 +129,7 @@ impl<'a> QualifyPaths<'a> {
132129
let resolution = self.source_scope.resolve_hir_path(&hir_path?)?;
133130
match resolution {
134131
PathResolution::Def(def) => {
135-
let found_path = from.find_use_path(self.db, def)?;
132+
let found_path = from.find_use_path(self.source_scope.db, def)?;
136133
let mut path = path_to_ast(found_path);
137134

138135
let type_args = p

crates/ra_assists/src/handlers/add_missing_impl_members.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ fn add_missing_impl_members_inner(
142142
let n_existing_items = impl_item_list.impl_items().count();
143143
let source_scope = sema.scope_for_def(trait_);
144144
let target_scope = sema.scope(impl_item_list.syntax());
145-
let ast_transform = QualifyPaths::new(&target_scope, &source_scope, sema.db)
146-
.or(SubstituteTypeParams::for_trait_impl(&source_scope, sema.db, trait_, impl_node));
145+
let ast_transform = QualifyPaths::new(&target_scope, &source_scope)
146+
.or(SubstituteTypeParams::for_trait_impl(&source_scope, trait_, impl_node));
147147
let items = missing_items
148148
.into_iter()
149149
.map(|it| ast_transform::apply(&*ast_transform, it))

crates/ra_assists/src/handlers/fill_match_arms.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::iter;
44

5-
use hir::{db::HirDatabase, Adt, HasSource, Semantics};
5+
use hir::{Adt, HasSource, Semantics};
66
use ra_syntax::ast::{self, edit::IndentLevel, make, AstNode, NameOwner};
77

88
use crate::{Assist, AssistCtx, AssistId};
@@ -88,11 +88,7 @@ fn resolve_enum_def(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<
8888
})
8989
}
9090

91-
fn build_pat(
92-
db: &impl HirDatabase,
93-
module: hir::Module,
94-
var: hir::EnumVariant,
95-
) -> Option<ast::Pat> {
91+
fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> Option<ast::Pat> {
9692
let path = crate::ast_transform::path_to_ast(module.find_use_path(db, var.into())?);
9793

9894
// FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though

crates/ra_ide/src/completion/presentation.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This modules takes care of rendering various definitions as completion items.
22
3-
use hir::{db::HirDatabase, Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type};
3+
use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type};
44
use join_to_string::join;
55
use ra_syntax::ast::NameOwner;
66
use test_utils::tested_by;
@@ -9,7 +9,10 @@ use crate::completion::{
99
CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
1010
};
1111

12-
use crate::display::{const_label, macro_label, type_label, FunctionSignature};
12+
use crate::{
13+
display::{const_label, macro_label, type_label, FunctionSignature},
14+
RootDatabase,
15+
};
1316

1417
impl Completions {
1518
pub(crate) fn add_field(
@@ -300,7 +303,7 @@ impl Completions {
300303
}
301304
}
302305

303-
fn is_deprecated(node: impl HasAttrs, db: &impl HirDatabase) -> bool {
306+
fn is_deprecated(node: impl HasAttrs, db: &RootDatabase) -> bool {
304307
node.attrs(db).by_key("deprecated").exists()
305308
}
306309

crates/ra_ide/src/typing.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,23 @@ fn foo() {
213213
type_char(
214214
'.',
215215
r"
216-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
217-
self.child_impl(db, name)
216+
fn main() {
217+
xs.foo()
218218
<|>
219219
}
220220
",
221221
r"
222-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
223-
self.child_impl(db, name)
222+
fn main() {
223+
xs.foo()
224224
.
225225
}
226226
",
227227
);
228228
type_char_noop(
229229
'.',
230230
r"
231-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
232-
self.child_impl(db, name)
231+
fn main() {
232+
xs.foo()
233233
<|>
234234
}
235235
",
@@ -241,23 +241,23 @@ fn foo() {
241241
type_char(
242242
'.',
243243
r"
244-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
245-
self.child_impl(db, name)
244+
fn main() {
245+
xs.foo()
246246
<|>;
247247
}
248248
",
249249
r"
250-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
251-
self.child_impl(db, name)
250+
fn main() {
251+
xs.foo()
252252
.;
253253
}
254254
",
255255
);
256256
type_char_noop(
257257
'.',
258258
r"
259-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
260-
self.child_impl(db, name)
259+
fn main() {
260+
xs.foo()
261261
<|>;
262262
}
263263
",
@@ -269,15 +269,15 @@ fn foo() {
269269
type_char(
270270
'.',
271271
r"
272-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
273-
self.child_impl(db, name)
272+
fn main() {
273+
xs.foo()
274274
.first()
275275
<|>
276276
}
277277
",
278278
r"
279-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
280-
self.child_impl(db, name)
279+
fn main() {
280+
xs.foo()
281281
.first()
282282
.
283283
}
@@ -286,8 +286,8 @@ fn foo() {
286286
type_char_noop(
287287
'.',
288288
r"
289-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
290-
self.child_impl(db, name)
289+
fn main() {
290+
xs.foo()
291291
.first()
292292
<|>
293293
}
@@ -334,15 +334,15 @@ fn foo() {
334334
type_char_noop(
335335
'.',
336336
r"
337-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
337+
fn main() {
338338
<|>
339339
}
340340
",
341341
);
342342
type_char_noop(
343343
'.',
344344
r"
345-
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
345+
fn main() {
346346
<|>
347347
}
348348
",

0 commit comments

Comments
 (0)