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 upTracking issue for trait aliases #41517
Comments
nagisa
added
B-unstable
B-RFC-approved
T-lang
labels
Apr 24, 2017
This comment has been minimized.
This comment has been minimized.
|
I think #24010 (allowing aliases to set associated types) should be mentioned here. |
bors
added a commit
that referenced
this issue
Jun 5, 2017
bors
added a commit
that referenced
this issue
Jun 19, 2017
bors
added a commit
that referenced
this issue
Jul 7, 2017
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
I'd like to take a crack at this (starting with parsing). |
This comment has been minimized.
This comment has been minimized.
|
I read the RFC and I saw a call out to Specifically, the "alias" needs to provide some additional associated types: See this snippet: https://gist.github.com/carllerche/76605b9f7c724a61a11224a36d29e023 Basically, you rarely want to just alias trait HttpService = Service<http::Request<Self::RequestBody>> {
type RequestBody;
}In other words, the trait alias introduces a new associated type. The reason why you can't do: |
This comment has been minimized.
This comment has been minimized.
phaazon
commented
Nov 3, 2017
Rarely? How do you define that? The syntax you suggest seems a bit complex to me and non-intuitive. I don’t get why we couldn’t make an exception in the way the “problem” shows up. Cannot we just hack around that rule you expressed? It’s not a “real trait”, it should be possible… right? |
This comment has been minimized.
This comment has been minimized.
|
@phaazon rarely with regards to the service trait. This was not a general statement for when you would want trait aliasing. Also, the syntax was not meant to be a real proposal. It was only to illustrate what I was talking about. |
This comment has been minimized.
This comment has been minimized.
phaazon
commented
Nov 3, 2017
|
I see. Cannot we just use free variables for that? Like, |
This comment has been minimized.
This comment has been minimized.
|
@phaazon I don't understand this proposal. |
bors
added a commit
that referenced
this issue
Dec 13, 2017
bors
added a commit
that referenced
this issue
Dec 13, 2017
bors
added a commit
that referenced
this issue
Dec 13, 2017
bors
added a commit
that referenced
this issue
Dec 14, 2017
bors
added a commit
that referenced
this issue
Dec 14, 2017
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Something I mentioned in the RFC: |
This comment has been minimized.
This comment has been minimized.
|
We can put a check for that in AST validation. However I suppose it could
be useful for code generation if there's no special case, I dunno.
…On Tue, Feb 27, 2018 at 12:48 PM, Clar Roʒe ***@***.***> wrote:
Something I mentioned in the RFC: trait Trait =; is accepted by the
proposed grammar and I think that this is a bit weird. Perhaps maybe the
proposed _ syntax might be more apt here, because I think that allowing
empty trait requirements is useful.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#41517 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n3HdG3ZOmbN2PKky7nFnx0WokY7Lks5tZD_fgaJpZM4NGzYc>
.
|
This comment has been minimized.
This comment has been minimized.
|
One other thing to note as a general weirdness is macro expansions involving trait bounds. Currently, But then, is |
This comment has been minimized.
This comment has been minimized.
|
Empty bound lists (and other lists) are accepted in other contexts as well, e.g. |
This comment has been minimized.
This comment has been minimized.
|
I think it makes sense being accepted, although I wonder if making it the canonical way to do so outside of macros is the right way to go. We already have been pushing toward |
crlf0710
referenced this issue
Dec 14, 2018
Closed
ASK: type aliasing for returning `impl Trait` #56801
phil-opp
referenced this issue
Jan 26, 2019
Merged
Store singleton directly in I2C type to take ownership #76
This comment has been minimized.
This comment has been minimized.
|
Not sure if it is a known bug or not, but if you have a |
This comment has been minimized.
This comment has been minimized.
|
@ricochet1k Best to file as an issue on the rustfmt repo. Thanks! https://github.com/rust-lang/rustfmt/issues |
mooli
referenced this issue
Feb 11, 2019
Closed
rustfmt incorrectly strips `pub` from the front of trait aliases #3340
This comment has been minimized.
This comment has been minimized.
|
@ricochet1k @alexreg Thanks. On a side note, currently putting #![feature(trait_alias)]
auto trait Foo = Iterator<Item = u8>;
fn main() {}Is this intentional? If not, could we change this to a syntax error? FWIW putting |
This comment has been minimized.
This comment has been minimized.
|
@topecongiro Definitely an oversight. Thanks for the report. |
Centril
added a commit
to Centril/rust
that referenced
this issue
Feb 13, 2019
Centril
added a commit
to Centril/rust
that referenced
this issue
Feb 13, 2019
seanmonstar
referenced this issue
Mar 8, 2019
Closed
ICE with trait alias when alias refers to bare Self #59029
This comment has been minimized.
This comment has been minimized.
|
Hit another ICE today reported in #59029 |
This comment has been minimized.
This comment has been minimized.
davidbarsky
commented
Apr 2, 2019
alexreg
referenced this issue
Apr 2, 2019
Merged
resolve: collect trait aliases along with traits #59166
This comment has been minimized.
This comment has been minimized.
|
@davidbarsky I don't think it's going to get stabilised quite yet... there are some outstanding questions about whether we want to generalise this system (mainly by other individuals). |
This comment has been minimized.
This comment has been minimized.
davidbarsky
commented
Apr 2, 2019
|
@alexreg Understood—when you say “we want to generalize this system” are you referring to the above discussion on higher-rank type bounds or something else? (Apologies if I'm having you restate things that were clearly state earlier—I'm just entering this discussion for the first time and I didn't see anything in the above conversation about generalization beyond the HRTB-related discussion.) |
This comment has been minimized.
This comment has been minimized.
|
@davidbarsky: I'm not sure whereabouts this is recorded, but there has been some concern about whether "bounds aliases" (i.e. the current behaviour for "trait aliases") or "constraint aliases" (where you explicitly parameterise over the type being bound) are the most useful notion of alias. For example, with trait aliases, you cannot encode type equality constraints (see #20041, for example). As a separate, but related issue, there are learnability concerns about the naming convention. Namely, there are three related, but distinct concepts that could be considered "trait aliases":
These questions at least will need to be resolved before stabilisation. |
This comment has been minimized.
This comment has been minimized.
|
A 4th question is how this all integrates with "trait generics" and "associated traits" as well. My goal is to ensure that we end up with flexible & a coherent system for all of this. However, it is difficult to test this out without having associated traits & trait generics on nightly. Thus, I think stabilization of this should wait on that. |
This comment has been minimized.
This comment has been minimized.
|
It'd be helpful to add steps of what's blocking this to the top comment, and if possible, links to something describing what they are. For instance, this is the first I've read about "associated traits". Are "trait generics" meant to describe generics on associated types (GATs)? |
This comment has been minimized.
This comment has been minimized.
|
@seanmonstar e.g. |
This comment has been minimized.
This comment has been minimized.
|
@Centril woah! Very interesting idea... Looking through the original trait aliases RFC, I see |
This comment has been minimized.
This comment has been minimized.
|
@seanmonstar I just read through all of the comments in the RFC; |
This comment has been minimized.
This comment has been minimized.
Ah, that's too bad. I'm a fan of keeping tracking issues to status updates, so would it make sense to move discussion of whether something like |
This comment has been minimized.
This comment has been minimized.
|
@seanmonstar I don't think I have the time for such a discussion but go ahead if you want. My view is that there would need to be really good arguments why we should stabilize this before associated traits & such are even in nightly. Given that trait aliases are mostly a matter of ergonomics it all seems like quite a risky endeavor to me. As such I'm at least for now not inclined to put trait aliases on a clear path to stabilization. |
This comment has been minimized.
This comment has been minimized.
|
@Centril Trait parameters and associated traits sound potentially interesting but this is the first I hear of them. Are they on any roadmap? Is there consensus in the lang team that they should block existing features (with an accepted RFC and an implementation) like trait aliases, or is that your personal opinion? |
This comment has been minimized.
This comment has been minimized.
Nope.
Yep. |
This comment has been minimized.
This comment has been minimized.
|
I think the stabilisation process includes consideration of interaction with possible future features, if insufficiently evaluated during the RFC process (and, indeed, I think some of these concerns were not realised until after the RFC was accepted). Besides that, though, there are issues with trait aliases that have been raised in the existing discussion (and which turn out to be relevant to @Centril's concerns). |
withoutboats commentedApr 24, 2017
•
edited by Centril
This is a tracking issue for trait aliases (rust-lang/rfcs#1733).
TODO:
unexpected definition: TraitAliasINCOHERENT_AUTO_TRAIT_OBJECTSfuture-compatibility warning (superseded by #56481)Unresolved questions: