forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#132361 - jieyouxu:rollup-zburkwr, r=jieyouxu
Rollup of 6 pull requests Successful merges: - rust-lang#130098 (Reject generic self types.) - rust-lang#131096 (rustdoc: Remove usage of `allow(unused)` attribute on `no_run` merged doctests) - rust-lang#132315 (compiletest: improve robustness of LLVM version handling) - rust-lang#132346 (Some graphviz tweaks) - rust-lang#132359 (Fix AIX libc call char type from i8 to u8) - rust-lang#132360 (Un-vacation myself) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
29 changed files
with
836 additions
and
186 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
The `self` parameter in a method has an invalid generic "receiver type". | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0801 | ||
struct Foo; | ||
impl Foo { | ||
fn foo<R: std::ops::Deref<Target=Self>>(self: R) {} | ||
} | ||
``` | ||
|
||
or alternatively, | ||
|
||
```compile_fail,E0801 | ||
struct Foo; | ||
impl Foo { | ||
fn foo(self: impl std::ops::Deref<Target=Self>) {} | ||
} | ||
``` | ||
|
||
Methods take a special first parameter, termed `self`. It's normal to | ||
use `self`, `&self` or `&mut self`, which are syntactic sugar for | ||
`self: Self`, `self: &Self`, and `self: &mut Self` respectively. | ||
But it's also possible to use more sophisticated types of `self` | ||
parameter, for instance `std::rc::Rc<Self>`. The set of allowable | ||
`Self` types is extensible using the nightly feature | ||
[Arbitrary self types][AST]. | ||
This will extend the valid set of `Self` types to anything which implements | ||
`std::ops::Deref<Target=Self>`, for example `Rc<Self>`, `Box<Self>`, or | ||
your own smart pointers that do the same. | ||
|
||
However, even with that feature, the `self` type must be concrete. | ||
Generic `self` types are not permitted. Specifically, a `self` type will | ||
be rejected if it is a type parameter defined on the method. | ||
|
||
These are OK: | ||
|
||
``` | ||
struct Foo; | ||
impl Foo { | ||
fn foo(self) {} | ||
fn foo2(self: std::rc::Rc<Self>) {} // or some other similar | ||
// smart pointer if you enable arbitrary self types and | ||
// the pointer implements Deref<Target=Self> | ||
} | ||
``` | ||
|
||
[AST]: https://doc.rust-lang.org/unstable-book/language-features/arbitrary-self-types.html |
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 |
---|---|---|
|
@@ -540,6 +540,7 @@ E0797: 0797, | |
E0798: 0798, | ||
E0799: 0799, | ||
E0800: 0800, | ||
E0801: 0801, | ||
); | ||
) | ||
} | ||
|
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
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
Oops, something went wrong.