Implement type variables
This will really become necessary when we implement generics, but even now, it allows us to reason 'backwards' to infer types of expressions that we didn't understand for some reason. We use ena, the union-find implementation extracted from rustc, to keep track of type variables.
This commit is contained in:
@@ -113,6 +113,27 @@ fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_backwards() {
|
||||
check_inference(
|
||||
r#"
|
||||
fn takes_u32(x: u32) {}
|
||||
|
||||
struct S { i32_field: i32 }
|
||||
|
||||
fn test() -> &mut &f64 {
|
||||
let a = unknown_function();
|
||||
takes_u32(a);
|
||||
let b = unknown_function();
|
||||
S { i32_field: b };
|
||||
let c = unknown_function();
|
||||
&mut &c
|
||||
}
|
||||
"#,
|
||||
"0006_backwards.txt",
|
||||
);
|
||||
}
|
||||
|
||||
fn infer(content: &str) -> String {
|
||||
let (db, _, file_id) = MockDatabase::with_single_file(content);
|
||||
let source_file = db.source_file(file_id);
|
||||
|
||||
Reference in New Issue
Block a user