-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Precedence of box
is possibly wrong
#21192
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
cc @pnkfelix |
(subtask of #11779 ) ((well, sort of; depends on your definition of what "placement box" covers.)) |
Assigning this to @pnkfelix too. |
It would be great if the language would require explicit () in cases like this, for us mortal programmers who have to read code. See this classic: http://lwn.net/Articles/382024/ |
@pnkfelix yes, this is making me change my mind. Even though my intution is that the precedence of |
still, could |
@pnkfelix I think this doesn't work because the precedence of fn main() {
println!("{}", 3_u32 + 4_u64 as u32);
} (Note also that my intuition is based on some notion that I think the precedence right now is roughly:
|
But, I-needs-decision! |
triage: P-medium |
I agree, just bumped into this. let v = vec![1,2,3];
let x = box v[0];
let y = (box v)[0]; |
triage: P-low Decided to keep this open as the place to discuss precedence of |
@kjpgit I'm not sure I completely agree, although I do think Rust is airing in the side of too many levels now. As a programmer that primarily learned using Racket I'd love to throw parenthesis everywhere, but I really don't want to end up with a weird rule like you sometime need parens unless it's a box that is near other operators. I've always thought that precedence should be a programmer problem solved by education. Personally I've always wanted to see what an editor aware of the grammar of a language could do in terms of alerting programmers to potential issues. A simple fix with an editor would be to show the implicit parens at like 50% opacity. |
Triage: IIRC, we're going back the drawing board again with the box syntax stuff. @pnkfelix ? |
If you're going back to the drawing board. What's wrong with |
cc @rust-lang/wg-grammar : this remains an open question and it would be great to try to attack it. (It may well tie in with whatever syntax we adopt for |
I agree, and think we should adopt the same style for these kinds of keywords in general. If we decide on prefix with custom precedence then it should be: box try await e
// or
box(try(await(e))) Of course Or if it's a macro then: box!(try!(await!(e))) Or finally, the proposed postfix method notation. e.await.try.box I'm personally a fan of the prefix notation for these, since I like field / tuple access and method call to be what |
@pnkfelix Yeah I think postfix box is the way to go and I want to thank whoever had the foresight to reserve |
At this point I personally think that postfix Here is a summary of the various cases that have been raised in this comment thread:
For the most part I think the postfix However, I also am not personally invested in this matter, and I don't think it is a pressing matter for the compiler or language teams in general. so I'm going to unassign myself from this issue. |
Given that box syntax is currently permanently unstable and potentially on a deprecation path, I don't think this issue is too useful. Closing. |
Now that
box
is a keyword, and not the~
operator, I think it's precedence is wrong. It maintains the precedence of a symbolic unary operator but I think keyword unary operators should have lower precedence.In practical terms, this means that I think:
should parse as
and not
Nominating.
The text was updated successfully, but these errors were encountered: