@@ -397,6 +397,55 @@ impl Bar {
397397```
398398"## ,
399399
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+
400449E0412 : r##"
401450An undeclared type name was used. Example of erroneous codes:
402451
@@ -835,7 +884,6 @@ register_diagnostics! {
835884 E0409 , // variable is bound with different mode in pattern # than in
836885 // pattern #1
837886 E0410 , // variable from pattern is not bound in pattern 1
838- E0411 , // use of `Self` outside of an impl or trait
839887 E0414 , // only irrefutable patterns allowed here
840888 E0418 , // is not an enum variant, struct or const
841889 E0420 , // is not an associated const
0 commit comments