Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upsyntax: Parse field/method access after type ascription and cast expressions #33380
Conversation
rust-highfive
assigned
nikomatsakis
May 3, 2016
This comment has been minimized.
This comment has been minimized.
|
Hmm. This has implications for possible future extensions to the type grammar ( |
nikomatsakis
added
I-nominated
T-lang
labels
May 3, 2016
This comment has been minimized.
This comment has been minimized.
|
But I agree |
This comment has been minimized.
This comment has been minimized.
|
To give some practical example, here's a commit converting lrs library to use type ascription: lrs-lang/lib@5dc95b6. |
This comment has been minimized.
This comment has been minimized.
|
We discussed this in the recent @rust-lang/lang meeting. We all agreed that the motivation here is pretty reasonable. In particular, this change enables the use of vec.iter()
.map()
.collect(): Vec<_>
.something()which is a pretty clear improvement on the version with (vec.iter()
.map()
.collect(): Vec<_>)
.something()@aturon has also harbored secret dreams of removing the need for "special purpose" converter methods. The commit you cited for example has a number of lines that convert calls to (self.as_ref():&[u8]).to_rmo_with(pool)
(self.as_ref(): &[u8]).to_rmo_with(pool) // current rustfmt output
self.as_ref():&[u8].to_rmo_with(pool)
self.as_ref::<[u8]>().to_rmo_with(pool)
self.as_ref<[u8]>().to_rmo_with(pool) // what we wanted, but can't get
self.as_bytes().to_rmo_with(pool)Opinions were somewhat varied, but basically we didn't feel like any of the first three examples (using ascription) were really improvements over As another example, here are some calls with (self.into():PathBuf).do_something()
self.into():PathBuf.do_something()
self.into::<PathBuf>().do_something()
self.into<PathBuf>().do_something() // what we wanted, but can't get yet
self.into_path_buf().do_something()
self.into(PathBuf).do_something() // magicalIn general, we were very concerned that this syntax produces some things that are just plain conusing and hard to parse (for a human, that is). Example: self.into():PathBuf.do_something()On the other hand, not having this syntax really devalues type ascription, since it makes usage in method chains unergonomic. In the end, we decided that we would rather not accept this PR. If you're really enthusiastically in favor of this syntax, we would of course consider an RFC, which would then get a broader set of feedback than this PR. However, if we don't accept this PR, it does raise some questions as to whether type ascription carries its weight, given that using it with |
nikomatsakis
closed this
May 6, 2016
This comment has been minimized.
This comment has been minimized.
I do consider this a noticeable improvement, however this is a simple backward compatible change and it can be applied at any moment, so I'll just wait for the decision about type ascription in general. |
petrochenkov
referenced this pull request
May 6, 2016
Open
Type ascription (tracking issue for RFC 803) #23416
This comment has been minimized.
This comment has been minimized.
kriomant
commented
May 10, 2016
|
|
petrochenkov commentedMay 3, 2016
Addresses #23416 (comment) / rust-lang/rfcs#1539 (comment)
This patch allows type ascription (and cast expressions) to be followed by field/method access syntax.
Therefore it allows type ascription to be used in method chains like
and also makes unsuffixed integer literals with type ascription almost as convenient as literal suffixes
r? @nikomatsakis