Skip to content
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 trait aliases #41517

Open
withoutboats opened this Issue Apr 24, 2017 · 67 comments

Comments

Projects
None yet
@withoutboats
Copy link
Contributor

withoutboats commented Apr 24, 2017

This is a tracking issue for trait aliases (rust-lang/rfcs#1733).

TODO:

  • Implement: tracking issue
  • #56485 — Bringing a trait alias into scope doesn't allow calling methods from its component traits (done in #59166)
  • #56488 — ICE with trait aliases and use items
  • #57023 — Nightly Type Alias Compiler panic unexpected definition: TraitAlias
  • #57059INCOHERENT_AUTO_TRAIT_OBJECTS future-compatibility warning (superseded by #56481)
  • Document
  • Stabilize

Unresolved questions:

  • Are bounds on other input types than the receiver enforced or implied?
@durka

This comment has been minimized.

Copy link
Contributor

durka commented May 7, 2017

I think #24010 (allowing aliases to set associated types) should be mentioned here.

bors added a commit that referenced this issue Jun 5, 2017

Auto merge of #42125 - petrochenkov:privty, r=<try>
Check types for privacy

This PR implements late post factum checking of type privacy, as opposed to early preventive "private-in-public" checking.
This will allow to turn private-in-public checks into a lint and make them more heuristic-based, and more aligned with what people may expect (e.g. reachability-based behavior).

Types are privacy-checked if they are written explicitly, and also if they are inferred as expression or pattern types.
This PR checks "semantic" types and does it unhygienically, this significantly restricts what macros 2.0 (as implemented in #40847) can do (sorry @jseyfried) - they still can use private *names*, but can't use private *types*.
This is the most conservative solution, but hopefully it's temporary and can be relaxed in the future, probably using macro contexts of expression/pattern spans.

Traits are also checked in preparation for [trait aliases](#41517), which will be able to leak private traits, and macros 2.0 which will be able to leak pretty much anything.

This is a [breaking-change], but the code that is not contrived and can be broken by this patch should be guarded by `private_in_public` lint. [Previous crater run](#34537 (comment)) discovered a few abandoned crates that weren't updated since `private_in_public` has been introduced in 2015.

cc #34537 https://internals.rust-lang.org/t/lang-team-minutes-private-in-public-rules/4504
Fixes #30476
Fixes #33479

cc @nikomatsakis
r? @eddyb

bors added a commit that referenced this issue Jun 19, 2017

Auto merge of #42125 - petrochenkov:privty, r=alexcrichton
Check types for privacy

This PR implements late post factum checking of type privacy, as opposed to early preventive "private-in-public" checking.
This will allow to turn private-in-public checks into a lint and make them more heuristic-based, and more aligned with what people may expect (e.g. reachability-based behavior).

Types are privacy-checked if they are written explicitly, and also if they are inferred as expression or pattern types.
This PR checks "semantic" types and does it unhygienically, this significantly restricts what macros 2.0 (as implemented in #40847) can do (sorry @jseyfried) - they still can use private *names*, but can't use private *types*.
This is the most conservative solution, but hopefully it's temporary and can be relaxed in the future, probably using macro contexts of expression/pattern spans.

Traits are also checked in preparation for [trait aliases](#41517), which will be able to leak private traits, and macros 2.0 which will be able to leak pretty much anything.

This is a [breaking-change], but the code that is not contrived and can be broken by this patch should be guarded by `private_in_public` lint. [Previous crater run](#34537 (comment)) discovered a few abandoned crates that weren't updated since `private_in_public` has been introduced in 2015.

cc #34537 https://internals.rust-lang.org/t/lang-team-minutes-private-in-public-rules/4504
Fixes #30476
Fixes #33479

cc @nikomatsakis
r? @eddyb

bors added a commit that referenced this issue Jul 7, 2017

Auto merge of #42125 - petrochenkov:privty, r=nikomatsakis
Check types for privacy

This PR implements late post factum checking of type privacy, as opposed to early preventive "private-in-public" checking.
This will allow to turn private-in-public checks into a lint and make them more heuristic-based, and more aligned with what people may expect (e.g. reachability-based behavior).

Types are privacy-checked if they are written explicitly, and also if they are inferred as expression or pattern types.
This PR checks "semantic" types and does it unhygienically, this significantly restricts what macros 2.0 (as implemented in #40847) can do (sorry @jseyfried) - they still can use private *names*, but can't use private *types*.
This is the most conservative solution, but hopefully it's temporary and can be relaxed in the future, probably using macro contexts of expression/pattern spans.

Traits are also checked in preparation for [trait aliases](#41517), which will be able to leak private traits, and macros 2.0 which will be able to leak pretty much anything.

This is a [breaking-change], but the code that is not contrived and can be broken by this patch should be guarded by `private_in_public` lint. [Previous crater run](#34537 (comment)) discovered a few abandoned crates that weren't updated since `private_in_public` has been introduced in 2015.

cc #34537 https://internals.rust-lang.org/t/lang-team-minutes-private-in-public-rules/4504
Fixes #30476
Fixes #33479

cc @nikomatsakis
r? @eddyb
@durka

This comment has been minimized.

Copy link
Contributor

durka commented Oct 2, 2017

I'd like to take a crack at this (starting with parsing).

@durka durka referenced this issue Oct 5, 2017

Merged

trait alias infrastructure #45047

7 of 10 tasks complete

@glaebhoerl glaebhoerl referenced this issue Oct 16, 2017

Open

Allocator traits and std::heap #32838

5 of 12 tasks complete
@carllerche

This comment has been minimized.

Copy link
Member

carllerche commented Nov 3, 2017

I read the RFC and I saw a call out to Service, but I am not sure if the RFC actually solves the Service problem.

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 HttpService to Service<Request = http::Request> You really want to do something like this (while making up syntax):

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: trait HttpService<B> = Service<http::Request<B>> is that then you end up getting into the "the type parameter B is not constrained by the impl trait, self type, or predicates" problem.

@phaazon

This comment has been minimized.

Copy link

phaazon commented Nov 3, 2017

Basically, you rarely want to just alias HttpService to Service<Request = http::Request>

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?

@carllerche

This comment has been minimized.

Copy link
Member

carllerche commented Nov 3, 2017

@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.

@phaazon

This comment has been minimized.

Copy link

phaazon commented Nov 3, 2017

I see. Cannot we just use free variables for that? Like, Service<Request = http::Request> implies the free variable used in http::request<_>?

@carllerche

This comment has been minimized.

Copy link
Member

carllerche commented Nov 3, 2017

@phaazon I don't understand this proposal.

bors added a commit that referenced this issue Dec 13, 2017

Auto merge of #45047 - durka:trait-alias, r=petrochenkov
trait alias infrastructure

This will be an implementation of trait aliases (RFC 1733, #41517).

Progress so far:

- [x] Feature gate
- [x] Add to parser
  - [x] `where` clauses
    - [x] prohibit LHS type parameter bounds via AST validation #45047 (comment)
- [x] Add to AST and HIR
  - [x] make a separate PathSource for trait alias contexts #45047 (comment)
- [x] Stub out enough of typeck and resolve to just barely not ICE

Postponed:

- [ ] Actually implement the alias part
- [ ] #21903
- [ ] #24010

I need some pointers on where to start with that last one. The test currently does this:

```
error[E0283]: type annotations required: cannot resolve `_: CD`
  --> src/test/run-pass/trait-alias.rs:34:16
   |
34 |     let both = foo();
   |                ^^^
   |
   = note: required by `foo`
```

bors added a commit that referenced this issue Dec 13, 2017

Auto merge of #45047 - durka:trait-alias, r=petrochenkov
trait alias infrastructure

This will be an implementation of trait aliases (RFC 1733, #41517).

Progress so far:

- [x] Feature gate
- [x] Add to parser
  - [x] `where` clauses
    - [x] prohibit LHS type parameter bounds via AST validation #45047 (comment)
- [x] Add to AST and HIR
  - [x] make a separate PathSource for trait alias contexts #45047 (comment)
- [x] Stub out enough of typeck and resolve to just barely not ICE

Postponed:

- [ ] Actually implement the alias part
- [ ] #21903
- [ ] #24010

I need some pointers on where to start with that last one. The test currently does this:

```
error[E0283]: type annotations required: cannot resolve `_: CD`
  --> src/test/run-pass/trait-alias.rs:34:16
   |
34 |     let both = foo();
   |                ^^^
   |
   = note: required by `foo`
```

bors added a commit that referenced this issue Dec 13, 2017

Auto merge of #45047 - durka:trait-alias, r=petrochenkov
trait alias infrastructure

This will be an implementation of trait aliases (RFC 1733, #41517).

Progress so far:

- [x] Feature gate
- [x] Add to parser
  - [x] `where` clauses
    - [x] prohibit LHS type parameter bounds via AST validation #45047 (comment)
- [x] Add to AST and HIR
  - [x] make a separate PathSource for trait alias contexts #45047 (comment)
- [x] Stub out enough of typeck and resolve to just barely not ICE

Postponed:

- [ ] Actually implement the alias part
- [ ] #21903
- [ ] #24010

I need some pointers on where to start with that last one. The test currently does this:

```
error[E0283]: type annotations required: cannot resolve `_: CD`
  --> src/test/run-pass/trait-alias.rs:34:16
   |
34 |     let both = foo();
   |                ^^^
   |
   = note: required by `foo`
```

bors added a commit that referenced this issue Dec 14, 2017

Auto merge of #45047 - durka:trait-alias, r=petrochenkov
trait alias infrastructure

This will be an implementation of trait aliases (RFC 1733, #41517).

Progress so far:

- [x] Feature gate
- [x] Add to parser
  - [x] `where` clauses
    - [x] prohibit LHS type parameter bounds via AST validation #45047 (comment)
- [x] Add to AST and HIR
  - [x] make a separate PathSource for trait alias contexts #45047 (comment)
- [x] Stub out enough of typeck and resolve to just barely not ICE

Postponed:

- [ ] Actually implement the alias part
- [ ] #21903
- [ ] #24010

I need some pointers on where to start with that last one. The test currently does this:

```
error[E0283]: type annotations required: cannot resolve `_: CD`
  --> src/test/run-pass/trait-alias.rs:34:16
   |
34 |     let both = foo();
   |                ^^^
   |
   = note: required by `foo`
```

bors added a commit that referenced this issue Dec 14, 2017

Auto merge of #45047 - durka:trait-alias, r=petrochenkov
trait alias infrastructure

This will be an implementation of trait aliases (RFC 1733, #41517).

Progress so far:

- [x] Feature gate
- [x] Add to parser
  - [x] `where` clauses
    - [x] prohibit LHS type parameter bounds via AST validation #45047 (comment)
- [x] Add to AST and HIR
  - [x] make a separate PathSource for trait alias contexts #45047 (comment)
- [x] Stub out enough of typeck and resolve to just barely not ICE

Postponed:

- [ ] Actually implement the alias part
- [ ] #21903
- [ ] #24010

I need some pointers on where to start with that last one. The test currently does this:

```
error[E0283]: type annotations required: cannot resolve `_: CD`
  --> src/test/run-pass/trait-alias.rs:34:16
   |
34 |     let both = foo();
   |                ^^^
   |
   = note: required by `foo`
```
@varkor

This comment has been minimized.

Copy link
Member

varkor commented Feb 21, 2018

@durka: how's the work on the follow-up to #45047 going?

@clarfon

This comment has been minimized.

Copy link
Contributor

clarfon commented Feb 27, 2018

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.

@durka

This comment has been minimized.

Copy link
Contributor

durka commented Feb 27, 2018

@clarfon

This comment has been minimized.

Copy link
Contributor

clarfon commented Feb 27, 2018

One other thing to note as a general weirdness is macro expansions involving trait bounds. Currently, fn thing<T:>() is valid syntax but perhaps fn thing<T: _>() should be the recommended version.

But then, is _ + Copy or something okay? I'm not sure. I would just suggest Any but that has different guarantees.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Feb 27, 2018

Empty bound lists (and other lists) are accepted in other contexts as well, e.g. fn f<T: /*nothing*/>() { ... }, so trait Trait = /*nothing*/; being accepted is more of a rule than an exception.

@clarfon

This comment has been minimized.

Copy link
Contributor

clarfon commented Feb 27, 2018

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 '_ for elided lifetimes in generics, for example.

@ricochet1k

This comment has been minimized.

Copy link
Contributor

ricochet1k commented Feb 1, 2019

Not sure if it is a known bug or not, but if you have a pub trait Asdf = Clone; or whatever, cargo fmt strips off the pub which can then cause errors about exposing a private Trait.

@alexreg

This comment has been minimized.

Copy link
Contributor

alexreg commented Feb 1, 2019

@ricochet1k Best to file as an issue on the rustfmt repo. Thanks! https://github.com/rust-lang/rustfmt/issues

@topecongiro

This comment has been minimized.

Copy link
Contributor

topecongiro commented Feb 12, 2019

@ricochet1k @alexreg Thanks.

On a side note, currently putting auto in front of a trait alias is allowed:

#![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 unsafe in front of a trait alias is a syntax error.

@alexreg

This comment has been minimized.

Copy link
Contributor

alexreg commented Feb 12, 2019

@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

@Ploppz Ploppz referenced this issue Feb 25, 2019

Closed

Generic rewrite #36

@SimonSapin SimonSapin referenced this issue Mar 7, 2019

Open

Tracking issue for RFC 1861: Extern types #43467

1 of 3 tasks complete
@seanmonstar

This comment has been minimized.

Copy link
Contributor

seanmonstar commented Mar 8, 2019

Hit another ICE today reported in #59029

@davidbarsky

This comment has been minimized.

Copy link

davidbarsky commented Apr 2, 2019

Since #59166 landed, is it possible to mark the second item #56485 as complete and begin the documentation/stabilization process?

@alexreg

This comment has been minimized.

Copy link
Contributor

alexreg commented Apr 2, 2019

@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).

@davidbarsky

This comment has been minimized.

Copy link

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.)

@varkor

This comment has been minimized.

Copy link
Member

varkor commented Apr 2, 2019

@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":

  • True trait aliases (which is technically not what the feature being tracked here is).
  • Bounds aliases (this feature).
  • Constraint aliases.

These questions at least will need to be resolved before stabilisation.

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Apr 2, 2019

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.

@seanmonstar

This comment has been minimized.

Copy link
Contributor

seanmonstar commented Apr 2, 2019

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)?

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Apr 2, 2019

@seanmonstar e.g. fn foo<trait T>(...), foo::<Ord + Eq> and trait A { trait B; }. See https://github.com/Centril/rfc-trait-parametric-polymorphism/ for more (very WIP).

@seanmonstar

This comment has been minimized.

Copy link
Contributor

seanmonstar commented Apr 3, 2019

@Centril woah! Very interesting idea...

Looking through the original trait aliases RFC, I see ContraintKinds listed as an alternative. Since it's listed, I assume it was discussed, and it didn't hold up the RFC merging. Has something come up since that reverts that decision?

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Apr 3, 2019

@seanmonstar I just read through all of the comments in the RFC; ConstraintKinds as in having trait X universal quantification and as an associated item was barely discussed. bound vs. trait was discussed partially; I'm not sure I agree entirely with the rationale. constraint Foo<T> was discussed but I think we need to actually test the limits of the system with associated traits and trait generics to gain confidence in the solution. IOW: we need more data with a fully implemented and coherent system.

@seanmonstar

This comment has been minimized.

Copy link
Contributor

seanmonstar commented Apr 3, 2019

ConstraintKinds as in having trait X universal quantification and as an associated item was barely discussed.

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 ConstraintKinds should block the progress here to something else? Like an IRLO thread or something?

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Apr 3, 2019

@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.

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Apr 3, 2019

@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?

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Apr 3, 2019

Are they on any roadmap?

Nope.

is that your personal opinion?

Yep.

@varkor

This comment has been minimized.

Copy link
Member

varkor commented Apr 3, 2019

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.