Skip to content

Commit eefe02c

Browse files
committed
Add two more tests
1 parent 9d6061f commit eefe02c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

crates/ra_hir_ty/src/tests/traits.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,31 @@ fn test() {
10131013
);
10141014
}
10151015

1016+
#[test]
1017+
fn argument_impl_trait_to_fn_pointer() {
1018+
assert_snapshot!(
1019+
infer_with_mismatches(r#"
1020+
trait Trait {}
1021+
fn foo(x: impl Trait) { loop {} }
1022+
struct S;
1023+
impl Trait for S {}
1024+
1025+
fn test() {
1026+
let f: fn(S) -> () = foo;
1027+
}
1028+
"#, true),
1029+
@r###"
1030+
[23; 24) 'x': impl Trait
1031+
[38; 49) '{ loop {} }': ()
1032+
[40; 47) 'loop {}': !
1033+
[45; 47) '{}': ()
1034+
[91; 124) '{ ...foo; }': ()
1035+
[101; 102) 'f': fn(S) -> ()
1036+
[118; 121) 'foo': fn foo(S) -> ()
1037+
"###
1038+
);
1039+
}
1040+
10161041
#[test]
10171042
#[ignore]
10181043
fn impl_trait() {
@@ -1376,6 +1401,32 @@ fn test<T: Trait1, U: Trait2>(x: T, y: U) {
13761401
);
13771402
}
13781403

1404+
#[test]
1405+
fn super_trait_impl_trait_method_resolution() {
1406+
assert_snapshot!(
1407+
infer(r#"
1408+
mod foo {
1409+
trait SuperTrait {
1410+
fn foo(&self) -> u32 {}
1411+
}
1412+
}
1413+
trait Trait1: foo::SuperTrait {}
1414+
1415+
fn test(x: &impl Trait1) {
1416+
x.foo();
1417+
}
1418+
"#),
1419+
@r###"
1420+
[50; 54) 'self': &Self
1421+
[63; 65) '{}': ()
1422+
[116; 117) 'x': &impl Trait1
1423+
[133; 149) '{ ...o(); }': ()
1424+
[139; 140) 'x': &impl Trait1
1425+
[139; 146) 'x.foo()': u32
1426+
"###
1427+
);
1428+
}
1429+
13791430
#[test]
13801431
fn super_trait_cycle() {
13811432
// This just needs to not crash

0 commit comments

Comments
 (0)