-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Description
This example program should not type check:
struct S<'self> {
pointer: &'self mut int
}
fn copy_borrowed_ptr<'a, 'b>(p: &'a mut S<'b>) -> S<'b> {
S { pointer: &mut *p.pointer }
}
fn main() {
let mut x = 1;
let mut y = S { pointer: &mut x };
let z = copy_borrowed_ptr(&mut y);
*y.pointer += 1;
*z.pointer += 1;
}
The problem is that the rules which limit reborrowing of mut data to unique paths do not consider the lifetime of those unique paths.
The legal signatures for copy_borrowed_ptr
would be either:
fn copy_borrowed_ptr<'a>(&'a mut S<'a>) -> S<'a>
; orfn copy_borrowed_ptr<'a, 'b>(&'a mut S<'b>) -> S<'a>
schneiderfelipe
Metadata
Metadata
Assignees
Labels
A-type-systemArea: Type systemArea: Type system
Type
Projects
Relationships
Development
Select code repository
Activity
metajack commentedon Aug 19, 2013
nominating production ready
nikomatsakis commentedon Sep 9, 2013
This is actually deserving of backwards compatible, because the fix will likely cause some APIs to be changed.
bluss commentedon Sep 10, 2013
I think the mutable
extra::dlist
iterator is sound, but I have a feeling it is enabled by this hole.catamorphism commentedon Sep 12, 2013
Accepted backwards-compatible
&mut &mut
#1051917 remaining items