@@ -108,6 +108,63 @@ LinkedList::new() += 1;
108
108
```
109
109
"## ,
110
110
111
+ E0072 : r##"
112
+ When defining a recursive struct or enum, any use of the type being defined
113
+ from inside the definition must occur behind a pointer (like `Box` or `&`).
114
+ This is because structs and enums must have a well-defined size, and without
115
+ the pointer the size of the type would need to be unbounded.
116
+
117
+ Consider the following erroneous definition of a type for a list of bytes:
118
+
119
+ ```
120
+ // error, illegal recursive struct type
121
+ struct ListNode {
122
+ head: u8,
123
+ tail: Option<ListNode>,
124
+ }
125
+ ```
126
+
127
+ This type cannot have a well-defined size, because it needs to be arbitrarily
128
+ large (since we would be able to nest `ListNode`s to any depth). Specifically,
129
+
130
+ ```
131
+ size of ListNode = 1 byte for head
132
+ + 1 byte for the discriminant of the Option
133
+ + size of ListNode
134
+ ```
135
+
136
+ One way to fix this is by wrapping `ListNode` in a `Box`, like so:
137
+
138
+ ```
139
+ struct ListNode {
140
+ head: u8,
141
+ tail: Option<Box<ListNode>>,
142
+ }
143
+ ```
144
+
145
+ This works because `Box` is a pointer, so its size is well-known.
146
+ "## ,
147
+
148
+ E0073 : r##"
149
+ You cannot define a struct (or enum) `Foo` that requires an instance of `Foo`
150
+ in order to make a new `Foo` value. This is because there would be no way a
151
+ first instance of `Foo` could be made to initialize another instance!
152
+
153
+ Here's an example of a struct that has this problem:
154
+
155
+ ```
156
+ struct Foo { x: Box<Foo> } // error
157
+ ```
158
+
159
+ One fix is to use `Option`, like so:
160
+
161
+ ```
162
+ struct Foo { x: Option<Box<Foo>> }
163
+ ```
164
+
165
+ Now it's possible to create at least one instance of `Foo`: `Foo { x: None }`.
166
+ "## ,
167
+
111
168
E0081 : r##"
112
169
Enum discriminants are used to differentiate enum variants stored in memory.
113
170
This error indicates that the same value was used for two or more variants,
@@ -265,6 +322,19 @@ RFC. It is, however, [currently unimplemented][iss15872].
265
322
[iss15872]: https://github.com/rust-lang/rust/issues/15872
266
323
"## ,
267
324
325
+ E0121 : r##"
326
+ In order to be consistent with Rust's lack of global type inference, type
327
+ placeholders are disallowed by design in item signatures.
328
+
329
+ Examples of this error include:
330
+
331
+ ```
332
+ fn foo() -> _ { 5 } // error, explicitly write out the return type instead
333
+
334
+ static BAR: _ = "test"; // error, explicitly write out the type instead
335
+ ```
336
+ "## ,
337
+
268
338
E0131 : r##"
269
339
It is not possible to define `main` with type parameters, or even with function
270
340
parameters. When `main` is present, it must take no arguments and return `()`.
@@ -293,6 +363,28 @@ return, for example with a `loop` that never breaks or a call to another
293
363
diverging function (such as `panic!()`).
294
364
"## ,
295
365
366
+ E0178 : r##"
367
+ In types, the `+` type operator has low precedence, so it is often necessary
368
+ to use parentheses.
369
+
370
+ For example:
371
+
372
+ ```
373
+ trait Foo {}
374
+
375
+ struct Bar<'a> {
376
+ w: &'a Foo + Copy, // error, use &'a (Foo + Copy)
377
+ x: &'a Foo + 'a, // error, use &'a (Foo + 'a)
378
+ y: &'a mut Foo + 'a, // error, use &'a mut (Foo + 'a)
379
+ z: fn() -> Foo + 'a, // error, use fn() -> (Foo + 'a)
380
+ }
381
+ ```
382
+
383
+ More details can be found in [RFC 438].
384
+
385
+ [RFC 438]: https://github.com/rust-lang/rfcs/pull/438
386
+ "## ,
387
+
296
388
E0184 : r##"
297
389
Explicitly implementing both Drop and Copy for a type is currently disallowed.
298
390
This feature can make some sense in theory, but the current implementation is
@@ -458,6 +550,35 @@ The `Sized` trait is a special trait built-in to the compiler for types with a
458
550
constant size known at compile-time. This trait is automatically implemented
459
551
for types as needed by the compiler, and it is currently disallowed to
460
552
explicitly implement it for a type.
553
+ "## ,
554
+
555
+ E0371 : r##"
556
+ When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
557
+ definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
558
+ `Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
559
+ definition, so it is not useful to do this.
560
+
561
+ Example:
562
+
563
+ ```
564
+ trait Foo { fn foo(&self) { } }
565
+ trait Bar: Foo { }
566
+ trait Baz: Bar { }
567
+
568
+ impl Bar for Baz { } // error, `Baz` implements `Bar` by definition
569
+ impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
570
+ impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
571
+ impl Baz for Bar { } // Note: This is OK
572
+ ```
573
+ "## ,
574
+
575
+ E0372 : r##"
576
+ Trying to implement a trait for a trait object (as in `impl Trait1 for
577
+ Trait2 { ... }`) does not work if the trait is not object-safe. Please see the
578
+ [RFC 255] for more details on object safety rules.
579
+
580
+ [RFC 255]:https://github.com/rust-lang/rfcs/blob/master/text/0255-object-\
581
+ safety.md
461
582
"##
462
583
463
584
}
@@ -489,8 +610,6 @@ register_diagnostics! {
489
610
E0069 ,
490
611
E0070 ,
491
612
E0071 ,
492
- E0072 ,
493
- E0073 ,
494
613
E0074 ,
495
614
E0075 ,
496
615
E0076 ,
@@ -514,7 +633,6 @@ register_diagnostics! {
514
633
E0118 ,
515
634
E0119 ,
516
635
E0120 ,
517
- E0121 ,
518
636
E0122 ,
519
637
E0123 ,
520
638
E0124 ,
@@ -531,7 +649,6 @@ register_diagnostics! {
531
649
E0172 ,
532
650
E0173 , // manual implementations of unboxed closure traits are experimental
533
651
E0174 , // explicit use of unboxed closure methods are experimental
534
- E0178 ,
535
652
E0182 ,
536
653
E0183 ,
537
654
E0185 ,
@@ -608,8 +725,6 @@ register_diagnostics! {
608
725
E0367 , // dropck forbid specialization to predicate not in struct/enum
609
726
E0368 , // binary operation `<op>=` cannot be applied to types
610
727
E0369 , // binary operation `<op>` cannot be applied to types
611
- E0371 , // impl Trait for Trait is illegal
612
- E0372 , // impl Trait for Trait where Trait is not object safe
613
728
E0374 , // the trait `CoerceUnsized` may only be implemented for a coercion
614
729
// between structures with one field being coerced, none found
615
730
E0375 , // the trait `CoerceUnsized` may only be implemented for a coercion
0 commit comments