Skip to content

Commit 8398d82

Browse files
committed
---
yaml --- r: 220870 b: refs/heads/auto c: f78333e h: refs/heads/master v: v3
1 parent 72263b0 commit 8398d82

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
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: ea79264ee422362428e5bd943a07f42ca885580c
11+
refs/heads/auto: f78333e052d0aee0387695de9e115f34802fd928
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/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)