feat: make izip! temporary friendly#1021
Conversation
cffa620 to
f065b55
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1021 +/- ##
========================================
Coverage 94.38% 94.39%
========================================
Files 48 50 +2
Lines 6665 6883 +218
========================================
+ Hits 6291 6497 +206
- Misses 374 386 +12 ☔ View full report in Codecov by Sentry. |
|
If needed I can add the example in the PR comment as a test to avoid future regressions |
|
Hi there, first of all: Huge thanks for a playground-runnable example. Honestly, I did not fully review the patch yet, because I found we have 3 macros:
If @jswrenn is ok with it, I suggest to seize the opportunity and bring them in line instead of only patching Maybe we can split things up into two parts: One macro to repeatedly call an iterator method usable in Rust 2024, and one macro to do tuple flattening. OT: We should somehow test Rust 2024 in our CI. |
|
For now I'll start by adding the non regression test as proposed as I see two thumbs up, if you want a more extensive patch, or would rework it in a later PR to manage the other macros as you said let me know! |
- some izip! calls with temporary values would not compile with the current izip! implementation due to the use of a block to create the temporary iter chain, if a user called izip! with an iterator from a temporary value the compilation would fail - this change adapts the macro to stop making use of the block and calls $crate::__std_iter::Iterator::zip directly to avoid the need for temporary iter bindings, this means the recursion produces a tuple of the form (a, (b, (c, d))) instead of (((a, b), c), d), needing a slight adaptation of the closure arm to invert the way arguments are unpacked, it also adds two arms to recursively build the zipped iterators without the final map adapter as we don't process all iterators at once as before
f065b55 to
5ca995e
Compare
|
hey @phimuemue I know what it's like (to an extent) to manage PRs on open source projects, just was wondering if you had reached a decision regarding the PR ? I'm in no rush on my end to get this working, just felt that it would be better to get this chugging along before we forget too much about it :) |
jswrenn
left a comment
There was a problem hiding this comment.
I'm happy to approve the point fix provided by this PR. :-)
some izip! calls with temporary values would not compile with the current izip! implementation due to the use of a block to create the temporary iter chain, if a user called izip! with an iterator from a temporary value the compilation would fail
this change adapts the macro to stop making use of the block and calls $crate::__std_iter::Iterator::zip directly to avoid the need for temporary iter bindings, this means the recursion produces a tuple of the form (a, (b, (c, d))) instead of (((a, b), c), d), needing a slight adaptation of the closure arm to invert the way arguments are unpacked, it also adds two arms to recursively build the zipped iterators without the final map adapter as we don't process all iterators at once as before
This should also prevent some failure linked to Rust Edition 2024 changes for some temporary lifetime (which actually prompted this patch in the first place) https://doc.rust-lang.org/edition-guide/rust-2024/temporary-tail-expr-scope.html
Example Rust code that this patch fixes:
Failing Cargo.toml
Sample error: