Skip to content

Commit 39720a1

Browse files
committed
Rust: More type inference tests
1 parent b0dc48e commit 39720a1

File tree

3 files changed

+2713
-2435
lines changed

3 files changed

+2713
-2435
lines changed

rust/ql/test/library-tests/type-inference/CONSISTENCY/PathResolutionConsistency.expected

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ multipleCallTargets
66
| dereference.rs:186:17:186:25 | S.bar(...) |
77
| dereference.rs:187:17:187:29 | S.bar(...) |
88
| main.rs:590:9:590:18 | ...::m(...) |
9-
| main.rs:2553:13:2553:31 | ...::from(...) |
10-
| main.rs:2554:13:2554:31 | ...::from(...) |
11-
| main.rs:2555:13:2555:31 | ...::from(...) |
12-
| main.rs:2561:13:2561:31 | ...::from(...) |
13-
| main.rs:2562:13:2562:31 | ...::from(...) |
14-
| main.rs:2563:13:2563:31 | ...::from(...) |
9+
| main.rs:2634:13:2634:31 | ...::from(...) |
10+
| main.rs:2635:13:2635:31 | ...::from(...) |
11+
| main.rs:2636:13:2636:31 | ...::from(...) |
12+
| main.rs:2642:13:2642:31 | ...::from(...) |
13+
| main.rs:2643:13:2643:31 | ...::from(...) |
14+
| main.rs:2644:13:2644:31 | ...::from(...) |

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,87 @@ mod builtins {
17361736
let f = 123.0f64; // $ certainType=f:f64
17371737
let t = true; // $ certainType=t:bool
17381738
let f = false; // $ certainType=f:bool
1739+
1740+
trait MyTrait<T> {
1741+
fn my_method(&self) -> &T;
1742+
1743+
fn my_func() -> T;
1744+
}
1745+
1746+
impl<T: Default, const N: usize> MyTrait<T> for [T; N] {
1747+
fn my_method(&self) -> &T {
1748+
self.get(0).unwrap() // $ MISSING: target=get target=unwrap
1749+
}
1750+
1751+
fn my_func() -> T {
1752+
T::default() // $ target=default
1753+
}
1754+
}
1755+
1756+
let x = [1, 2, 3].my_method(); // $ target=my_method type=x:&T.i32
1757+
let x = <[_; 3]>::my_method(&[1, 2, 3]); // $ target=my_method type=x:&T.i32
1758+
let x = <[i32; 3]>::my_func(); // $ MISSING: target=my_func type=x:i32
1759+
1760+
impl<T: Default> MyTrait<T> for [T] {
1761+
fn my_method(&self) -> &T {
1762+
self.get(0).unwrap() // $ target=get target=unwrap
1763+
}
1764+
1765+
fn my_func() -> T {
1766+
T::default() // $ target=default
1767+
}
1768+
}
1769+
1770+
let s: &[i32] = &[1, 2, 3];
1771+
let x = s.my_method(); // $ target=my_method type=x:&T.i32
1772+
let x = <[_]>::my_method(s); // $ target=my_method type=x:&T.i32
1773+
let x = <[i32]>::my_func(); // $ MISSING: target=my_func type=x:i32
1774+
1775+
impl<T: Default> MyTrait<T> for (T, i32) {
1776+
fn my_method(&self) -> &T {
1777+
&self.0
1778+
}
1779+
1780+
fn my_func() -> T {
1781+
T::default() // $ target=default
1782+
}
1783+
}
1784+
1785+
let p = (42, 7);
1786+
let x = p.my_method(); // $ target=my_method type=x:&T.i32
1787+
let x = <(_, _)>::my_method(&p); // $ target=my_method type=x:&T.i32
1788+
let x = <(i32, i32)>::my_func(); // $ MISSING: target=my_func type=x:i32
1789+
1790+
impl<T: Default> MyTrait<T> for &T {
1791+
fn my_method(&self) -> &T {
1792+
*self // $ target=deref
1793+
}
1794+
1795+
fn my_func() -> T {
1796+
T::default() // $ target=default
1797+
}
1798+
}
1799+
1800+
let r = &42;
1801+
let x = r.my_method(); // $ target=my_method type=x:&T.i32
1802+
let x = <&_>::my_method(&r); // $ target=my_method type=x:&T.i32
1803+
let x = <&i32>::my_func(); // $ MISSING: target=my_func type=x:i32
1804+
1805+
impl<T: Default> MyTrait<T> for *mut T {
1806+
fn my_method(&self) -> &T {
1807+
unsafe { &**self } // $ target=deref target=deref
1808+
}
1809+
1810+
fn my_func() -> T {
1811+
T::default() // $ target=default
1812+
}
1813+
}
1814+
1815+
let mut v = 42;
1816+
let p: *mut i32 = &mut v;
1817+
let x = unsafe { p.my_method() }; // $ target=my_method type=x:&T.i32
1818+
let x = unsafe { <*mut _>::my_method(&p) }; // $ target=my_method type=x:&T.i32
1819+
let x = <*mut i32>::my_func(); // $ MISSING: target=my_func type=x:i32
17391820
}
17401821
}
17411822

0 commit comments

Comments
 (0)