@@ -397,6 +397,55 @@ impl Bar {
397
397
```
398
398
"## ,
399
399
400
+ E0411 : r##"
401
+ `Self` keyword was used outside an impl or a trait. Erroneous code
402
+ example:
403
+
404
+ ```
405
+ <Self>::foo; // error: use of `Self` outside of an impl or trait
406
+ ```
407
+
408
+ The `Self` keyword represents the current type, which explains why it
409
+ can only be used inside an impl or a trait. For example, it is used
410
+ to solve conflicts like this one:
411
+
412
+ ```
413
+ trait Foo {
414
+ type Bar;
415
+ }
416
+
417
+ trait Foo2 {
418
+ type Bar;
419
+ }
420
+
421
+ trait Baz : Foo + Foo2 {
422
+ fn bar() -> Self::Bar;
423
+ // error: ambiguous associated type `Bar` in bounds of `Self`
424
+ }
425
+ ```
426
+
427
+ Which can be solved by specifying from which trait we want to use
428
+ the `Bar` type:
429
+
430
+ ```
431
+ trait Baz : Foo + Foo2 {
432
+ fn bar() -> <Self as Foo>::Bar; // ok!
433
+ }
434
+ ```
435
+
436
+ A more simple example gives:
437
+
438
+ ```
439
+ trait Foo {
440
+ type Bar;
441
+ }
442
+
443
+ trait Baz : Foo {
444
+ fn bar() -> <Self as Foo>::Bar; // ok!
445
+ }
446
+ ```
447
+ "## ,
448
+
400
449
E0412 : r##"
401
450
An undeclared type name was used. Example of erroneous codes:
402
451
@@ -835,7 +884,6 @@ register_diagnostics! {
835
884
E0409 , // variable is bound with different mode in pattern # than in
836
885
// pattern #1
837
886
E0410 , // variable from pattern is not bound in pattern 1
838
- E0411 , // use of `Self` outside of an impl or trait
839
887
E0414 , // only irrefutable patterns allowed here
840
888
E0418 , // is not an enum variant, struct or const
841
889
E0420 , // is not an associated const
0 commit comments