-
Notifications
You must be signed in to change notification settings - Fork 13.3k
syntax: Parse field/method access after type ascription and cast expressions #33380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hmm. This has implications for possible future extensions to the type grammar ( |
But I agree |
To give some practical example, here's a commit converting lrs library to use type ascription: lrs-lang/lib@5dc95b6. |
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() // magical In 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 |
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. |
|
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