forked from intellij-rust/intellij-rust
-
Couldn't load subscription status.
- Fork 0
Draft of a type inference algorithm
Antoine Wacheux edited this page Feb 2, 2017
·
2 revisions
Modules have no type
Extern crate declaration have no type
Use declarations have no type
fn foo(x1 : T1, x2: T2, ..., xn: Tn) -> T { value }Functions declaration and Generic functions declaration does not have a type
Constraints
typeof(value) = T
fn foo(x1 : T1, x2: T2, ..., xn: Tn) -> !Diverging function declaration does not have a type
extern fn "ABI" foo(x1 : T1, x2: T2, ..., xn: Tn) -> T { value }This does not have a type Constraints
typeof(value) = T
type A = BConstraints
A = B
Struct declarations have no types
struct S {
f1: T1,
f2: T2,
...
fn: TN
}Constraint
- S becomes a new type
- If S implement a trait T, there is an implicit conversion of S to T
enum E {
V1,
V2,
...
Vn
}Constraints
- E becomes a new type
- For all i from 1 to N
typeof(Vi) = (x1 : T1, x2: T2, ..., xn: Tn) -> E
const x: T = valueConstant items declaration does not have type
Constraints
typeof(value) = T
static x: T = valueStatic items declaration does not have type
Constraints
typeof(value) = T
trait T {
}Trait declaration does not have type
Constraints
- T become a new type
- If T implement S then T there is an implicit conversion of T to S
Implementation does not have a type
struct S {}
impl S {
fn foo(self: T1, x2: T2, ...) -> R {}
}Constraint
- if a function contains a
selfargument, thentypeof(self) = S
struct S {}
trait T {}
impl T for S {
fn foo(self: T1, x2: T2, ...) -> R {}
}Constraint
- if a function contains a
selfargument, thentypeof(self) = S
External blocks does not have a type