@@ -288,13 +288,44 @@ pub enum AutoAdjustment<'tcx> {
288
288
AdjustDerefRef ( AutoDerefRef < ' tcx > ) ,
289
289
}
290
290
291
+ /// Represents coercing a pointer to a different kind of pointer - where 'kind'
292
+ /// here means either or both of raw vs borrowed vs unique and fat vs thin.
293
+ /// The simplest cases are where the pointer is not adjusted fat vs thin. Here
294
+ /// the pointer will be dereferenced N times (where a dereference can happen to
295
+ /// to raw or borrowed pointers or any smart pointer which implements Deref,
296
+ /// including Box<_>). The number of dereferences is given by `autoderefs`.
297
+ /// It can then be auto-referenced zero or one times, indicated by `autoref`, to
298
+ /// either a raw or borrowed pointer. In these cases unsize is None.
299
+ ///
300
+ /// A DST coercon involves unsizing the underlying data. We start with a thin
301
+ /// pointer, deref a number of times, unsize the underlying data, then autoref.
302
+ /// The 'unsize' phase may change a fixed length array to a dynamically sized one,
303
+ /// a concrete object to a trait object, or statically sized struct to a dyncamically
304
+ /// sized one.
305
+ /// E.g., &[i32; 4] -> &[i32] is represented by:
306
+ /// AutoDerefRef {
307
+ /// autoderefs: 1, // &[i32; 4] -> [i32; 4]
308
+ /// unsize: Some([i32]), // [i32; 4] -> [i32]
309
+ /// autoref: Some(AutoPtr), // [i32] -> &[i32]
310
+ /// }
311
+ /// Note that for a struct, the 'deep' unsizing of the struct is not recorded.
312
+ /// E.g., `struct Foo<T> { x: T }` we can coerce &Foo<[i32; 4]> to &Foo<[i32]>
313
+ /// The autoderef and -ref are the same as in the above example, but the type
314
+ /// stored in `unsize` is `Foo<[i32]>`, we don't store any further detail about
315
+ /// the underlying conversions from `[i32; 4]` to `[i32]`.
316
+ ///
317
+ /// Box pointers are treated somewhat differently, the last deref is not counted,
318
+ /// nor is the 'ref' to a `Box<_>`. Imagine them more like structs.
319
+ /// E.g., Box<[i32; 4]> -> Box<[i32]> is represented by:
320
+ /// AutoDerefRef {
321
+ /// autoderefs: 0,
322
+ /// unsize: Some(Box<[i32]>),
323
+ /// autoref: None,
324
+ /// }
291
325
#[ derive( Copy , Clone , Debug ) ]
292
326
pub struct AutoDerefRef < ' tcx > {
293
327
// FIXME with more powerful date structures we could have a better design
294
- // here. Some constraints:
295
- // unsize => autoref
296
- // unsize => autodefs == 0
297
-
328
+ // here.
298
329
299
330
/// Apply a number of dereferences, producing an lvalue.
300
331
pub autoderefs : usize ,
0 commit comments