Conversation
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
40da73d to
c12f1b7
Compare
| ```rust | ||
| let init_x: &own<'_> MyStruct = uninit_x; | ||
| x <- init_x; // Mark x as initialised. | ||
| // Now x is initialised | ||
| dbg!(x.id); // OK | ||
| ``` |
There was a problem hiding this comment.
There is no x in this example. And the "marking" of being initialized only works when the &own reference points to that local variable, no?
There was a problem hiding this comment.
Oops. I will fix that.
| and the corresponding `&own` as `&'a uninit MyStruct` and `&'b own<'c> MyStruct`. | ||
| When coercion happens on `uninit_x`, the relationship `'a == 'c` is established. | ||
| Later, when `<-` is used, the lifetime for which the `x` remains uninitialised | ||
| is matched against the so-called origin lifetime on the `&own` and the statement |
There was a problem hiding this comment.
| is matched against the so-called origin lifetime on the `&own` and the statement | |
| is matched against the so-called origin lifetime `'c` on the `&'b own<'c>` and the statement |
| is only accepted when the two lifetime matches. This is true in this case | ||
| because the origin lifetime `'c` indeed matches the lifetime `'a` on `uninit_x`. |
There was a problem hiding this comment.
I don't think this works for this locals, since they do not have a lifetime. Consider:
let x: Struct;
let y: Struct;
let r: &uninit Struct = &uninit x;
r.a = 42;
r.b = 24;
let r: &own Struct = r; // `r` is fully initialized
y <- r; // oops used the wrong local variable with the `&own`
There is no lifetime that can differentiate x from y.
There was a problem hiding this comment.
Yup, this needs compiler magic to produce a generativity-style unique invariant lifetime for x and y.
There was a problem hiding this comment.
I realised that this section is very badly written. Let me sort something out and update it later.
In general, one needs a more detailed spelling of the borrow checking rules for this to work admittedly.
Let's put a summary of the out-pointer/uninit-pointer in the wiki.
cc @cramertj, please feel free to critic and review!