Skip to content

Commit a5a07bd

Browse files
committed
Add tests for checking the impl self type
1 parent cfa50df commit a5a07bd

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

crates/ra_hir_ty/src/tests.rs

+14
Original file line numberDiff line numberDiff line change
@@ -3433,6 +3433,20 @@ pub fn baz() -> usize { 31usize }
34333433
assert_eq!("(i32, usize)", type_at_pos(&db, pos));
34343434
}
34353435

3436+
#[test]
3437+
fn method_resolution_unify_impl_self_type() {
3438+
let t = type_at(
3439+
r#"
3440+
//- /main.rs
3441+
struct S<T>;
3442+
impl S<u32> { fn foo(&self) -> u8 {} }
3443+
impl S<i32> { fn foo(&self) -> i8 {} }
3444+
fn test() { (S::<u32>.foo(), S::<i32>.foo())<|>; }
3445+
"#,
3446+
);
3447+
assert_eq!(t, "(u8, i8)");
3448+
}
3449+
34363450
#[test]
34373451
fn method_resolution_trait_before_autoref() {
34383452
let t = type_at(

crates/ra_ide/src/completion/complete_dot.rs

+33
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,39 @@ mod tests {
216216
);
217217
}
218218

219+
#[test]
220+
fn test_method_completion_only_fitting_impls() {
221+
assert_debug_snapshot!(
222+
do_ref_completion(
223+
r"
224+
struct A<T> {}
225+
impl A<u32> {
226+
fn the_method(&self) {}
227+
}
228+
impl A<i32> {
229+
fn the_other_method(&self) {}
230+
}
231+
fn foo(a: A<u32>) {
232+
a.<|>
233+
}
234+
",
235+
),
236+
@r###"
237+
[
238+
CompletionItem {
239+
label: "the_method()",
240+
source_range: [243; 243),
241+
delete: [243; 243),
242+
insert: "the_method()$0",
243+
kind: Method,
244+
lookup: "the_method",
245+
detail: "fn the_method(&self)",
246+
},
247+
]
248+
"###
249+
);
250+
}
251+
219252
#[test]
220253
fn test_trait_method_completion() {
221254
assert_debug_snapshot!(

0 commit comments

Comments
 (0)