Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upimplement inherent associated items (see RFC 195). #8995
Comments
This comment has been minimized.
This comment has been minimized.
|
Nominating; is backwards compatible. I can try and take this on if we decide we want it. |
This comment has been minimized.
This comment has been minimized.
|
(type aliases would need to preceed all methods) |
This comment has been minimized.
This comment has been minimized.
|
@cmr said "(type aliases would need to preceed all methods)" why? To my knowledge there is no such ordering constraint for type aliases within a mod item, so why would an impl item require this? |
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix yikes, you're right. I think they should be. Why? Because: #[crate_type="lib"];
mod bar {
fn foo() -> T {
32i
}
type T = int;
}is crazy. |
This comment has been minimized.
This comment has been minimized.
|
Why is that less crazy than fn foo() { bar() }
fn bar() {}? |
This comment has been minimized.
This comment has been minimized.
|
I cede. On Tue, Dec 31, 2013 at 1:05 AM, Huon Wilson notifications@github.comwrote:
|
This comment has been minimized.
This comment has been minimized.
|
assigning P-low priority (is backwards compatible going foward, as cmr said). |
This comment has been minimized.
This comment has been minimized.
|
Triage: How does this interact with Associated Types? At least a new syntax would probably have to be chosen. |
This comment has been minimized.
This comment has been minimized.
|
I think that this feature request is actually satisfied by the Associated Items RFC. In particular, the section "inherent associated items" of RFC 59 implies (to me) that you can write the exact example that I had asked for. (I did write in the issue description that this feature request is distinct from associated types, but nonetheless, it seems that the author of RFC 59 decided that it was a natural feature to include.) |
This comment has been minimized.
This comment has been minimized.
|
So, this now seems to be a subissue of #17307. I will change the title to "implement inherent associated items." |
pnkfelix
changed the title
RFC: allow type definition item within impl
implement inherent associated items (see RFC 59).
Oct 6, 2014
This comment has been minimized.
This comment has been minimized.
rohel01
commented
Aug 14, 2015
|
Hello, I hope this the right place to ask for my request. Associated types currently only work with traits. pub struct GenericStruct<A, B> {
fa : A,
fb : B,
}
struct GenericResult<A, B> {
fa : A,
fb : B,
}
impl <A, B> GenericStruct<A, B> {
// I d like to write
// type Result = Option<GenericResult<A, B>>;
// and use it in the code
fn new(a: A, b : B) -> Option<GenericResult<A, B>> {
Some(GenericResult {fa: a, fb : b})
}
} |
petrochenkov
referenced this issue
Sep 14, 2015
Closed
Redefining built-in types does not work #20427
steveklabnik
added
A-associated-items
B-RFC-approved
T-lang
and removed
A-grammar
A-typesystem
P-low
labels
Feb 7, 2017
This comment has been minimized.
This comment has been minimized.
|
I'm going to tag this with the tags from #8995 since it was closed without this being implemented. |
Mark-Simulacrum
added
the
C-feature-request
label
Jul 19, 2017
Mark-Simulacrum
added
C-tracking-issue
and removed
C-enhancement
C-feature-request
labels
Jul 27, 2017
This comment has been minimized.
This comment has been minimized.
|
@steveklabnik I think you meant to reference #17307 rather than #8995, which is this issue. |
This comment has been minimized.
This comment has been minimized.
|
note that inherent associated consts work perfectly fine today
|
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis Is it right to assume that this can't be implemented without lazy normalization? |
This comment has been minimized.
This comment has been minimized.
|
It would be good to link to this issue in the error message for https://doc.rust-lang.org/nightly/error-index.html#E0202, as it's not immediately clear that this is supposed to be supported. |
This comment has been minimized.
This comment has been minimized.
|
Any developments on this lately? |
pnkfelix commentedSep 5, 2013
•
edited
This issue is tracking RFC 195's inherent associated items
Original description follows.
When developing a type-parametric impl, I found myself writing code somewhat like this:
I cannot make a
typedefinition forHashMap<NT, ~[Prod<T,NT>]>outside of theimplbecause it then those free references toNTandTwould be unbound.And I cannot put a
typedefinition within the impl, even an impl for a struct such as this (it simply does not parse with the current grammar).(Being able to put type definitions within impls will probably arise naturally from #5033, when we get around to that. But that is nonetheless a separate issue from this: Associated Types (and Associated Items) are about enabling certain patterns for the user of a trait, while this ticket describes a convenience for the implementor of a struct.)