Skip to content

Commit 2b06611

Browse files
committed
one more test. this test itself isn't very interesting but it revealed that this only works on T's not &T's
1 parent d7ba48a commit 2b06611

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

crates/ide-diagnostics/src/handlers/unresolved_method.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedMethodCall<'_>) -> Opt
7777
}
7878

7979
/// Fix to add the missing method.
80-
fn add_method_fix(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedMethodCall) -> Option<Assist> {
80+
fn add_method_fix(
81+
ctx: &DiagnosticsContext<'_>,
82+
d: &hir::UnresolvedMethodCall<'_>,
83+
) -> Option<Assist> {
8184
let root = ctx.sema.db.parse_or_expand(d.expr.file_id);
8285
let expr = d.expr.value.to_node(&root).left()?;
8386

@@ -356,6 +359,60 @@ fn main() {
356359
);
357360
}
358361

362+
#[test]
363+
fn test_add_method_from_same_impl_block() {
364+
check_fix(
365+
r#"
366+
struct Tiger;
367+
368+
impl Tiger {
369+
fn sleep(&self) {}
370+
fn do_stuff(self) {
371+
self.sleep();
372+
self.roar$0();
373+
self.sleep();
374+
}
375+
}"#,
376+
r#"
377+
struct Tiger;
378+
379+
impl Tiger {
380+
fn sleep(&self) {}
381+
fn do_stuff(self) {
382+
self.sleep();
383+
self.roar();
384+
self.sleep();
385+
}
386+
fn roar(&self) { todo!() }
387+
}"#,
388+
);
389+
}
390+
391+
#[test]
392+
#[cfg(false)]
393+
fn test_add_method_with_args() {
394+
check_fix(
395+
r#"
396+
struct Speaker;
397+
398+
impl Speaker {
399+
fn greet(&self) {
400+
self.say("hello");$0
401+
}
402+
}"#,
403+
r#"
404+
struct Speaker;
405+
406+
impl Speaker {
407+
fn greet(&self) {
408+
self.say("hello");
409+
}
410+
411+
fn say(&self, arg1: &str) {}
412+
}"#,
413+
);
414+
}
415+
359416
#[test]
360417
fn smoke_test_in_macro_def_site() {
361418
check_diagnostics(

0 commit comments

Comments
 (0)