Skip to content

Commit 481fab1

Browse files
committed
chore: add test case for assoc func fix in unresolved_method diagnostic
1 parent 69410bb commit 481fab1

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,85 @@ fn assoc_func_fix(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedMethodCall) -
202202
mod tests {
203203
use crate::tests::{check_diagnostics, check_fix};
204204

205+
#[test]
206+
fn test_assoc_func_fix() {
207+
check_fix(
208+
r#"
209+
struct A {}
210+
211+
impl A {
212+
fn hello() {}
213+
}
214+
fn main() {
215+
let a = A{};
216+
a.hello$0();
217+
}
218+
"#,
219+
r#"
220+
struct A {}
221+
222+
impl A {
223+
fn hello() {}
224+
}
225+
fn main() {
226+
let a = A{};
227+
A::hello();
228+
}
229+
"#,
230+
);
231+
}
232+
233+
#[test]
234+
fn test_assoc_func_diagnostic() {
235+
check_diagnostics(
236+
r#"
237+
struct A {}
238+
impl A {
239+
fn hello() {}
240+
}
241+
fn main() {
242+
let a = A{};
243+
a.hello();
244+
// ^^^^^^^^^ 💡 error: no method `hello` on type `A`, but an associated function with a similar name exists
245+
}
246+
"#,
247+
);
248+
}
249+
250+
#[test]
251+
fn test_assoc_func_fix_with_generic() {
252+
check_fix(
253+
r#"
254+
struct A<T, U> {
255+
a: T,
256+
b: U
257+
}
258+
259+
impl<T, U> A<T, U> {
260+
fn foo() {}
261+
}
262+
fn main() {
263+
let a = A {a: 0, b: ""};
264+
a.foo()$0;
265+
}
266+
"#,
267+
r#"
268+
struct A<T, U> {
269+
a: T,
270+
b: U
271+
}
272+
273+
impl<T, U> A<T, U> {
274+
fn foo() {}
275+
}
276+
fn main() {
277+
let a = A {a: 0, b: ""};
278+
A::<i32, &str>::foo();
279+
}
280+
"#,
281+
);
282+
}
283+
205284
#[test]
206285
fn smoke_test() {
207286
check_diagnostics(

0 commit comments

Comments
 (0)