Sisu
E0050

A type that cannot be inferred

Error

Built from the repository at commit a8614dc.

None takes the optional type its position expects. Where nothing says which type, Sisu cannot choose one.

Why

Every optional is an optional of some type: None of i64? and None of Tree? are different values. A let with no type has nothing to take it from.

A call of a generic function, class or variant has the same problem when nothing fixes one of its type parameters. first([]) gives T no type: the [] has none of its own, and a later use of the result does not count. Annotate the result, let x: i64? = first([]), or write the type arguments, first<i64>([]).

Some(None) has the same problem: Some holds a value of any type, and None has no type of its own. Annotate the optional, let x: i64?? = Some(None).

Ok(1) has the same problem: Ok holds the value, and nothing says the type of the error. Annotate the result, let r: Result<i64, string> = Ok(1). Err("bad") leaves the type of the value open in the same way.

x ?? None ?? 0 has the same problem, because ?? groups to the right. It is x ?? (None ?? 0), and nothing gives that None a type. To remove two layers from an i64??, write (x ?? None) ?? 0.

Broken

fn main() {
    let x = None
}

What sisu says

error[E0050]: cannot infer the type of `None`
 --> E0050.sisu:2:13
  |
2 |     let x = None
  |             ^^^^
  |
  = help: write the type: `let x: i64? = None`

sisu: 1 error
sisu: for more on a code, run `sisu explain <code>`: E0050

Fixed

fn main() {
    let x: i64? = None
    print(x ?? 0)
}