Why not make iterator lending in 2024 edition?

AFAIK editions allow breaking changes.

Why don't we also add GAT support to the Iterator making it lending iterator in 2024 edition? This would resolve quite a lot of limitations that current iterator has. I know GATs were not released when Iterator was added but this can be fixed now.

If you actually want to propose that, that sounds more like something you would post on

@SebastianJL, this is not a proposal, more like a question. I know that people regularry talk about lending iterators but I couldn't find why it is not considered as a change for the edition.

Ok, I actually found "recent" discussion on the internals forum. thanks

1 Like

There is no lending iterator at all in libstd, so it's an untested idea. Adding one so quickly, and making it enabled by default would be rushing a potentially problematic or half-baked feature.

I think an optional lending iterator needs to be in libstd for a while and get significant usage, before it can be considered to become supported by default.

4 Likes

Well, remember that you can't .collect() a lending iterator, in general. So there's lots of existing Iterator code that can't be migrated.

That means it can't just be changed directly, but there needs to be some way of writing a trait alias -- which also aren't stable -- that limits the the lending iterator to not actually use the lending, but I don't think we even have syntax for it. Notably, Item: 'static will not work, since iterators can have non-'static things as items.

3 Likes

Also, last time I checked writing an implementation or filter for lending iterators required Polonius, which is hardly available even on nightly.