News for hackers. Stuff that matters.
Re:Rust stabilizes generic associated types by davidatbu on Tuesday September 13, 2022 @05:22PM (#32830346)
So I have a question about GATs: since there was a lot of concern about the complexity cost they add, was it not possible to just define traits with generic params (instead of generic associated types, GATs) to achieve everything GATs could? To demonstrate, doesn't something like this work for lending iterators?

    trait LendingIterator<'a, T> {
        fn next(&'a mut self) -> Option<&'a T>;
    }

    impl<'a, T> LendingIterator<'a, T> for Whatever {
        fn next(&'a mut self) -> Option<&'a T> {
            todo!()
        }
    }
And of course, you'd modify the for loop syntax to desugar appropriately if the the iterator implements LendingIterator.
Re:Rust stabilizes generic associated types by retrocat on Wednesday September 14, 2022 @02:04AM (#32833773)
As far as I can tell, this can't actually work, because the return type of `fn next(&'a mut self)` should actually live for some lifetime `'b` that is shorter than `'a`, instead of at least as long as `'a`; mostly because `next` borrows `self` mutably.
Re:Rust stabilizes generic associated types by xavxav on Tuesday September 13, 2022 @05:44PM (#32830537)
An immediate issue which could be addressed with further complexity is that for loop desugaring is done very early in Rust's compilation pipeline, way before typing is actually performed. This would also be weird in the case that you have a for loop over some generic iterator, the monomorphized code could vary quite a bit based on what trait your type implements.