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 upIn macros, `$($x:expr),*` fragments can be used to bypass future-proofing restrictions #25658
Comments
This comment has been minimized.
This comment has been minimized.
|
cc @bluss |
This comment has been minimized.
This comment has been minimized.
|
Note that macro_rules! foo {
( $x:expr ... ) => { 1 }
}
fn main() { }is (correctly) prohibited. |
This comment has been minimized.
This comment has been minimized.
|
It's not just the type |
This comment has been minimized.
This comment has been minimized.
|
Nooooooo! You're going to break my macro article again, aren't you? :( (Note: I realise the following is not a good reason to not fix this problem.) The problem for me, personally, is that the following doesn't work: macro_rules! foo {
( $($x:expr),* , ... ) => { 1 }
}
fn main() {
// error: local ambiguity: multiple parsing options: built-in NTs expr ('x') or 1 other options.
let _ = foo!(1, 2, 3, ...);
// ^~~
}It would be nice if MBE preferred literal matches to captures. |
This comment has been minimized.
This comment has been minimized.
|
@DanielKeep Shouldn't that be macro_rules! foo {
(...) => {{
()
}};
($e:expr, $($tok:tt)+) => {{
($e, foo!($($tok)+))
}}
}
fn main() {
let tpl = foo!(1,2,3,4,...);
println!("{:?}", tpl);
} |
steveklabnik
added
the
A-macros
label
May 21, 2015
This comment has been minimized.
This comment has been minimized.
|
triage: I-nominated |
rust-highfive
added
the
I-nominated
label
May 26, 2015
This comment has been minimized.
This comment has been minimized.
|
cc @pnkfelix |
nikomatsakis
added
the
T-lang
label
Jun 2, 2015
This comment has been minimized.
This comment has been minimized.
|
So my feeling is that we should probably fix this, but it'd be good to evaluate the impact. It might be a good place to use a more elongated "breaking change procedure", or at least actively reach out to help people rewrite. |
This comment has been minimized.
This comment has been minimized.
|
Is this a bug where we need to consider "FOLLOW"? I thought I saw a PR/RFC that added detailed FOLLOW checking but I could be wrong. |
This comment has been minimized.
This comment has been minimized.
|
Would it be a middle ground to always warn on this, and then "just let it break" if expression syntax ever changes so that it does -- the macro would suddenly match differently. @DanielKeep and I found out a parsing strategy with |
This comment has been minimized.
This comment has been minimized.
|
triage: P-high Assigning high priority as, if we are going to fix this, we need to do it soon. If we're just going to warn, urgency is somewhat lower. I'm not yet sure of best overall strategy here. A crater report might be helpful in making the determination. |
rust-highfive
added
P-high
and removed
I-nominated
labels
Jun 3, 2015
pnkfelix
self-assigned this
Aug 6, 2015
This comment has been minimized.
This comment has been minimized.
|
I just found this gem, which is probably related to this issue: macro_rules! e {
($($e:expr)*) => ($($e)*);
}
fn main() {
e!(() "");
e!("" 4);
}The first invocation is accepted, the second leads to a type error:
(this doesn't depend on the return type of the function, it gives the same error when it returns something else than |
This comment has been minimized.
This comment has been minimized.
|
@jonas-schievink Hmm, I don't think that is related to this ticket... it is a strange inconsistency though. (I also think that all of those update: spawned off into #29799 |
pnkfelix
referenced this issue
Nov 12, 2015
Closed
in stmt context, seq!(() "") accepted while seq!("" 4) rejected #29799
This comment has been minimized.
This comment has been minimized.
|
Fixing the bug here without adding a warning seems simple: just let the checking for delimited-sequences fall, on success, into the code for non-delimited ones. (Wish I had looked at this for a day back in May...) I'm going to double-check that this passes (And in parallel with the crater run, I'll see how hard it would be to instead emit a (hard) warning... it may require more invasive surgery on the code in question.) |
This comment has been minimized.
This comment has been minimized.
|
I did a crater run for my simple (error-generating, not a warning cycle) fix for this.
While that was running, I hacked together a warning-cycle version of the change. (As predicted, it is more invasive, but also lays out further changes we can make to simplify this code if we go down the route I'm suggesting.) Once that builds successfully, I'll put it through a crater run as well, since I am not thrilled with 17 root regressions. |
bluss
referenced this issue
Nov 16, 2015
Merged
Use a more well-defined way to accept trailing comma #2
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix Ha! I'm responsible for four of those 17. Oh... this breaks trailing commas. That's really going to suck. |
This comment has been minimized.
This comment has been minimized.
|
Some of the errors from my crater run above seem like they may be due to our limited approach to having sequences followed by other sequences, which the code in some ways acts like has always been disallowed, but clearly we let it through for delimited sequences. I'm having difficulty interpreting the intent of RFC 550 here; I'll report more later after I've finished writing up an analysis of the results. |
This comment has been minimized.
This comment has been minimized.
|
@DanielKeep my initial guess is that my naive approach, while accepted by our internal |
This comment has been minimized.
This comment has been minimized.
|
I looked through all of the crater reported root regressions; the analysis writeup is here: https://gist.github.com/pnkfelix/be4b76cd8891230eb065 Of the 17 root regressions
For the "fundamental consequences", I mean the cases:
For "seq rep followed by seq rep", the code as written disallows But there's no fundamental reason that we cannot allow sequences followed by sequences. The reason why I think the current code tried to disallow them is to allow for a simple computation to find the "first" token that immediately follows any given sequence. (This is supported by comments in the code like "This doesn't actually compute the FIRST of the rest of the matcher yet, it only considers single tokens and simple NTs" (emphasis added).) |
This comment has been minimized.
This comment has been minimized.
|
My feeling here is that we should not rush to issue a breaking change IF we think there are simple ways to make the code more intelligent that would mitigate the effect of that change. In other words, if being smart about follow sets means we can both fix this bug AND support more macros, seems like we should do that. I'm not entirely clear if that is the case from your write-up (perhaps because I need to read it more carefully :) |
This comment has been minimized.
This comment has been minimized.
|
OK, so, this "trailing comma" pattern jumps out: |
This comment has been minimized.
This comment has been minimized.
@nikomatsakis yes I think that is right. I'm working on a revised version of the code that does a more precise computation of FIRST for the suffix after the cursor (and also tracks LAST for the token sequence prefix before the cursor, since you can have things like |
This comment has been minimized.
This comment has been minimized.
|
results of new crater run with a smarter (still in development) changeset: https://gist.github.com/pnkfelix/b351caa523d45f9aa86b I interpret this as a signal that I need to add
(Some of the regressing crates fall into more than one of the buckets above...) |
This comment has been minimized.
This comment has been minimized.
|
I don't understand disallowing |
This comment has been minimized.
This comment has been minimized.
|
Also, as a matter of policy, could/should crate authors be notified (assuming an email was provided) when their crate is caught regressing in a crater run related to an accepted breaking change? |
This comment has been minimized.
This comment has been minimized.
Almost certainly an oversight. Good point! |
pnkfelix
referenced this issue
Nov 27, 2015
Merged
Amend RFC 550 with (expanded) abstract specification rather than algorithm #1384
This comment has been minimized.
This comment has been minimized.
|
On Wed, Nov 18, 2015 at 08:53:16AM -0800, Felix S Klock II wrote:
I still feel uncomfortable with this. I would rather than a nt for Perhaps though there is a compromise:
|
This comment has been minimized.
This comment has been minimized.
yeah, I have come around to seeing this as a better solution (see e.g. rust-lang/rfcs#1384 (comment) ) Just need to think of a good name for the specifier. :) |
This comment has been minimized.
This comment has been minimized.
|
now that amendment rust-lang/rfcs#1384 has been accepted, this issue should be fixed once the implementation has landed (i.e. #30450 is resolved). |
durka
referenced this issue
Jan 3, 2016
Open
Let expressions be followed by blocks in macro arguments #30679
This comment has been minimized.
This comment has been minimized.
|
I should point out that crater is still massively deficient as it still does not test Windows targets at all, and did not notice that
|
This comment has been minimized.
This comment has been minimized.
|
Cc @brson re above crater note (I strongly doubt we would revert the RFC amendment or associated PR. you might find support for adding |
This comment has been minimized.
This comment has been minimized.
|
@retep998 Thanks for bringing this up. I assure you the deficiencies of crater are well-known, and it'd be really great if we could improve it -- though even if we got 100% coverage for crates.io, obviously it still wouldn't be 100% coverage of all the Rust code out there. In any case though, this is part of why we try our best to do warning cycles for bug fixes that are likely to have major impact, so that we can find out about other problems before changes become permanent (and also of course to give people time to transition). As @pnkfelix said, I don't think it makes sense to rollback this bug fix completely or anything like that. It might alleviate some short term pain but it'd be guaranteed to cause more breakage in the long-term, since basically every change to Rust's grammar would be a potential breaking change to some macro. However, also as @pnkfelix said, adding |
pnkfelix
referenced this issue
Jan 14, 2016
Closed
macro future-proofing regression: `$a:ty [ b ]` is now rejected #30923
This comment has been minimized.
This comment has been minimized.
|
This issue (as described in the description) is fixed by #30694 |
nikomatsakis commentedMay 20, 2015
This should not be accepted, but it is:
cc @pnkfelix @cmr