-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explain why
Self
is invalid in generic parameters
- Loading branch information
1 parent
d45ed75
commit a72dd4a
Showing
3 changed files
with
35 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// Regression test of #36638. | ||
|
||
struct Foo<Self>(Self); | ||
//~^ ERROR expected identifier, found keyword `Self` | ||
//~^^ ERROR E0392 | ||
//~^ ERROR unexpected keyword `Self` in generic parameters | ||
//~| ERROR recursive type `Foo` has infinite size | ||
|
||
trait Bar<Self> {} | ||
//~^ ERROR expected identifier, found keyword `Self` | ||
//~^ ERROR unexpected keyword `Self` in generic parameters | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
error: expected identifier, found keyword `Self` | ||
error: unexpected keyword `Self` in generic parameters | ||
--> $DIR/keyword-self-as-type-param.rs:3:12 | ||
| | ||
LL | struct Foo<Self>(Self); | ||
| ^^^^ expected identifier, found keyword | ||
| ^^^^ | ||
| | ||
= note: you cannot use `Self` as a generic parameter because it is reserved for associated items | ||
|
||
error: expected identifier, found keyword `Self` | ||
error: unexpected keyword `Self` in generic parameters | ||
--> $DIR/keyword-self-as-type-param.rs:7:11 | ||
| | ||
LL | trait Bar<Self> {} | ||
| ^^^^ expected identifier, found keyword | ||
| ^^^^ | ||
| | ||
= note: you cannot use `Self` as a generic parameter because it is reserved for associated items | ||
|
||
error[E0392]: parameter `Self` is never used | ||
--> $DIR/keyword-self-as-type-param.rs:3:12 | ||
error[E0072]: recursive type `Foo` has infinite size | ||
--> $DIR/keyword-self-as-type-param.rs:3:1 | ||
| | ||
LL | struct Foo<Self>(Self); | ||
| ^^^^ unused parameter | ||
| ^^^^^^^^^^^^^^^^^----^^ | ||
| | | | ||
| | recursive without indirection | ||
| recursive type has infinite size | ||
| | ||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable | ||
| | ||
= help: consider removing `Self`, referring to it in a field, or using a marker such as `PhantomData` | ||
= help: if you intended `Self` to be a const parameter, use `const Self: usize` instead | ||
LL | struct Foo<Self>(Box<Self>); | ||
| ++++ + | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0392`. | ||
For more information about this error, try `rustc --explain E0072`. |