Skip to content

Commit cd1f94a

Browse files
committed
Rollup merge of rust-lang#25328 - nham:E0106_E0107, r=alexcrichton
Adds long diagnostic messages for the following error codes: - E0049 - E0050 - E0066 - E0069 - E0106 - E0107 - E0166 - E0201 - E0322 cc rust-lang#24407
2 parents b833737 + 5c77f0d commit cd1f94a

File tree

2 files changed

+198
-14
lines changed

2 files changed

+198
-14
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,8 +3033,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
30333033
let mut checked = false;
30343034
opt_place.as_ref().map(|place| match place.node {
30353035
ast::ExprPath(None, ref path) => {
3036-
// FIXME(pcwalton): For now we hardcode the two permissible
3037-
// places: the exchange heap and the managed heap.
3036+
// FIXME(pcwalton): For now we hardcode the only permissible
3037+
// place: the exchange heap.
30383038
let definition = lookup_full_def(tcx, path.span, place.id);
30393039
let def_id = definition.def_id();
30403040
let referent_ty = fcx.expr_ty(&**subexpr);
@@ -3048,7 +3048,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
30483048

30493049
if !checked {
30503050
span_err!(tcx.sess, expr.span, E0066,
3051-
"only the managed heap and exchange heap are currently supported");
3051+
"only the exchange heap is currently supported");
30523052
fcx.write_ty(id, tcx.types.err);
30533053
}
30543054
}
@@ -3268,7 +3268,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
32683268
if let Err(_) = fcx.mk_eqty(false, infer::Misc(expr.span),
32693269
result_type, ty::mk_nil(fcx.tcx())) {
32703270
span_err!(tcx.sess, expr.span, E0069,
3271-
"`return;` in function returning non-nil");
3271+
"`return;` in a function whose return type is \
3272+
not `()`");
32723273
},
32733274
Some(ref e) => {
32743275
check_expr_coercable_to_type(fcx, &**e, result_type);

src/librustc_typeck/diagnostics.rs

Lines changed: 193 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,51 @@ methods that do not have default implementations), as well as any required
1919
trait items like associated types or constants.
2020
"##,
2121

22+
E0049: r##"
23+
This error indicates that an attempted implementation of a trait method
24+
has the wrong number of type parameters.
25+
26+
For example, the trait below has a method `foo` with a type parameter `T`,
27+
but the implementation of `foo` for the type `Bar` is missing this parameter:
28+
29+
```
30+
trait Foo {
31+
fn foo<T: Default>(x: T) -> Self;
32+
}
33+
34+
struct Bar;
35+
36+
// error: method `foo` has 0 type parameters but its trait declaration has 1
37+
// type parameter
38+
impl Foo for Bar {
39+
fn foo(x: bool) -> Self { Bar }
40+
}
41+
```
42+
"##,
43+
44+
E0050: r##"
45+
This error indicates that an attempted implementation of a trait method
46+
has the wrong number of function parameters.
47+
48+
For example, the trait below has a method `foo` with two function parameters
49+
(`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits
50+
the `u8` parameter:
51+
52+
```
53+
trait Foo {
54+
fn foo(&self, x: u8) -> bool;
55+
}
56+
57+
struct Bar;
58+
59+
// error: method `foo` has 1 parameter but the declaration in trait `Foo::foo`
60+
// has 2
61+
impl Foo for Bar {
62+
fn foo(&self) -> bool { true }
63+
}
64+
```
65+
"##,
66+
2267
E0054: r##"
2368
It is not allowed to cast to a bool. If you are trying to cast a numeric type
2469
to a bool, you can compare it with zero instead:
@@ -46,6 +91,16 @@ enum variant, one of the fields was not provided. Each field should be specified
4691
exactly once.
4792
"##,
4893

94+
E0066: r##"
95+
Box placement expressions (like C++'s "placement new") do not support any
96+
place expression except the exchange heap (i.e. `std::boxed::HEAP`).
97+
Furthermore, the syntax is changing to use `in` instead of `box`. See [RFC
98+
470][rfc470] and [RFC 809][rfc809] for more details.
99+
100+
[rfc470]: https://github.com/rust-lang/rfcs/pull/470
101+
[rfc809]: https://github.com/rust-lang/rfcs/pull/809
102+
"##,
103+
49104
E0067: r##"
50105
The left-hand side of an assignment operator must be an lvalue expression. An
51106
lvalue expression represents a memory location and includes item paths (ie,
@@ -63,6 +118,22 @@ LinkedList::new() += 1;
63118
```
64119
"##,
65120

121+
E0069: r##"
122+
This error means that the compiler found a function whose body contains a
123+
`return;` statement but whose return type is not `()`. For example:
124+
125+
```
126+
// error
127+
fn foo() -> u8 {
128+
return;
129+
}
130+
```
131+
132+
When you omit the value from a `return` expression (that is, when you use
133+
`return;` instead of `return x;`), the value `()` gets returned. So `return;`
134+
is always incorrect for a function whose return type is not `()`.
135+
"##,
136+
66137
E0081: r##"
67138
Enum discriminants are used to differentiate enum variants stored in memory.
68139
This error indicates that the same value was used for two or more variants,
@@ -138,6 +209,88 @@ enum Empty {}
138209
```
139210
"##,
140211

212+
E0106: r##"
213+
This error indicates that a lifetime is missing from a type. If it is an error
214+
inside a function signature, the problem may be with failing to adhere to the
215+
lifetime elision rules (see below).
216+
217+
Here are some simple examples of where you'll run into this error:
218+
219+
```
220+
struct Foo { x: &bool } // error
221+
struct Foo<'a> { x: &'a bool } // correct
222+
223+
enum Bar { A(u8), B(&bool), } // error
224+
enum Bar<'a> { A(u8), B(&'a bool), } // correct
225+
226+
type MyStr = &str; // error
227+
type MyStr<'a> = &'a str; //correct
228+
229+
```
230+
231+
Lifetime elision is a special, limited kind of inference for lifetimes in
232+
function signatures which allows you to leave out lifetimes in certain cases.
233+
For more background on lifetime elision see [the book][book-le].
234+
235+
The lifetime elision rules require that any function signature with an elided
236+
output lifetime must either have
237+
238+
- exactly one input lifetime
239+
- or, multiple input lifetimes, but the function must also be a method with a
240+
`&self` or `&mut self` receiver
241+
242+
In the first case, the output lifetime is inferred to be the same as the unique
243+
input lifetime. In the second case, the lifetime is instead inferred to be the
244+
same as the lifetime on `&self` or `&mut self`.
245+
246+
Here are some examples of elision errors:
247+
248+
```
249+
// error, no input lifetimes
250+
fn foo() -> &str { ... }
251+
252+
// error, `x` and `y` have distinct lifetimes inferred
253+
fn bar(x: &str, y: &str) -> &str { ... }
254+
255+
// error, `y`'s lifetime is inferred to be distinct from `x`'s
256+
fn baz<'a>(x: &'a str, y: &str) -> &str { ... }
257+
```
258+
259+
[book-le]: http://doc.rust-lang.org/nightly/book/lifetimes.html#lifetime-elision
260+
"##,
261+
262+
E0107: r##"
263+
This error means that an incorrect number of lifetime parameters were provided
264+
for a type (like a struct or enum) or trait.
265+
266+
Some basic examples include:
267+
268+
```
269+
struct Foo<'a>(&'a str);
270+
enum Bar { A, B, C }
271+
272+
struct Baz<'a> {
273+
foo: Foo, // error: expected 1, found 0
274+
bar: Bar<'a>, // error: expected 0, found 1
275+
}
276+
```
277+
278+
Here's an example that is currently an error, but may work in a future version
279+
of Rust:
280+
281+
```
282+
struct Foo<'a>(&'a str);
283+
284+
trait Quux { }
285+
impl Quux for Foo { } // error: expected 1, found 0
286+
```
287+
288+
Lifetime elision in implementation headers was part of the lifetime elision
289+
RFC. It is, however, [currently unimplemented][iss15872].
290+
291+
[iss15872]: https://github.com/rust-lang/rust/issues/15872
292+
"##,
293+
141294
E0131: r##"
142295
It is not possible to define `main` with type parameters, or even with function
143296
parameters. When `main` is present, it must take no arguments and return `()`.
@@ -152,6 +305,20 @@ fn(isize, *const *const u8) -> isize
152305
```
153306
"##,
154307

308+
E0166: r##"
309+
This error means that the compiler found a return expression in a function
310+
marked as diverging. A function diverges if it has `!` in the place of the
311+
return type in its signature. For example:
312+
313+
```
314+
fn foo() -> ! { return; } // error
315+
```
316+
317+
For a function that diverges, every control path in the function must never
318+
return, for example with a `loop` that never breaks or a call to another
319+
diverging function (such as `panic!()`).
320+
"##,
321+
155322
E0184: r##"
156323
Explicitly implementing both Drop and Copy for a type is currently disallowed.
157324
This feature can make some sense in theory, but the current implementation is
@@ -161,6 +328,24 @@ it has been disabled for now.
161328
[iss20126]: https://github.com/rust-lang/rust/issues/20126
162329
"##,
163330

331+
E0201: r##"
332+
It is an error to define a method--a trait method or an inherent method--more
333+
than once.
334+
335+
For example,
336+
337+
```
338+
struct Foo(u8);
339+
340+
impl Foo {
341+
fn bar() {}
342+
343+
// error: duplicate method
344+
fn bar(&self) -> bool { self.0 > 5 }
345+
}
346+
```
347+
"##,
348+
164349
E0204: r##"
165350
An attempt to implement the `Copy` trait for a struct failed because one of the
166351
fields does not implement `Copy`. To fix this, you must implement `Copy` for the
@@ -292,6 +477,13 @@ const B: [u32; foo()] = [];
292477
use std::{f64, u8};
293478
const C: [u32; u8::MAX + f64::EPSILON] = [];
294479
```
480+
"##,
481+
482+
E0322: r##"
483+
The `Sized` trait is a special trait built-in to the compiler for types with a
484+
constant size known at compile-time. This trait is automatically implemented
485+
for types as needed by the compiler, and it is currently disallowed to
486+
explicitly implement it for a type.
295487
"##
296488

297489
}
@@ -313,17 +505,13 @@ register_diagnostics! {
313505
E0040, // explicit use of destructor method
314506
E0044, // foreign items may not have type parameters
315507
E0045, // variadic function must have C calling convention
316-
E0049,
317-
E0050,
318508
E0053,
319509
E0055, // method has an incompatible type for trait
320510
E0057, // method has an incompatible type for trait
321511
E0059,
322512
E0060,
323513
E0061,
324-
E0066,
325514
E0068,
326-
E0069,
327515
E0070,
328516
E0071,
329517
E0072,
@@ -346,8 +534,6 @@ register_diagnostics! {
346534
E0102,
347535
E0103,
348536
E0104,
349-
E0106,
350-
E0107,
351537
E0116,
352538
E0117,
353539
E0118,
@@ -365,7 +551,6 @@ register_diagnostics! {
365551
E0159,
366552
E0163,
367553
E0164,
368-
E0166,
369554
E0167,
370555
E0168,
371556
E0172,
@@ -391,7 +576,6 @@ register_diagnostics! {
391576
E0198, // negative implementations are not unsafe
392577
E0199, // implementing trait is not unsafe
393578
E0200, // trait requires an `unsafe impl` declaration
394-
E0201, // duplicate method in trait impl
395579
E0202, // associated items are not allowed in inherent impls
396580
E0203, // type parameter has more than one relaxed default bound,
397581
// and only one is supported
@@ -422,7 +606,7 @@ register_diagnostics! {
422606
E0231, // only named substitution parameters are allowed
423607
E0232, // this attribute must have a value
424608
E0233,
425-
E0234, // `for` loop expression has type which does not implement the `Iterator` trait
609+
E0234,
426610
E0235, // structure constructor specifies a structure of type but
427611
E0236, // no lang item for range syntax
428612
E0237, // no lang item for range syntax
@@ -439,7 +623,6 @@ register_diagnostics! {
439623
E0319, // trait impls for defaulted traits allowed just for structs/enums
440624
E0320, // recursive overflow during dropck
441625
E0321, // extended coherence rules for defaulted traits violated
442-
E0322, // cannot implement Sized explicitly
443626
E0323, // implemented an associated const when another trait item expected
444627
E0324, // implemented a method when another trait item expected
445628
E0325, // implemented an associated type when another trait item expected

0 commit comments

Comments
 (0)