Closed
Description
Updated description
The fact that leading blocks are never expressions needs to be documented in the language reference both in the grammar section and likely elsewhere to make it known
Original description
Can't use operators on unsafe { }
/tmp/test.rs:2:18: 2:19 error: unexpected token: `+`
/tmp/test.rs:2 unsafe { 1 } + 1;
^
You need parentheses:
(unsafe { 1 }) + 1;
but it doesn't seem like that should be necessary.
Activity
alexcrichton commentedon Mar 19, 2014
This is caused by the parser parsing
unsafe { ... }
as a statement, and then parsing+1
as an expression (which is not a valid expression). This isn't just contained to unsafe blocks, but any block-based expression@nikomatsakis, @brson, this relates to the discussion at the work week. I think we resolved that this is working as intended, but did we intend to write up documentation for this?
sfackler commentedon Mar 19, 2014
It's also an issue with macros. I think there's already an issue for that case.
Thiez commentedon Mar 19, 2014
We do allow
It seems like the reverse should work also.
huonw commentedon Mar 19, 2014
#5941 for macros.
nikomatsakis commentedon Mar 24, 2014
@alexcrichton this is working as intended, yes. I had no particular plan to write docs but of course that's always a nice thing to do. Not sure where that'd go, I'd assume it's just part of the language grammar, which we ought to document but as part of general work on the reference manual I guess. @Thiez no, the reverse does not work, it introduces parser ambiguities, use a parenthesis.
[-]Can't use operators on unsafe { }[/-][+]Document that leading blocks are never expressions[/+]alexcrichton commentedon Mar 24, 2014
Updated title/description to reflect what needs to be done.
steveklabnik commentedon Dec 8, 2014
I'm not sure how or where to appropriately document this, it seems like just straight-up invalid code.
steveklabnik commentedon Feb 13, 2015
Traige: still not clear exactly with what to do for an "I expected this to work but it doesn't," so I'm giving this a close. It's not scalable to put every kind of quesiton like this in the docs, and I don't see people asking about this very often. If it becomes a problem, we can try to figure something out eventually.
feat: Generate static method using Self::assoc() syntax
Auto merge of rust-lang#13041 - DorianListens:dscheidt/gen-fn-self-as…
1 remaining item