@@ -64,6 +64,44 @@ impl Foo for Bar {
64
64
```
65
65
"## ,
66
66
67
+ E0053 : r##"
68
+ In a trait method implementation, the function signature must match exactly.
69
+ This error indicates a mutability mismatch between a trait method signature
70
+ and the signature of the implementation.
71
+
72
+ Here's an example where the mutability of the `self` parameter is wrong:
73
+
74
+ ```
75
+ trait Foo { fn foo(&self); }
76
+
77
+ struct Bar;
78
+
79
+ impl Foo for Bar {
80
+ // error, the signature should be `fn foo(&self)` instead
81
+ fn foo(&mut self) { }
82
+ }
83
+
84
+ fn main() {}
85
+ ```
86
+
87
+ Here's another example, this time for a non-`self` parameter:
88
+
89
+ ```
90
+ trait Foo { fn foo(x: &mut bool) -> bool; }
91
+
92
+ struct Bar;
93
+
94
+ impl Foo for Bar {
95
+ // error, the type of `x` should be `&mut bool` instead
96
+ fn foo(x: &bool) -> bool { *x }
97
+ }
98
+
99
+ fn main() {}
100
+ ```
101
+
102
+
103
+ "## ,
104
+
67
105
E0054 : r##"
68
106
It is not allowed to cast to a bool. If you are trying to cast a numeric type
69
107
to a bool, you can compare it with zero instead:
@@ -483,6 +521,48 @@ The `Sized` trait is a special trait built-in to the compiler for types with a
483
521
constant size known at compile-time. This trait is automatically implemented
484
522
for types as needed by the compiler, and it is currently disallowed to
485
523
explicitly implement it for a type.
524
+ "## ,
525
+
526
+ E0368 : r##"
527
+ This error indicates that a binary assignment operator like `+=` or `^=` was
528
+ applied to the wrong types.
529
+
530
+ A couple examples of this are as follows:
531
+
532
+ ```
533
+ let mut x: u16 = 5;
534
+ x ^= true; // error, `^=` cannot be applied to types `u16` and `bool`
535
+ x += (); // error, `+=` cannot be applied to types `u16` and `()`
536
+ ```
537
+
538
+ Another problem you might be facing is this: suppose you've overloaded the `+`
539
+ operator for some type `Foo` by implementing the `std::ops::Add` trait for
540
+ `Foo`, but you find that using `+=` does not work, as in this example:
541
+
542
+ ```
543
+ use std::ops::Add;
544
+
545
+ struct Foo(u32);
546
+
547
+ impl Add for Foo {
548
+ type Output = Foo;
549
+
550
+ fn add(self, rhs: Foo) -> Foo {
551
+ Foo(self.0 + rhs.0)
552
+ }
553
+ }
554
+
555
+ fn main() {
556
+ let mut x: Foo = Foo(5);
557
+ x += Foo(7); // error, `+= cannot be applied to types `Foo` and `Foo`
558
+ }
559
+ ```
560
+
561
+ This is because the binary assignment operators currently do not work off of
562
+ traits, so it is not possible to overload them. See [RFC 953] for a proposal
563
+ to change this.
564
+
565
+ [RFC 953]: https://github.com/rust-lang/rfcs/pull/953
486
566
"##
487
567
488
568
}
@@ -503,7 +583,6 @@ register_diagnostics! {
503
583
E0040 , // explicit use of destructor method
504
584
E0044 , // foreign items may not have type parameters
505
585
E0045 , // variadic function must have C calling convention
506
- E0053 ,
507
586
E0055 , // method has an incompatible type for trait
508
587
E0057 , // method has an incompatible type for trait
509
588
E0059 ,
@@ -629,7 +708,6 @@ register_diagnostics! {
629
708
E0328 , // cannot implement Unsize explicitly
630
709
E0366 , // dropck forbid specialization to concrete type or region
631
710
E0367 , // dropck forbid specialization to predicate not in struct/enum
632
- E0368 , // binary operation `<op>=` cannot be applied to types
633
711
E0369 , // binary operation `<op>` cannot be applied to types
634
712
E0371 , // impl Trait for Trait is illegal
635
713
E0372 , // impl Trait for Trait where Trait is not object safe
0 commit comments