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 updocument and justify temporary lifetime rules in the documentation #12032
Comments
This comment has been minimized.
This comment has been minimized.
|
1.0 blocker, P-low. |
pnkfelix
added
P-low
and removed
I-nominated
labels
Feb 6, 2014
pnkfelix
added this to the 1.0 milestone
Feb 6, 2014
This comment has been minimized.
This comment has been minimized.
|
Nominating for removal from milestone. We'll live if this isn't documented. |
brson
added
the
I-nominated
label
Jun 11, 2014
This comment has been minimized.
This comment has been minimized.
|
Removing from 1.0 milestone. |
pnkfelix
removed this from the 1.0 milestone
Jun 12, 2014
alexcrichton
removed
the
I-nominated
label
Jun 12, 2014
steveklabnik
added
the
A-docs
label
Feb 10, 2015
This comment has been minimized.
This comment has been minimized.
|
Traige: I'm not sure what these are exactly, maybe we can have a chat about them, @nikomatsakis ? |
This comment has been minimized.
This comment has been minimized.
|
@steveklabnik I would say
My go-to example of a gotcha here: Consider the following hypothetical desugaring of macro_rules! for_bad {
(($pat:pat) in $head:expr { $($body:stmt)* }) => { {
let mut iter = IntoIterator::into_iter($head);
loop {
match Iterator::next(&mut iter) {
Some($pat) => { $($body)* }
None => break,
}
}
} }
}The above is remarkably easy to read, at least for someone versed in Unfortunately, it does not work, and (according to my understanding), it is due to the R-value lifetime rules for temporaries. In particular, consider: let mut iter = IntoIterator::into_iter($head);only live to the end of that statement, not beyond. Thus the So, what's the go-to fix for this? Its this: Bind via Here's that desugaring: macro_rules! for_gud {
(($pat:pat) in $head:expr { $($body:stmt)* }) => { {
match IntoIterator::into_iter($head) {
mut iter => loop {
match Iterator::next(&mut iter) {
Some($pat) => { $($body)* }
None => break,
}
}
}
} }
}And here's a playpen link to save you the trouble of transcribing the above into code if you want to play with it: http://is.gd/NmptIx |
pnkfelix
referenced this issue
Feb 14, 2015
Closed
dropck seems overconservative when dealing with matches at the end of a block #22252
This comment has been minimized.
This comment has been minimized.
|
Any update? I wrote down some rules here: https://internals.rust-lang.org/t/borrow-scopes/1732 |
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix Wouldn't it work to just bind $head with a let? macro_rules! for_ok {
(($pat:pat) in $head:expr { $($body:stmt)* }) => { {
let head = $head;
let mut iter = IntoIterator::into_iter(head);
loop {
match Iterator::next(&mut iter) {
Some($pat) => { $($body)* }
None => break,
}
}
} }
} |
This comment has been minimized.
This comment has been minimized.
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Jul 6, 2015
steveklabnik
referenced this issue
Jul 6, 2015
Closed
Document temporary lifetime rules in the reference #26833
This comment has been minimized.
This comment has been minimized.
|
After doing #26833 , @nikomatsakis and I decided to not actually go through this right now. At some point, we'll be developing a more formal model for Rust, and this information will belong there, but as it is, it feels weird in the reference. |
nikomatsakis commentedFeb 4, 2014
The new syntax-based rules for temporary lifetimes that landed with #3511 have not yet been thoroughly documented outside the source. This should be fixed!