]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0392.md
Auto merge of #66396 - smmalis37:pythontest, r=alexcrichton
[rust.git] / src / librustc_error_codes / error_codes / E0392.md
1 This error indicates that a type or lifetime parameter has been declared
2 but not actually used. Here is an example that demonstrates the error:
3
4 ```compile_fail,E0392
5 enum Foo<T> {
6     Bar,
7 }
8 ```
9
10 If the type parameter was included by mistake, this error can be fixed
11 by simply removing the type parameter, as shown below:
12
13 ```
14 enum Foo {
15     Bar,
16 }
17 ```
18
19 Alternatively, if the type parameter was intentionally inserted, it must be
20 used. A simple fix is shown below:
21
22 ```
23 enum Foo<T> {
24     Bar(T),
25 }
26 ```
27
28 This error may also commonly be found when working with unsafe code. For
29 example, when using raw pointers one may wish to specify the lifetime for
30 which the pointed-at data is valid. An initial attempt (below) causes this
31 error:
32
33 ```compile_fail,E0392
34 struct Foo<'a, T> {
35     x: *const T,
36 }
37 ```
38
39 We want to express the constraint that Foo should not outlive `'a`, because
40 the data pointed to by `T` is only valid for that lifetime. The problem is
41 that there are no actual uses of `'a`. It's possible to work around this
42 by adding a PhantomData type to the struct, using it to tell the compiler
43 to act as if the struct contained a borrowed reference `&'a T`:
44
45 ```
46 use std::marker::PhantomData;
47
48 struct Foo<'a, T: 'a> {
49     x: *const T,
50     phantom: PhantomData<&'a T>
51 }
52 ```
53
54 [PhantomData] can also be used to express information about unused type
55 parameters.
56
57 [PhantomData]: https://doc.rust-lang.org/std/marker/struct.PhantomData.html