-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Syntax extensions (and macros) that start a line want to be a whole statement #5941
Comments
�@paulstansifer How hard is this to fix? How important is it to fix? One can see similar paren-wrapping work-arounds elsewhere in such cases where disambiguation is necessary (e.g. to distinguish a method call So, would it possibly suffice in this case to improve the parser's error message? |
I think that this is different from that because, in that case, we need parentheses to distinguish between two different legitimate parses, whereas, in this case, there's a legitimate interpretation that's not accessible (and surprises the user who isn't thinking about statements at all). On the other hand, determining whether Summary: I think it's important, but I could be persuaded that using parens is the proper Rustic solution. |
Triage: still an issue; personally I think that parsing it as a statement always is ok if we detected when we've hit a parse error due to this choice (detecting it heuristically or otherwise), i.e. something like: fn main() { stringify!(1).to_owned(); } currently errors out with
but could error with
or something like that. |
I think changing this would be backwards incompatible (although it's not clear that we actually want to change it), e.g. foo!()
(x + 1).bar() currently parses as two statements (Similar things happen with a prefix unary Nominating. |
How important is it that we have macros that can expand to statements? Couldn't such macros instead expand to the expression |
Actually, I think there's some of that there, already; if you look at the default implementation of Ooh, okay, how about this one; a |
I have found use in an RAII macro like macro_rules! guard {
($thing: expr) => { let _guard = Guarder::new($thing); }
} which means {
guard!(foo);
// ... all inside the guard above, due to the scoping of the `let`
} works as you might expect; this was mainly to avoid problems where someone might write |
(It would also kill macros like this.) |
Oh yeah, it doesn't work for |
Team decided that resolving this does not need to block 1.0; that is, if we to stick with our current behavior, that is acceptable for 1.0, though a bit of a wart. Leaving issue open in the hopes that a better solution arises, but not a 1.0 milestone bug P-high.. |
As far as I can tell, there is no ‘nice’ way of fully resolving this, as an expression/statements like
|
This is pretty annoying when trying to use macros to start a chain of operations, as it makes using the macro much uglier. This is an issue in rust-enforce as it makes the start of the chain |
This fixes the most commonly-encountered case of rust-lang#5941.
cc @nick29581, could you migrate this to the RFCs repo? |
This issue has been moved to the RFCs repo: rust-lang/rfcs#364 |
Don't lint if it has always inline attribute Don't trigger the lint `trivially_copy_pass_by_ref` if it has `#[inline(always)]` attribute. Note: I am not particularly familiar with `inline` impacts, so I implemented this the way that if only `#[inline]` attribute is here (without `always`), the lint will still trigger. Also, it will still trigger if it has `#[inline(never)]`. Just tell me if it sounds too much conservative. Fixes: rust-lang#5876 changelog: none
However, if you wrap the macro invocation in parens...
...it works.
The tricky thing about this problem is that, when the parser sees
stringify!
, it doesn't know whether it'll be a statement macro or an expression macro; currently, it commits to the former, which breaks if the invocation has to be an expression.The text was updated successfully, but these errors were encountered: