File tree 1 file changed +8
-7
lines changed
1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change 80
80
'b: {
81
81
let z: &'b i32;
82
82
'c: {
83
- // Must use 'b here because this reference is
84
- // being passed to that scope.
83
+ // Must use 'b here because the reference to x is
84
+ // being passed to the scope 'b .
85
85
let y: &'b i32 = &'b x;
86
86
z = y;
87
87
}
@@ -208,11 +208,12 @@ violate the *second* rule of references.
208
208
209
209
However this is * not at all* how Rust reasons that this program is bad. Rust
210
210
doesn't understand that ` x ` is a reference to a subpath of ` data ` . It doesn't
211
- understand ` Vec ` at all. What it * does* see is that ` x ` has to live for ` 'b ` to
212
- be printed. The signature of ` Index::index ` subsequently demands that the
213
- reference we take to ` data ` has to survive for ` 'b ` . When we try to call ` push ` ,
214
- it then sees us try to make an ` &'c mut data ` . Rust knows that ` 'c ` is contained
215
- within ` 'b ` , and rejects our program because the ` &'b data ` must still be alive!
211
+ understand ` Vec ` at all. What it * does* see is that ` x ` has to live for ` 'b ` in
212
+ order to be printed. The signature of ` Index::index ` subsequently demands that
213
+ the reference we take to ` data ` has to survive for ` 'b ` . When we try to call
214
+ ` push ` , it then sees us try to make an ` &'c mut data ` . Rust knows that ` 'c ` is
215
+ contained within ` 'b ` , and rejects our program because the ` &'b data ` must still
216
+ be alive!
216
217
217
218
Here we see that the lifetime system is much more coarse than the reference
218
219
semantics we're actually interested in preserving. For the most part, * that's
You can’t perform that action at this time.
0 commit comments