You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/Project-Goals-2025-October-Update.md
+26-52Lines changed: 26 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,8 +165,7 @@ Design a language feature to solve Field Projections <a href='https://github.com
165
165
<h3>Field Representing Types</h3>
166
166
<p>Since projections now decompose, we have no need from a design perspective for multi-level FRTs. So <code>field_of!(Foo, bar.baz)</code> is no longer required to work. Thus we have decided to restrict FRTs to only a single field and get rid of the path. This simplifies the implementation in the compiler and also avoids certain difficult questions such as the locality of FRTs (if we had a path, we would have to walk the path and it is local, if all structs included in the path are local). Now with only a single field, the FRT is local if the struct is.</p>
167
167
<p>We also discovered that it is a good idea to make FRTs inhabited (they still are ZSTs), since then it allows the following pattern to work:</p>
let my_field = project_free_standing(field_of!(MyStruct, my_field), &my_struct);
172
171
</code></pre>
@@ -188,13 +187,11 @@ let my_field = project_free_standing(field_of!(MyStruct, my_field), &my_stru
188
187
<p>This goes into a similar direction as the reborrowing project goal https://github.com/rust-lang/rust-project-goals/issues/399, however, it needs extra borrow checker support.</p>
<p>This makes it overall a lot more readable (by providing sensible names instead of magic numbers), and maintainable (we can add a new variant without worrying about which IDs are unused). It also avoids the <code>unsafe</code> <code>HasWork</code> trait and the need to write the <code>impl_has_work!</code> macro for each <code>Work</code> field.</p>
<p>In the current proposal the <code>Project::project</code> function is <code>unsafe</code>, because it takes a raw pointer as an argument. This is pretty unusual for an operator trait (it would be the first). <ahref="https://github.com/tmandry">Tyler Mandry</a> thought about a way of making it safe by introducing "partial struct types". This new type is spelled <code>Struct.F</code> where <code>F</code> is an FRT of that struct. It's like <code>Struct</code>, but with the restriction that only the field represented by <code>F</code> can be accessed. So for example <code>&Struct.F</code> would point to <code>Struct</code>, but only allow one to read that single field. This way we could design the <code>Project</code> trait in a safe manner:</p>
351
328
<pre><codeclass="language-rust">// governs conversion of `Self` to `Narrowed<F>` & replaces Projectable
352
329
pub unsafe trait NarrowPointee {
353
-
type Target;
354
-
330
+
type Target;<br>
355
331
type Narrowed<F: Field<Base = Self::Target>>;
356
-
}
357
-
332
+
}<br>
358
333
pub trait Project: NarrowPointee {
359
-
type Output<F: Field<Base = Self::Type>>;
360
-
334
+
type Output<F: Field<Base = Self::Type>>;<br>
0 commit comments