Description
I am reading the Rust reference to learn Rust.
I reached 8.2.4, "Type cast expressions".
I read over the table. Immediately I found myself asking: What happens if you cast to bool
? It's not listed.
I tested it, and immediately found that casting to bool is illegal.
Looking at the table after testing it, in retrospect this is "obvious". The reference says: "as
can be used to explicitly perform coercions [link to coercion section in reference], as well as the following additional casts". It does not say as
can be used for anything else. Therefore, any cast not listed in either the coercion rules or the table must be illegal.
But, I was not able to figure that out just from reading the text! It is too easy to misinterpret "it can be used to do this..." as an example, rather than (as it is apparently intended) a normative definition.
"Expected behavior": What would have helped me is somehow explicitly noting that "coercions, as well as the following additional casts" is exhaustive. So for example putting "(and no others)" after "following additional casts", or putting a sentence after the table saying "Any cast which is not either a defined coercion, or in the above table, is an error".