Skip to content

Commit def124e

Browse files
committed
Fix file ID when qualifying paths; add another failing test
1 parent 4545f28 commit def124e

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

crates/ra_assists/src/assists/add_missing_impl_members.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ fn add_missing_impl_members_inner(
134134
return None;
135135
}
136136

137-
let file_id = ctx.frange.file_id;
138137
let db = ctx.db;
138+
let file_id = ctx.frange.file_id;
139+
let trait_file_id = trait_.source(db).file_id;
139140

140141
ctx.add_assist(AssistId(assist_id), label, |edit| {
141142
let n_existing_items = impl_item_list.impl_items().count();
@@ -157,10 +158,10 @@ fn add_missing_impl_members_inner(
157158
let items = missing_items
158159
.into_iter()
159160
.map(|it| {
160-
substitute_type_params(db, hir::InFile::new(file_id.into(), it), &substs_by_param)
161+
substitute_type_params(db, hir::InFile::new(trait_file_id, it), &substs_by_param)
161162
})
162163
.map(|it| match module {
163-
Some(module) => qualify_paths(db, hir::InFile::new(file_id.into(), it), module),
164+
Some(module) => qualify_paths(db, hir::InFile::new(trait_file_id, it), module),
164165
None => it,
165166
})
166167
.map(|it| match it {
@@ -259,6 +260,7 @@ fn qualify_paths<N: AstNode>(db: &impl HirDatabase, node: hir::InFile<N>, from:
259260
match resolution {
260261
PathResolution::Def(def) => {
261262
let found_path = from.find_path(db, def)?;
263+
// TODO fix type arg replacements being qualified
262264
let args = p
263265
.segment()
264266
.and_then(|s| s.type_arg_list())
@@ -523,6 +525,32 @@ impl foo::Foo<u32> for S {
523525
);
524526
}
525527

528+
#[test]
529+
fn test_substitute_param_no_qualify() {
530+
// when substituting params, the substituted param should not be qualified!
531+
check_assist(
532+
add_missing_impl_members,
533+
"
534+
mod foo {
535+
trait Foo<T> { fn foo(&self, bar: T); }
536+
pub struct Param;
537+
}
538+
struct Param;
539+
struct S;
540+
impl foo::Foo<Param> for S { <|> }",
541+
"
542+
mod foo {
543+
trait Foo<T> { fn foo(&self, bar: T); }
544+
pub struct Param;
545+
}
546+
struct Param;
547+
struct S;
548+
impl foo::Foo<Param> for S {
549+
<|>fn foo(&self, bar: Param) { unimplemented!() }
550+
}",
551+
);
552+
}
553+
526554
#[test]
527555
fn test_qualify_path_associated_item() {
528556
check_assist(

0 commit comments

Comments
 (0)