|
1 |
| -- Feature Name: dst-coercions |
| 1 | +- Feature Name: dst_coercions |
2 | 2 | - Start Date: 2015-03-16
|
3 | 3 | - RFC PR: (leave this empty)
|
4 | 4 | - Rust Issue: (leave this empty)
|
@@ -51,7 +51,7 @@ An example implementation:
|
51 | 51 |
|
52 | 52 | ```
|
53 | 53 | impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<Rc<U>> for Rc<T> {}
|
54 |
| -impl<T: ?Sized+CoerceUnsized<U>, U: ?Sized> NonZero<U> for NonZero<T> {} |
| 54 | +impl<T: ?Sized+CoerceUnsized<U>, U: ?Sized> CoerceUnsized<NonZero<U>> for NonZero<T> {} |
55 | 55 |
|
56 | 56 | // For reference, the definitions of Rc and NonZero:
|
57 | 57 | pub struct Rc<T: ?Sized> {
|
@@ -107,15 +107,18 @@ not a general `Coerce` trait.
|
107 | 107 | * If the impl is for a built-in pointer type, we check nothing, otherwise...
|
108 | 108 | * The compiler checks that the `Self` type is a struct or tuple struct and that
|
109 | 109 | the `Target` type is a simple substitution of type parameters from the `Self`
|
110 |
| -type (one day, with HKT, this could be a regular part of type checking, for now |
| 110 | +type (i.e., That `Self` is `Foo<Ts>`, `Target` is `Foo<Us>` and that there exist |
| 111 | +`Vs` and `Xs` (where `Xs` are all type parameters) such that `Target = [Vs/Xs]Self`. |
| 112 | +One day, with HKT, this could be a regular part of type checking, for now |
111 | 113 | it must be an ad hoc check). We might enforce that this substitution is of the
|
112 | 114 | form `X/Y` where `X` and `Y` are both formal type parameters of the
|
113 | 115 | implementation (I don't think this is necessary, but it makes checking coercions
|
114 | 116 | easier and is satisfied for all smart pointers).
|
115 | 117 | * The compiler checks each field in the `Self` type against the corresponding field
|
116 | 118 | in the `Target` type. Assuming `Fs` is the type of a field in `Self` and `Ft` is
|
117 | 119 | the type of the corresponding field in `Target`, then either `Ft <: Fs` or
|
118 |
| -`Fs: CoerceUnsized<Ft>` (note that this includes built-in coercions). |
| 120 | +`Fs: CoerceUnsized<Ft>` (note that this includes some built-in coercions, coercions |
| 121 | +unrelated to unsizing are excluded, these could probably be added later, if needed). |
119 | 122 | * There must be only one field that is coerced.
|
120 | 123 | * We record for each impl, the index of the field in the `Self` type which is
|
121 | 124 | coerced.
|
@@ -156,8 +159,7 @@ all now, since all checking is postponed until trans or relies on traits and imp
|
156 | 159 |
|
157 | 160 | # Drawbacks
|
158 | 161 |
|
159 |
| -Not as flexible as the previous proposal. Can't handle pointer-like types like |
160 |
| -`Option<Box<T>>`. |
| 162 | +Not as flexible as the previous proposal. |
161 | 163 |
|
162 | 164 | # Alternatives
|
163 | 165 |
|
|
0 commit comments