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 RFC 2515, "Permit impl Trait in type aliases" #63063

Open
5 of 8 tasks
Centril opened this issue Jul 28, 2019 · 167 comments
Open
5 of 8 tasks

Tracking issue for RFC 2515, "Permit impl Trait in type aliases" #63063

Centril opened this issue Jul 28, 2019 · 167 comments
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` needs-fcp This change is insta-stable, so needs a completed FCP to proceed. requires-nightly This issue requires a nightly compiler in some way. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@Centril
Copy link
Contributor

Centril commented Jul 28, 2019

This is a tracking issue for the RFC "Permit impl Trait in type aliases" (rust-lang/rfcs#2515) which is implemented under the following #![feature(..)] gates:

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also uses as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved questions

  • Exactly what should count as "defining uses" for opaque types?

    • Should the set of "defining uses" for an opaque type in an impl be just items of the impl, or include nested items within the impl functions etc? (see here for example)
    • should return-position-impl-trait also start allowing nested functions and closures to affect the hidden type? -- independent question to be answered separately by the lang team. Would simplify compiler.
  • can we come up with consistent rules when cross-usage type inference can happen?

    • fn foo(x: bool) -> impl Debug {
          if x { return vec!["hi"] }
          Default::default()
      }
      compiles on stable, even though there is no obvious type for Default::default() to produce a value of. We combine all return sites though and compute a shared type across them, so we'll figure out a Vec<&'static str>
    • impl Foo can be used for associated types that expect a type that implements Bar, even if Foo and Bar are entirely unrelated. The hidden type must satisfy both. See https://github.com/rust-lang/rust/pull/99860/files for examples.
  • impl traits in consts through const fns are allowed but shouldn't be: impl traits in consts through const fns are allowed but shouldn't #87277

@Centril Centril added B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-lang Relevant to the language team, which will review and decide on the PR/issue. A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. labels Jul 28, 2019
@Centril Centril added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. and removed requires-nightly This issue requires a nightly compiler in some way. labels Jul 28, 2019
@alexreg

This comment has been minimized.

@varkor

This comment has been minimized.

Centril added a commit to Centril/rust that referenced this issue Jul 29, 2019
@Nemo157

This comment has been minimized.

bors added a commit that referenced this issue Aug 3, 2019
Change opaque type syntax from `existential type` to type alias `impl Trait`

This implements a new feature gate `type_alias_impl_trait` (this is slightly different from the originally proposed feature name, but matches what has been used in discussion since), deprecating the old `existential_types` feature.

The syntax for opaque types has been changed. In addition, the "existential" terminology has been replaced with "opaque", as per previous discussion and the RFC.

This makes partial progress towards implementing #63063.

r? @Centril
@crlf0710

This comment has been minimized.

@Centril
Copy link
Contributor Author

Centril commented Aug 3, 2019

In #63092, landed on 2019-07-28, written by @Centril and reviewed by @varkor, the tracking issue for existential_type was adjusted to this one.

In #63096, landed on 2019-07-29, written by @Centril and reviewed by @varkor, 3 ICEs were closed with reproducer tests added.

In #63158, landed on 2019-07-31, written by @JohnTitor and reviewed by @Centril, 1 ICE was closed with a reproducer test added.

In #63180, landed on 2019-08-03, written by @varkor and reviewed by @Centril, the syntax was changed to type Foo = impl Bar; through a temporary hack in the parser. @varkor will follow up to remove that hack. The new feature gate name is type_alias_impl_trait and the old one existential_type has been removed.

In rust-lang/rustc-dev-guide#402, landed on 2019-08-29, written by @varkor and reviewed by @mark-i-m, @Arnavion, and @spastorino, the rustc guide description was updated.

@GlenDC
Copy link
Contributor

GlenDC commented Nov 26, 2023

FYI for now I make use of async fn traits in a fork of Tokio's tower (https://github.com/plabayo/tower-async). However it turns out there are a lot of usability concerns. First of all the stabilisation of the async fn trait features in this and the upcoming rust versions mean not much given that for now there is still a need for the RTN (return type) notation for our use cases. On top of that there is no immediate plans to support dynamic dispatch for async fn traits. This means boxed services are also out (without a lot of awkward work arounds). A last ergonomic issue is that the resolver cannot always infer auto trait bounds correctly given awkward to impossible situations.

As such, to summarise, a lot of ergonomic problems.

In contrast, while syncing back with the tower team to see what they think of tower-async and what future direction we can take (breaking change) to easier (and without boxing) support opaque futures, the impl Trait notation in associated types came up. I played with this idea and described its results at tower-rs/tower#753 (comment), with playground https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=11b0998956ab3ac077ec54a683d5c425.

The feature and RFC tracked in this issue works beautifully. It has none of the ergonomic pitfalls, requires no breaking changes in existing future code, in general plays very nice with Rust and the way it handles async code through futures. It just works. And thus dynamic dispatch is also possible, given we work with non async fn code here.

I discover this nightly feature late, but I feel that this feature (impl Trait as associated types in traits) should have been the feature being stabilised in the async story over others. As it really plays well with existing code and just works. Love it. To the future and beyond!

@rakshith-ravi
Copy link
Contributor

rakshith-ravi commented Nov 28, 2023

Adding to @GlenDC's point - given that we already have AFIT, at the end of the day, AFIT anyway desugars to some form of impl_trait_in_assoc_type. So the implementation shouldn't be too different. I would strongly suggest stabilizing it since it would make using tower much easier to use un-boxed without having to change existing code

@Finomnis
Copy link
Contributor

Finomnis commented Dec 6, 2023

How far is this feature from stabilization? I'd love to see RTIC 2 on stable Rust :)

I'm asking because I don't see any major blockers in the task list, and want to ping so people don't forget about this feature :)

@h33p
Copy link

h33p commented Dec 7, 2023

For people wondering, I asked on Zulip, and I was was told there are quite a few design blockers to be done. So no, it's not yet ready.

Related issues: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AF-type_alias_impl_trait++label%3AT-lang

@GlenDC
Copy link
Contributor

GlenDC commented Dec 7, 2023

Thanks for the updates. And honestly no rush, it takes as long as you need. I can wait.
My point was more that I feel that this RFC is a lot more useful then features that are about to be stable.
This due to mostly ergonomics, compatibility with existing code bases and the fact that for many real world scenarios there is still a need for awkward nightly features in order to use the soon to be stable features.

That said, take your time, thanks for everything and take care.

@vojtechkral
Copy link
Contributor

vojtechkral commented Dec 13, 2023

@RalfJung
Copy link
Member

RalfJung commented Dec 13, 2023

The impl Trait syntax is already overloaded for at least two semantically very different usecases

That's not true, impl Trait is always an existential type. Some people make a difference between argument position and return position but that's really not necessary.

(Discussing this in detail is off-topic here, I just felt it was important to point out this (common) misconception. :) Zulip or https://users.rust-lang.org/ would be a better place to discuss this.)

@vojtechkral
Copy link
Contributor

Ok, I removed that part.

brainstorm added a commit to brainstorm/embassy-as5600 that referenced this issue Mar 24, 2024
$ cargo build
  Downloaded as5600 v0.6.0
  Downloaded 1 crate (14.1 KB) in 0.85s
   Compiling autocfg v1.1.0
   Compiling num-derive v0.4.2
   Compiling nb v0.1.3
   Compiling embedded-hal v0.2.7
   Compiling num-traits v0.2.18
   Compiling as5600 v0.6.0
   Compiling embassy-avr-as5600-encoder v0.1.0 (/home/rvalls/dev/personal/embassy-avr-as5600-encoder)
error[E0658]: `impl Trait` in associated types is unstable
 --> src/main.rs:8:1
  |
8 | #[embassy_executor::main]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #63063 <rust-lang/rust#63063> for more information
  = help: add `#![feature(impl_trait_in_assoc_type)]` to the crate attributes to enable
  = note: this compiler was built on 2024-03-23; consider upgrading it if it is out of date
  = note: this error originates in the attribute macro `::embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0658`.
error: could not compile `embassy-avr-as5600-encoder` (bin "embassy-avr-as5600-encoder") due to 1 previous error
@Mark-Simulacrum Mark-Simulacrum removed the relnotes Marks issues that should be documented in the release notes of the next release. label Aug 25, 2024
inorick pushed a commit to eclipse-heimlig/heimlig that referenced this issue Aug 27, 2024
The move from unstable dependencies pulled directly from Github to the
crates.io version required several changes:

- Update of other dependencies to match the expectations of the crates
.io versions.
- Use `impl_trait_in_assoc_type` instead of `type_alias_impl_trait`
feature. See rust-lang/rust#63063
- Remove unstable features of dependencies.
inorick pushed a commit to eclipse-heimlig/heimlig that referenced this issue Aug 27, 2024
The move from unstable dependencies pulled directly from Github to the
crates.io version required several changes:

- Update of other dependencies to match the expectations of the crates
.io versions.
- Use `impl_trait_in_assoc_type` instead of `type_alias_impl_trait`
feature. See rust-lang/rust#63063
- Remove unstable features of dependencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` needs-fcp This change is insta-stable, so needs a completed FCP to proceed. requires-nightly This issue requires a nightly compiler in some way. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
Development

No branches or pull requests