-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking issue for RFC 2300, "Self
in type definitions"
#49303
Comments
I have tried to solve this, but the dfficulty of this is beyond my current rust-experience so I'd appreciate any mentorship. |
re-cc @rust-lang/compiler - could we get some mentoring instructions perhaps per @csmoe's request? |
Currently working on this... |
`Self` in type definitions (self_in_typedefs) This implements the [`self_in_typedefs` feature](https://github.com/rust-lang/rfcs/blob/master/text/2300-self-in-typedefs.md) ([tracking issue 49303](#49303)). r? @eddyb CC @Centril
You can tick off "implemented" now. :-) |
@rfcbot merge Stabilization report & proposalFeature name: Originally accepted in rust-lang/rfcs#2300, I propose that we stabilize The proposed change is not a blocker for anyone but it is a nice quality of life feature in some cases. What is being stabilizedRelevant artefacts: The changes are:
enum List<T>
where
// In where clauses, both on the side of types being constrained and on the bounds side.
Self: PartialOrd<Self>
{
Nil,
Cons(T, Box<Self>) // In fields. The usual rules re. infinite types apply.
} What is not being stabilizedMentions of Divergences from RFCNone Unresolved questionsThere is currently one unresolved question, it reads as:
At this point I believe that the discussion in the RFC is sufficient and that there is no problem should we ever want to pursue the extension aforementioned. Thus, I suggest that we resolve the question as a footnote that may have some value in the future but does not impact us now. |
Team member @Centril has proposed to merge this. The next step is review by the rest of the tagged teams:
No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I still feel that this brings some harm in terms of code readability/searchability and should be generally discouraged. Additionally, interactions with #51994 are not yet implemented and value |
We allow it pretty much everywhere else. I don’t see a difference here. |
I think searchability and readability are not the same thing; However; when it comes to readability, given that we chose to have an implicit head parameter to traits in the form of
What interactions? Can you elaborate (because I don't recall there being any interactions)? Also please elaborate on "value Before stabilizing, we might want to extend the set of tests to include: struct Foo;
impl Foo {
fn bar() {
struct Baz(u8, Option<Box<Self>>);
let cons: Option<Box<Baz>> = None;
let _ = Baz(1, cons); // Make sure that `Self` refers to the right thing
}
} |
Well, you need something contrived to get it, but something like struct S([u8; Self]); should not result in the "cannot find value Obviously, not critical. |
@petrochenkov Oh I see; so to make actual use of it you would need to write: #![feature(self_struct_ctor)]
struct S([u8; weird(Self([]))]);
const fn weird(_: S) -> usize { 0 }
// This has a cycle I think
// Yeah...
// error[E0391]: cycle detected when const-evaluating + checking `S::0::{{constant}}` (enum discriminants or rust-lang/rfcs#1806 might be more realistic use cases...) I re-checked the RFC now and apparently I wrote:
It explicitly says type contexts (and not value contexts), so going by the letter of the RFC, the implementation is correct and the error message should occur (tho it should be differently phrased, but I think we can improve diagnostics later for this pathological case...). I think we can probably revisit this later. :) |
Stabilization PR (for when FCP finishes, hopefully) |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
… r=Centril Stabilize self_in_typedefs feature [**Tracking Issue**](rust-lang#49303) r? @Centril
… r=Centril Stabilize self_in_typedefs feature [**Tracking Issue**](rust-lang#49303) r? @Centril
… r=Centril Stabilize self_in_typedefs feature [**Tracking Issue**](rust-lang#49303) r? @Centril
The final comment period, with a disposition to merge, as per the review above, is now complete. |
An issue is filed in rust-lang/reference#473 for the documentation. |
@Centril I believe the reference is already up-to-date. |
This is a tracking issue for the RFC "
Self
in type definitions" (rust-lang/rfcs#2300).Steps:
Unresolved questions:
The text was updated successfully, but these errors were encountered: