-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Closed
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-type-systemArea: Type systemArea: Type systemP-mediumMedium priorityMedium priority
Description
I can access a &mut int through a & &mut int pointer:
let x = &mut ~3; let y = &x; ***y // evaluates to `3`
But not access a &mut struct field through &self:
struct Ref<'self, T>(&'self mut T);
let mut it = range(0,3);
let r = &Ref(&mut it);
r.size_hint()
// error: cannot borrow an `&mut` in a `&` pointer; try an `&mut` instead
The use case is precisely Ref above, in essence, I want to implement a "by-ref" (by mutable ref) adaptor for iterators. And it works fine for implementing Iterator::next but not for Iterator::size_hint for the reason above.
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-type-systemArea: Type systemArea: Type systemP-mediumMedium priorityMedium priority