Type ascription

what is the current status of Type ascription?
RFC 803, "Type ascription" #23416 seems to be stalled.

I'd like to know if the feature is in the beta or nightly builds?

It's available on nightly under #![feature(type_ascription)], but it is not currently on a path to stabilization. What use case would it enable for you?

2 Likes

I don't remember exactly what my code looked like. I was attempting to return a case where there were no args. I'm following someone using C and I wanted to reproduce the functionality of assert (*argv = NULL), in the most literal way imaginable.

And after a short time with Googling I came up with a way to Option(None) somehow.

assert_eq!(env::args().len(), Option(None));

That will error[E0423], I've worked around it since.
I thought myself quite cleaver that I found a way to maybe set env::args() == Option(None). I simply wanted to tell if I did or didn't include arguments when executing the file.

The syntax is None, not Option(None). Usually Rust figures out the Sartre question by itself from context, e.g. env::args().nth(5) == None doesn't need any type annotations. In case of Option, you still can specify the full type without type ascription, with the turbofish: None::<String>

4 Likes