Consider side effects when rewriting iterator behaviors#14490
Consider side effects when rewriting iterator behaviors#14490Jarcho merged 3 commits intorust-lang:masterfrom
Conversation
Jarcho
left a comment
There was a problem hiding this comment.
I don't see why this needs to be limited to checking only closure captures. Any iterator that contains a mutable reference has the same issue.
I think any iterator type containing one of the following would need to not lint:
- A mutable reference/pointer
- A reference/pointer to a non-
Freezetype - A
PhantomDatatype containing any of the previous.
92e35bf to
4a54775
Compare
|
Updated. Now these will also be covered. |
|
This CI failure does not seem to be my problem. Any ideas? |
I've restarted it to see if it's intermittent (we'll have to fix it anyway) or not. For reference, here is the failing version. Edit: this does not look like it is intermittent. |
|
Thanks to #14514, the CI is working now. |
|
r? clippy |
|
samueltardieu is on vacation. Please choose another assignee. |
Jarcho
left a comment
There was a problem hiding this comment.
Looks like I didn't actually post a review last time I looked at this. Sorry about the wait.
|
r? Jarcho sending it back, then 😄 |
|
For the util name something like |
|
I pushed a refactored version. The |
|
You'll need to keep track of what types have been seen as you recurse. Right now walking a type which recurses via struct Foo<T> {
inner: T,
marker: core::marker::PhantomData<Self>,
}
impl<T: Iterator> Iterator for Foo<T> {
type Item = T::Item;
fn next(&mut self) -> Option<Self::Item> {
self.inner.next()
}
}
fn main() {
Foo {
inner: [].iter(),
marker: core::marker::PhantomData,
}.collect::<Vec<&i32>>().len();
} |
a58ffda to
5ab23fa
Compare
Jarcho
left a comment
There was a problem hiding this comment.
Just one last extension to handle any known projections and this should be good.
6fd1995 to
a6c8868
Compare
Closes #9191
Closes #14444
Closes #8055
Adds a new helper to partly check for side effects by recursively checking if the iterator type contains closures with mutable captures.
changelog: [
double_ended_iterator_last] fix FP when iter has side effectschangelog: [
needless_collect] fix lint not consider side effects