Closed
Description
Right now the compiler accepts partial type hints for casts with as
like this:
let x = &5 as *_;
However, it fails with a fully unrestricted type on the right hand side with a unhelpful error message:
.../type_hole_1.rs:35:18: 35:22 error: the type of this value must be known in this context
.../type_hole_1.rs:35 let a: int = 1u32 as _;
^~~~
To quote @nikomatsakis:
"The reason that the type check doesn't work is because we check immediately that the as
conversion is legal. We could just say that the type of <expr> as T
is T
and then go back and check later that the type conversion is legal once types are known. I kind of like that."
There are three possible ways to resolve this:
- Explicitly allow type placeholders in
as
, which means fixing theas _
case. - Explicitly forbid type placeholders in
as
, which means preventing partial type hints inas
in general. - Only forbid
as _
, while allowing partial type hints otherwise. This means catching the error case and emitting a useful error message.