-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Infinite loop when compiling nested macros #11692
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
Comments
That sounds pretty bad! Nominating. |
Accepted for 1.0, P-high |
The code path seems to be: The But how to fix it? |
This led to infinite recursion when compiling a macro which inside used an undefined macro. Instead some dummy expression is returned for the result of expansion (rather than the macro itself). Closes rust-lang#11692
You'd probably want to move the |
Moving In the same vein, changing Is there any other way to do it? |
I think the best thing is to probably restructure the matches to avoid the double borrow. I'm not sure how painful that'll be though. Changing the signature of |
I couldn't find a way to untangle the double borrow. Here's what I found so far for whoever may pick up this issue in the future. The issue reported in this ticket is twofold. One is that unless it is one of the hardcoded macros defined in The reason that a nested legit macro deemed as undefined is that the inner macro gets expanded in the expander function of outer macro. But the expander function has no syntax context information right now, in that context there are macros being injected from The #11803 seems to be remotely related. |
Closes #11692. Instead of returning the original expression, a dummy expression (with identical span) is returned. This prevents infinite loops of failed expansions as well as odd double error messages in certain situations. This is a slightly better fix than #12197, because it does not produce a double error and also fixes a few other cases where an infinite loop could happen. This does not fix the other issue in #11692 (non-builtin macros not being recognised when expanded inside macros), which I think should be moved into a separate issue.
Do we plan to support nested macro invocations? #9323 is also relevant. |
Nested macro invocations should be (?) supported. Things are expanded outside-in. |
…, r=xFrednet [`iter_without_into_iter`]: fix papercuts in suggestion and restrict linting to exported types See rust-lang#11692 for more context. tldr: the lint `iter_without_into_iter` has suggestions that don't compile, which imo isn't that problematic because it does have the appropriate `Applicability` that tells external tools that it shouldn't be auto-applied. However there were some obvious "errors" in the suggestion that really should've been included in my initial PR adding the lint, which is fixed by this PR: - `IntoIterator::into_iter` needs a `self` argument. - `IntoIterator::Iter` associated type doesn't exist. This should've just been `Item`. This still doesn't make it machine applicable, and the remaining things are imho quite non-trivial to implement, as I've explained in rust-lang/rust-clippy#11692 (comment). I personally think it's fine to leave it there and let the user change the remaining errors when copy-pasting the suggestion (e.g. errors caused by lifetimes that were permitted in fn return-position but are not in associated types). This is how many of our other lint suggestions already work. Also, we now restrict linting to only exported types. This required moving basically all of the tests around since they were previously in the `main` function. Same for `into_iter_without_iter`. The git diff is a bit useless here... changelog: [`iter_without_into_iter`]: fix papercuts in suggestion and restrict linting to exported types (cc `@lopopolo,` figured I should mention you since you created the issue)
Apologies if this has been reported before. A search didn't turn up anything but you know how GH's search is.
Tested with today's x86_64 lucid nightly from https://launchpad.net/~hansjorg/+archive/rust
The text was updated successfully, but these errors were encountered: