@@ -2112,38 +2112,63 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust
2112
2112
"## ,
2113
2113
2114
2114
E0392 : r##"
2115
- This error indicates that a type parameter has been declared but not actually
2116
- used.
2117
-
2118
- Here is an example that demonstrates the error:
2115
+ This error indicates that a type or lifetime parameter has been declared
2116
+ but not actually used. Here is an example that demonstrates the error:
2119
2117
2120
2118
```
2121
2119
enum Foo<T> {
2122
2120
Bar
2123
2121
}
2124
2122
```
2125
2123
2126
- The first way to fix this error is by removing the type parameter, as
2127
- shown below:
2124
+ If the type parameter was included by mistake, this error can be fixed
2125
+ by simply removing the type parameter, as shown below:
2128
2126
2129
2127
```
2130
2128
enum Foo {
2131
2129
Bar
2132
2130
}
2133
2131
```
2134
2132
2135
- The second method is to actually make use of the type parameter:
2133
+ Alternatively, if the type parameter was intentionally inserted, it must be
2134
+ used. A simple fix is shown below:
2136
2135
2137
2136
```
2138
2137
enum Foo<T> {
2139
2138
Bar(T)
2140
2139
}
2141
2140
```
2142
2141
2143
- See the 'Type Parameters' section of the reference for more details
2144
- on this topic:
2142
+ This error may also commonly be found when working with unsafe code. For
2143
+ example, when using raw pointers one may wish to specify the lifetime for
2144
+ which the pointed-at data is valid. An initial attempt (below) causes this
2145
+ error:
2146
+
2147
+ ```
2148
+ struct Foo<'a, T> {
2149
+ x: *const T
2150
+ }
2151
+ ```
2152
+
2153
+ We want to express the constraint that Foo should not outlive `'a`, because
2154
+ the data pointed to by `T` is only valid for that lifetime. The problem is
2155
+ that there are no actual uses of `'a`. It's possible to work around this
2156
+ by adding a PhantomData type to the struct, using it to tell the compiler
2157
+ to act as if the struct contained a borrowed reference `&'a T`:
2158
+
2159
+ ```
2160
+ use std::marker::PhantomData;
2161
+
2162
+ struct Foo<'a, T: 'a> {
2163
+ x: *const T,
2164
+ phantom: PhantomData<&'a T>
2165
+ }
2166
+ ```
2167
+
2168
+ PhantomData can also be used to express information about unused type parameters.
2169
+ You can read more about it in the API documentation:
2145
2170
2146
- http ://doc.rust-lang.org/reference. html#type-parameters-1
2171
+ https ://doc.rust-lang.org/std/marker/struct.PhantomData. html
2147
2172
"##
2148
2173
2149
2174
}
0 commit comments