Skip to content

Commit 486710c

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 4d54aab commit 486710c

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

@@ -359,6 +362,60 @@ fn main() {
359362
);
360363
}
361364

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

0 commit comments

Comments
 (0)