Skip to content

Commit 886ea16

Browse files
committed
Rollup merge of rust-lang#28010 - GuillaumeGomez:patch-2, r=Manishearth
r? @Manishearth
2 parents abfa081 + fbbd874 commit 886ea16

File tree

1 file changed

+174
-41
lines changed

1 file changed

+174
-41
lines changed

src/librustc_typeck/diagnostics.rs

+174-41
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,39 @@ the enum.
7373
"##,
7474

7575
E0025: r##"
76-
Each field of a struct can only be bound once in a pattern. Each occurrence of a
77-
field name binds the value of that field, so to fix this error you will have to
78-
remove or alter the duplicate uses of the field name. Perhaps you misspelt
79-
another field name?
76+
Each field of a struct can only be bound once in a pattern. Erroneous code
77+
example:
78+
79+
```
80+
struct Foo {
81+
a: u8,
82+
b: u8,
83+
}
84+
85+
fn main(){
86+
let x = Foo { a:1, b:2 };
87+
88+
let Foo { a: x, a: y } = x;
89+
// error: field `a` bound multiple times in the pattern
90+
}
91+
```
92+
93+
Each occurrence of a field name binds the value of that field, so to fix this
94+
error you will have to remove or alter the duplicate uses of the field name.
95+
Perhaps you misspelled another field name? Example:
96+
97+
```
98+
struct Foo {
99+
a: u8,
100+
b: u8,
101+
}
102+
103+
fn main(){
104+
let x = Foo { a:1, b:2 };
105+
106+
let Foo { a: x, b: y } = x; // ok!
107+
}
108+
```
80109
"##,
81110

82111
E0026: r##"
@@ -401,10 +430,35 @@ extern "C" {
401430
"##,
402431

403432
E0046: r##"
433+
Items are missing in a trait implementation. Erroneous code example:
434+
435+
```
436+
trait Foo {
437+
fn foo();
438+
}
439+
440+
struct Bar;
441+
442+
impl Foo for Bar {}
443+
// error: not all trait items implemented, missing: `foo`
444+
```
445+
404446
When trying to make some type implement a trait `Foo`, you must, at minimum,
405447
provide implementations for all of `Foo`'s required methods (meaning the
406448
methods that do not have default implementations), as well as any required
407-
trait items like associated types or constants.
449+
trait items like associated types or constants. Example:
450+
451+
```
452+
trait Foo {
453+
fn foo();
454+
}
455+
456+
struct Bar;
457+
458+
impl Foo for Bar {
459+
fn foo() {} // ok!
460+
}
461+
```
408462
"##,
409463

410464
E0049: r##"
@@ -615,14 +669,62 @@ variadic functions (except for its C-FFI).
615669

616670
E0062: r##"
617671
This error indicates that during an attempt to build a struct or struct-like
618-
enum variant, one of the fields was specified more than once. Each field should
619-
be specified exactly one time.
672+
enum variant, one of the fields was specified more than once. Erroneous code
673+
example:
674+
675+
```
676+
struct Foo {
677+
x: i32
678+
}
679+
680+
fn main() {
681+
let x = Foo {
682+
x: 0,
683+
x: 0, // error: field `x` specified more than once
684+
};
685+
}
686+
```
687+
688+
Each field should be specified exactly one time. Example:
689+
690+
```
691+
struct Foo {
692+
x: i32
693+
}
694+
695+
fn main() {
696+
let x = Foo { x: 0 }; // ok!
697+
}
698+
```
620699
"##,
621700

622701
E0063: r##"
623702
This error indicates that during an attempt to build a struct or struct-like
624-
enum variant, one of the fields was not provided. Each field should be
625-
specified exactly once.
703+
enum variant, one of the fields was not provided. Erroneous code example:
704+
705+
```
706+
struct Foo {
707+
x: i32,
708+
y: i32
709+
}
710+
711+
fn main() {
712+
let x = Foo { x: 0 }; // error: missing field: `y`
713+
}
714+
```
715+
716+
Each field should be specified exactly once. Example:
717+
718+
```
719+
struct Foo {
720+
x: i32,
721+
y: i32
722+
}
723+
724+
fn main() {
725+
let x = Foo { x: 0, y: 0 }; // ok!
726+
}
727+
```
626728
"##,
627729

628730
E0066: r##"
@@ -1025,7 +1127,7 @@ fn main() {
10251127
}
10261128
```
10271129
1028-
The number of supplied parameters much exactly match the number of defined type
1130+
The number of supplied parameters must exactly match the number of defined type
10291131
parameters.
10301132
"##,
10311133

@@ -1620,14 +1722,20 @@ extern {
16201722
E0131: r##"
16211723
It is not possible to define `main` with type parameters, or even with function
16221724
parameters. When `main` is present, it must take no arguments and return `()`.
1725+
Erroneous code example:
1726+
1727+
```
1728+
fn main<T>() { // error: main function is not allowed to have type parameters
1729+
}
1730+
```
16231731
"##,
16241732

16251733
E0132: r##"
16261734
It is not possible to declare type parameters on a function that has the `start`
16271735
attribute. Such a function must have the following type signature:
16281736
16291737
```
1630-
fn(isize, *const *const u8) -> isize
1738+
fn(isize, *const *const u8) -> isize;
16311739
```
16321740
"##,
16331741

@@ -1779,7 +1887,7 @@ rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
17791887

17801888
E0193: r##"
17811889
`where` clauses must use generic type parameters: it does not make sense to use
1782-
them otherwise. An example causing this error:
1890+
them otherwise. An example causing this error:
17831891
17841892
```
17851893
trait Foo {
@@ -1881,7 +1989,6 @@ unsafe impl Foo { }
18811989
// converting it to this will fix it
18821990
impl Foo { }
18831991
```
1884-
18851992
"##,
18861993

18871994
E0198: r##"
@@ -1898,7 +2005,6 @@ unsafe impl !Clone for Foo { }
18982005
// this will compile
18992006
impl !Clone for Foo { }
19002007
```
1901-
19022008
"##,
19032009

19042010
E0199: r##"
@@ -1916,7 +2022,6 @@ unsafe impl Bar for Foo { }
19162022
// this will compile
19172023
impl Bar for Foo { }
19182024
```
1919-
19202025
"##,
19212026

19222027
E0200: r##"
@@ -1934,7 +2039,6 @@ impl Bar for Foo { }
19342039
// this will compile
19352040
unsafe impl Bar for Foo { }
19362041
```
1937-
19382042
"##,
19392043

19402044
E0201: r##"
@@ -2717,6 +2821,36 @@ It is also possible to overload most operators for your own type by
27172821
implementing traits from `std::ops`.
27182822
"##,
27192823

2824+
E0370: r##"
2825+
The maximum value of an enum was reached, so it cannot be automatically
2826+
set in the next enum value. Erroneous code example:
2827+
2828+
```
2829+
enum Foo {
2830+
X = 0x7fffffffffffffff,
2831+
Y // error: enum discriminant overflowed on value after
2832+
// 9223372036854775807: i64; set explicitly via
2833+
// Y = -9223372036854775808 if that is desired outcome
2834+
}
2835+
```
2836+
2837+
To fix this, please set manually the next enum value or put the enum variant
2838+
with the maximum value at the end of the enum. Examples:
2839+
2840+
```
2841+
enum Foo {
2842+
X = 0x7fffffffffffffff,
2843+
Y = 0, // ok!
2844+
}
2845+
2846+
// or:
2847+
enum Foo {
2848+
Y = 0, // ok!
2849+
X = 0x7fffffffffffffff,
2850+
}
2851+
```
2852+
"##,
2853+
27202854
E0371: r##"
27212855
When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
27222856
definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
@@ -2869,44 +3003,44 @@ https://doc.rust-lang.org/std/marker/struct.PhantomData.html
28693003
}
28703004

28713005
register_diagnostics! {
2872-
E0068,
2873-
E0085,
2874-
E0086,
3006+
// E0068,
3007+
// E0085,
3008+
// E0086,
28753009
E0090,
28763010
E0103, // @GuillaumeGomez: I was unable to get this error, try your best!
28773011
E0104,
28783012
E0118,
28793013
E0122,
2880-
E0123,
2881-
E0127,
2882-
E0129,
2883-
E0141,
3014+
// E0123,
3015+
// E0127,
3016+
// E0129,
3017+
// E0141,
28843018
// E0159, // use of trait `{}` as struct constructor
28853019
E0163,
28863020
E0164,
28873021
E0167,
28883022
// E0168,
2889-
E0173, // manual implementations of unboxed closure traits are experimental
3023+
// E0173, // manual implementations of unboxed closure traits are experimental
28903024
E0174, // explicit use of unboxed closure methods are experimental
28913025
E0182,
28923026
E0183,
2893-
E0187, // can't infer the kind of the closure
2894-
E0188, // can not cast a immutable reference to a mutable pointer
2895-
E0189, // deprecated: can only cast a boxed pointer to a boxed object
2896-
E0190, // deprecated: can only cast a &-pointer to an &-object
3027+
// E0187, // can't infer the kind of the closure
3028+
// E0188, // can not cast a immutable reference to a mutable pointer
3029+
// E0189, // deprecated: can only cast a boxed pointer to a boxed object
3030+
// E0190, // deprecated: can only cast a &-pointer to an &-object
28973031
E0196, // cannot determine a type for this closure
28983032
E0203, // type parameter has more than one relaxed default bound,
28993033
// and only one is supported
29003034
E0208,
2901-
E0209, // builtin traits can only be implemented on structs or enums
3035+
// E0209, // builtin traits can only be implemented on structs or enums
29023036
E0212, // cannot extract an associated type from a higher-ranked trait bound
2903-
E0213, // associated types are not accepted in this context
3037+
// E0213, // associated types are not accepted in this context
29043038
E0214, // parenthesized parameters may only be used with a trait
29053039
// E0215, // angle-bracket notation is not stable with `Fn`
29063040
// E0216, // parenthetical notation is only stable with `Fn`
2907-
E0217, // ambiguous associated type, defined in multiple supertraits
2908-
E0218, // no associated type defined
2909-
E0219, // associated type defined in higher-ranked supertrait
3041+
// E0217, // ambiguous associated type, defined in multiple supertraits
3042+
// E0218, // no associated type defined
3043+
// E0219, // associated type defined in higher-ranked supertrait
29103044
// E0222, // Error code E0045 (variadic function must have C calling
29113045
// convention) duplicate
29123046
E0224, // at least one non-builtin train is required for an object type
@@ -2916,25 +3050,24 @@ register_diagnostics! {
29163050
E0229, // associated type bindings are not allowed here
29173051
E0230, // there is no type parameter on trait
29183052
E0231, // only named substitution parameters are allowed
2919-
E0233,
2920-
E0234,
3053+
// E0233,
3054+
// E0234,
29213055
// E0235, // structure constructor specifies a structure of type but
29223056
E0236, // no lang item for range syntax
29233057
E0237, // no lang item for range syntax
29243058
E0238, // parenthesized parameters may only be used with a trait
2925-
E0239, // `next` method of `Iterator` trait has unexpected type
2926-
E0240,
2927-
E0241,
3059+
// E0239, // `next` method of `Iterator` trait has unexpected type
3060+
// E0240,
3061+
// E0241,
29283062
E0242, // internal error looking up a definition
29293063
E0245, // not a trait
2930-
E0246, // invalid recursive type
3064+
// E0246, // invalid recursive type
29313065
E0247, // found module name used as a type
2932-
E0319, // trait impls for defaulted traits allowed just for structs/enums
3066+
// E0319, // trait impls for defaulted traits allowed just for structs/enums
29333067
E0320, // recursive overflow during dropck
29343068
E0321, // extended coherence rules for defaulted traits violated
29353069
E0328, // cannot implement Unsize explicitly
29363070
E0329, // associated const depends on type parameter or Self.
2937-
E0370, // discriminant overflow
29383071
E0374, // the trait `CoerceUnsized` may only be implemented for a coercion
29393072
// between structures with one field being coerced, none found
29403073
E0375, // the trait `CoerceUnsized` may only be implemented for a coercion

0 commit comments

Comments
 (0)