Skip to content

Commit 252a041

Browse files
committed
---
yaml --- r: 220700 b: refs/heads/master c: f78333e h: refs/heads/master v: v3
1 parent 8e654f4 commit 252a041

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ea79264ee422362428e5bd943a07f42ca885580c
2+
refs/heads/master: f78333e052d0aee0387695de9e115f34802fd928
33
refs/heads/snap-stage3: d4432b37378ec55450e06799f5344b4b0f4b94e0
44
refs/heads/try: b53c0f93eedcdedd4fd89bccc5a3a09d1c5cd23e
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/librustc_typeck/diagnostics.rs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,38 +2112,63 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust
21122112
"##,
21132113

21142114
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:
21192117
21202118
```
21212119
enum Foo<T> {
21222120
Bar
21232121
}
21242122
```
21252123
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:
21282126
21292127
```
21302128
enum Foo {
21312129
Bar
21322130
}
21332131
```
21342132
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:
21362135
21372136
```
21382137
enum Foo<T> {
21392138
Bar(T)
21402139
}
21412140
```
21422141
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:
21452170
2146-
http://doc.rust-lang.org/reference.html#type-parameters-1
2171+
https://doc.rust-lang.org/std/marker/struct.PhantomData.html
21472172
"##
21482173

21492174
}

0 commit comments

Comments
 (0)