Skip to content

Commit 6b9d05d

Browse files
committed
Fix add_new assist (kind of)
1 parent b0bb862 commit 6b9d05d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

crates/ra_assists/src/handlers/add_new.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use format_buf::format;
2-
use hir::InFile;
2+
use hir::{Adt, InFile};
33
use join_to_string::join;
44
use ra_syntax::{
55
ast::{
@@ -135,17 +135,22 @@ fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<a
135135
})?;
136136
let mut sb = ctx.source_binder();
137137

138-
let struct_ty = {
138+
let struct_def = {
139139
let src = InFile { file_id: ctx.frange.file_id.into(), value: strukt.clone() };
140-
sb.to_def(src)?.ty(db)
140+
sb.to_def(src)?
141141
};
142142

143143
let block = module.descendants().filter_map(ast::ImplBlock::cast).find_map(|impl_blk| {
144144
let src = InFile { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() };
145145
let blk = sb.to_def(src)?;
146146

147-
// TODO this check doesn't work
148-
let same_ty = blk.target_ty(db) == struct_ty;
147+
// FIXME: handle e.g. `struct S<T>; impl<U> S<U> {}`
148+
// (we currently use the wrong type parameter)
149+
// also we wouldn't want to use e.g. `impl S<u32>`
150+
let same_ty = match blk.target_ty(db).as_adt() {
151+
Some(def) => def == Adt::Struct(struct_def),
152+
None => false,
153+
};
149154
let not_trait_impl = blk.target_trait(db).is_none();
150155

151156
if !(same_ty && not_trait_impl) {

0 commit comments

Comments
 (0)