Skip to content

Commit 7ac49fc

Browse files
author
Nick Hamann
committed
Add error explanations for E0055, E0089, E0192, E0261, E0262, E0263, E0318.
1 parent 820b1d8 commit 7ac49fc

File tree

2 files changed

+116
-7
lines changed

2 files changed

+116
-7
lines changed

src/librustc/diagnostics.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,54 @@ enum Method { GET, POST }
396396
```
397397
"##,
398398

399+
E0261: r##"
400+
When using a lifetime like `'a` in a type, it must be declared before being
401+
used.
402+
403+
These two examples illustrate the problem:
404+
405+
```
406+
// error, use of undeclared lifetime name `'a`
407+
fn foo(x: &'a str) { }
408+
409+
struct Foo {
410+
// error, use of undeclared lifetime name `'a`
411+
x: &'a str,
412+
}
413+
```
414+
415+
These can be fixed by declaring lifetime parameters:
416+
417+
```
418+
fn foo<'a>(x: &'a str) { }
419+
420+
struct Foo<'a> {
421+
x: &'a str,
422+
}
423+
```
424+
"##,
425+
426+
E0262: r##"
427+
Declaring certain lifetime names in parameters is disallowed. For example,
428+
because the `'static` lifetime is a special built-in lifetime name denoting
429+
the lifetime of the entire program, this is an error:
430+
431+
```
432+
// error, illegal lifetime parameter name `'static`
433+
fn foo<'static>(x: &'static str) { }
434+
```
435+
"##,
436+
437+
E0263: r##"
438+
A lifetime name cannot be declared more than once in the same scope. For
439+
example:
440+
441+
```
442+
// error, lifetime name `'a` declared twice in the same scope
443+
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { }
444+
```
445+
"##,
446+
399447
E0265: r##"
400448
This error indicates that a static or constant references itself.
401449
All statics and constants need to resolve to a value in an acyclic manner.
@@ -814,9 +862,6 @@ register_diagnostics! {
814862
E0136,
815863
E0138,
816864
E0139,
817-
E0261, // use of undeclared lifetime name
818-
E0262, // illegal lifetime parameter name
819-
E0263, // lifetime name declared twice in same scope
820865
E0264, // unknown external lang item
821866
E0266, // expected item
822867
E0269, // not all control paths return a value

src/librustc_typeck/diagnostics.rs

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,37 @@ let x_is_nonzero = x as bool;
274274
```
275275
"##,
276276

277+
E0055: r##"
278+
During a method call, a value is automatically dereferenced as many times as
279+
needed to make the value's type match the method's receiver. The catch is that
280+
the compiler will only attempt to dereference a number of times up to the
281+
recursion limit (which can be set via the `recursion_limit` attribute).
282+
283+
For a somewhat artificial example:
284+
285+
```
286+
#![recursion_limit="2"]
287+
288+
struct Foo;
289+
290+
impl Foo {
291+
fn foo(&self) {}
292+
}
293+
294+
fn main() {
295+
let foo = Foo;
296+
let ref_foo = &&Foo;
297+
298+
// error, reached the recursion limit while auto-dereferencing &&Foo
299+
ref_foo.foo();
300+
}
301+
```
302+
303+
One fix may be to increase the recursion limit. Note that it is possible to
304+
create an infinite recursion of dereferencing, in which case the only fix is to
305+
somehow break the recursion.
306+
"##,
307+
277308
E0062: r##"
278309
This error indicates that during an attempt to build a struct or struct-like
279310
enum variant, one of the fields was specified more than once. Each field should
@@ -524,6 +555,31 @@ enum Empty {}
524555
```
525556
"##,
526557

558+
E0089: r##"
559+
Not enough type parameters were supplied for a function. For example:
560+
561+
```
562+
fn foo<T, U>() {}
563+
564+
fn main() {
565+
foo::<f64>(); // error, expected 2 parameters, found 1 parameter
566+
}
567+
```
568+
569+
Note that if a function takes multiple type parameters but you want the compiler
570+
to infer some of them, you can use type placeholders:
571+
572+
```
573+
fn foo<T, U>(x: T) {}
574+
575+
fn main() {
576+
let x: bool = true;
577+
foo::<f64>(x); // error, expected 2 parameters, found 1 parameter
578+
foo::<_, f64>(x); // same as `foo::<bool, f64>(x)`
579+
}
580+
```
581+
"##,
582+
527583
E0106: r##"
528584
This error indicates that a lifetime is missing from a type. If it is an error
529585
inside a function signature, the problem may be with failing to adhere to the
@@ -678,6 +734,12 @@ it has been disabled for now.
678734
[iss20126]: https://github.com/rust-lang/rust/issues/20126
679735
"##,
680736

737+
E0192: r##"
738+
Negative impls are only allowed for traits with default impls. For more
739+
information see the [opt-in builtin traits RFC](https://github.com/rust-lang/
740+
rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
741+
"##,
742+
681743
E0197: r##"
682744
Inherent implementations (one that do not implement a trait but provide
683745
methods associated with a type) are always safe because they are not
@@ -899,6 +961,12 @@ const C: [u32; u8::MAX + f64::EPSILON] = [];
899961
```
900962
"##,
901963

964+
E0318: r##"
965+
Default impls for a trait must be located in the same crate where the trait was
966+
defined. For more information see the [opt-in builtin traits RFC](https://github
967+
.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
968+
"##,
969+
902970
E0322: r##"
903971
The `Sized` trait is a special trait built-in to the compiler for types with a
904972
constant size known at compile-time. This trait is automatically implemented
@@ -989,7 +1057,6 @@ register_diagnostics! {
9891057
E0040, // explicit use of destructor method
9901058
E0044, // foreign items may not have type parameters
9911059
E0045, // variadic function must have C calling convention
992-
E0055, // method has an incompatible type for trait
9931060
E0057, // method has an incompatible type for trait
9941061
E0059,
9951062
E0060,
@@ -1004,7 +1071,6 @@ register_diagnostics! {
10041071
E0086,
10051072
E0087,
10061073
E0088,
1007-
E0089,
10081074
E0090,
10091075
E0091,
10101076
E0092,
@@ -1044,7 +1110,6 @@ register_diagnostics! {
10441110
E0189, // deprecated: can only cast a boxed pointer to a boxed object
10451111
E0190, // deprecated: can only cast a &-pointer to an &-object
10461112
E0191, // value of the associated type must be specified
1047-
E0192, // negative impls are allowed just for `Send` and `Sync`
10481113
E0193, // cannot bound type where clause bounds may only be attached to types
10491114
// involving type parameters
10501115
E0194,
@@ -1093,7 +1158,6 @@ register_diagnostics! {
10931158
E0246, // illegal recursive type
10941159
E0247, // found module name used as a type
10951160
E0248, // found value name used as a type
1096-
E0318, // can't create default impls for traits outside their crates
10971161
E0319, // trait impls for defaulted traits allowed just for structs/enums
10981162
E0320, // recursive overflow during dropck
10991163
E0321, // extended coherence rules for defaulted traits violated

0 commit comments

Comments
 (0)