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
1 of 6 tasks
Centril opened this issue Jul 28, 2019 · 50 comments
Open
1 of 6 tasks

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

Centril opened this issue Jul 28, 2019 · 50 comments

Comments

@Centril
Copy link
Contributor

@Centril Centril commented Jul 28, 2019

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

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? E.g. currently statics and consts are not counted, but rust-lang/rfcs#2071 specifies that they should be. #77898
    • 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)
  • impl traits in consts through const fns are allowed but shouldn't #87277
@alexreg

This comment has been hidden.

@varkor

This comment has been hidden.

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

This comment has been hidden.

bors added a commit that referenced this issue Aug 2, 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
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 was marked as off-topic.

@Centril
Copy link
Contributor Author

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

Loading

@CAD97
Copy link
Contributor

@CAD97 CAD97 commented Mar 21, 2021

One random worry I thought of:

There's currently two ways to effectively seal a trait:

trait A {
    // requires naming an unnameable type
    fn sealed(_: Voldemort);
}

// requires implementing an unnameable trait
trait B: Voldemort {
}

The latter still works in the face of type = impl Trait;, but the former no longer prevents implementation of the trait once you can use TAIT to name the parameter type.

This seems like the correct behavior for TAIT, but we should make sure to communicate that the former method for pseudo-sealing the trait won't work once full TAIT is available.

Loading

@Nemo157
Copy link
Member

@Nemo157 Nemo157 commented Mar 21, 2021

@CAD97 do you have an example of how your trait A will be affected by TAIT? The type alias is treated as a different type to the concrete type it aliases, so even with extra public API to allow creating a TAIT of the Voldemort type it's not possible to implement the trait: playground.

Loading

@CAD97
Copy link
Contributor

@CAD97 CAD97 commented Mar 21, 2021

Ah, it seems there are two things in the way of this causing a problem.

  1. I assumed that use as a trait method argument would be enough to be a defining use (as it does limit it to be one type), and
  2. I assumed that a TAIT constrained in this fashion would be allowed to be used as the function argument.

It's a question of to whom exactly the TAIT is opaque. It's obviously not opaque to the defining usage(s). So long as trait method argument use isn't considered a defining use (and you can make an argument that it could be), and the TAIT's use in this position is always in the opaque region rather than the defining/transparent region, then TAIT won't break this method of pseudo-sealing traits.

Loading

github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Apr 8, 2021
=== stdout ===
=== stderr ===
error[E0658]: `impl Trait` in type aliases is unstable
 --> /home/runner/work/glacier/glacier/ices/83613.rs:3:19
  |
3 | type OpaqueType = impl OpaqueTrait;
  |                   ^^^^^^^^^^^^^^^^
  |
  = note: see issue #63063 <rust-lang/rust#63063> for more information
  = help: add `#![feature(min_type_alias_impl_trait)]` to the crate attributes to enable

error[E0601]: `main` function not found in crate `83613`
 --> /home/runner/work/glacier/glacier/ices/83613.rs:1:1
  |
1 | / trait OpaqueTrait {}
2 | | impl<T> OpaqueTrait for T {}
3 | | type OpaqueType = impl OpaqueTrait;
4 | | fn mk_opaque() -> OpaqueType {
... |
8 | | impl<T: Send> AnotherTrait for T {}
9 | | impl AnotherTrait for OpaqueType {}
  | |___________________________________^ consider adding a `main` function to `/home/runner/work/glacier/glacier/ices/83613.rs`

error[E0119]: conflicting implementations of trait `AnotherTrait` for type `impl OpaqueTrait`
 --> /home/runner/work/glacier/glacier/ices/83613.rs:9:1
  |
8 | impl<T: Send> AnotherTrait for T {}
  | -------------------------------- first implementation here
9 | impl AnotherTrait for OpaqueType {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `impl OpaqueTrait`

error: cannot implement trait on type alias impl trait
 --> /home/runner/work/glacier/glacier/ices/83613.rs:9:1
  |
9 | impl AnotherTrait for OpaqueType {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: type alias impl trait defined here
 --> /home/runner/work/glacier/glacier/ices/83613.rs:3:19
  |
3 | type OpaqueType = impl OpaqueTrait;
  |                   ^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0119, E0601, E0658.
For more information about an error, try `rustc --explain E0119`.
==============
darkwater added a commit to sinewave-ee/w5500 that referenced this issue Apr 16, 2021
@ibraheemdev
Copy link
Contributor

@ibraheemdev ibraheemdev commented May 10, 2021

Is there a list of known bugs, blocking min_type_alias_impl_trait from being stabilized? This feature means that literally hundreds of Box::pins can be removed from the async ecosystem, and writing low-level async code becomes waay more ergonomic as this also eliminates the need for many custom future types. Of course, without GATs they can't be completely eliminated, but this still represents a huge step forward towards real async fns in traits and I know that many of us are eagerly .awaiting it. The only unresolved question listed here is regarding defining uses, but I don't think that applies to the minimal feature gate .... @oli-obk is there a release that can be a reasonable target for min_type_alias_impl_trait landing on stable?

Loading

@WaffleLapkin
Copy link
Contributor

@WaffleLapkin WaffleLapkin commented May 10, 2021

@CAD97 note that with full TAIT you can name the type (it still doesn't allow you to implement the trait though):

type V = impl Any;

fn setv<T: A>() {
    fn teq<T>(_: &T, _: &T) {}

    let x = todo!();
    let y = todo!();
    teq(&x, &y);
    
    T::sealed(x);
    
    let _f = move || -> V { y };
}

(playground)

Loading

@oli-obk
Copy link
Contributor

@oli-obk oli-obk commented May 10, 2021

A bit unorganized: https://hackmd.io/tB3V8MP5S66zHIWTUdRvQw but it holds all current info I think. I also created a github label for Tait, but idk how complete the list of tagged things is. I won't work on any of this until July though

Loading

@ibraheemdev
Copy link
Contributor

@ibraheemdev ibraheemdev commented May 10, 2021

@oli-obk and you'll be done after about 2 weeks in July right? 😛 Thanks for the link, and thanks for all of your amazing work on this! I look forward to seeing it stabilize soon.

Loading

github-actions bot pushed a commit to rust-lang/glacier that referenced this issue May 12, 2021
=== stdout ===
=== stderr ===
error[E0557]: feature has been removed
 --> /home/runner/work/glacier/glacier/ices/53092.rs:1:12
  |
1 | #![feature(const_fn)]
  |            ^^^^^^^^ feature has been removed
  |
  = note: split into finer-grained feature gates

warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/53092.rs:3:12
  |
3 | #![feature(impl_trait_in_bindings)]
  |            ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #63065 <rust-lang/rust#63065> for more information

warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/53092.rs:5:12
  |
5 | #![feature(type_alias_impl_trait)]
  |            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #63063 <rust-lang/rust#63063> for more information

error: aborting due to previous error; 2 warnings emitted

For more information about this error, try `rustc --explain E0557`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jun 18, 2021
=== stdout ===
=== stderr ===
warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/78450.rs:2:12
  |
2 | #![feature(type_alias_impl_trait)]
  |            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #63063 <rust-lang/rust#63063> for more information

warning: 1 warning emitted

==============
JohnTitor pushed a commit to rust-lang/glacier that referenced this issue Jun 18, 2021
=== stdout ===
=== stderr ===
warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/78450.rs:2:12
  |
2 | #![feature(type_alias_impl_trait)]
  |            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #63063 <rust-lang/rust#63063> for more information

warning: 1 warning emitted

==============

Co-authored-by: rustbot <rustbot@users.noreply.github.com>
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jul 17, 2021
=== stdout ===
=== stderr ===
error[E0658]: `impl Trait` in type aliases is unstable
 --> /home/runner/work/glacier/glacier/ices/77179.rs:3:19
  |
3 | type Pointer<T> = impl std::ops::Deref<Target=T>;
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #63063 <rust-lang/rust#63063> for more information
  = help: add `#![feature(min_type_alias_impl_trait)]` to the crate attributes to enable

warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/77179.rs:1:12
  |
1 | #![feature(type_alias_impl_trait)]
  |            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #63063 <rust-lang/rust#63063> for more information

error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types
 --> /home/runner/work/glacier/glacier/ices/77179.rs:5:22
  |
5 | fn test() -> Pointer<_> {
  |              --------^-
  |              |       |
  |              |       not allowed in type signatures
  |              help: replace with the correct return type: `Box<i32>`

error: aborting due to 2 previous errors; 1 warning emitted

Some errors have detailed explanations: E0121, E0658.
For more information about an error, try `rustc --explain E0121`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jul 21, 2021
=== stdout ===
=== stderr ===
error[E0557]: feature has been removed
 --> /home/runner/work/glacier/glacier/ices/53092.rs:1:12
  |
1 | #![feature(impl_trait_in_bindings)]
  |            ^^^^^^^^^^^^^^^^^^^^^^ feature has been removed
  |
  = note: the implementation was not maintainable, the feature may get reintroduced once the current refactorings are done

warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/53092.rs:3:12
  |
3 | #![feature(type_alias_impl_trait)]
  |            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #63063 <rust-lang/rust#63063> for more information

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0557`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jul 21, 2021
=== stdout ===
=== stderr ===
error[E0658]: `impl Trait` in type aliases is unstable
 --> /home/runner/work/glacier/glacier/ices/77179.rs:3:19
  |
3 | type Pointer<T> = impl std::ops::Deref<Target=T>;
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #63063 <rust-lang/rust#63063> for more information
  = help: add `#![feature(min_type_alias_impl_trait)]` to the crate attributes to enable

warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/77179.rs:1:12
  |
1 | #![feature(type_alias_impl_trait)]
  |            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #63063 <rust-lang/rust#63063> for more information

error[E0308]: mismatched types
 --> /home/runner/work/glacier/glacier/ices/77179.rs:6:25
  |
3 | type Pointer<T> = impl std::ops::Deref<Target=T>;
  |                   ------------------------------ the expected opaque type
...
6 |     let p: Pointer<_> = Box::new(1);
  |            ----------   ^^^^^^^^^^^ expected opaque type, found struct `Box`
  |            |
  |            expected due to this
  |
  = note: expected opaque type `impl Deref`
                  found struct `Box<{integer}>`

error: could not find defining uses
 --> /home/runner/work/glacier/glacier/ices/77179.rs:3:19
  |
3 | type Pointer<T> = impl std::ops::Deref<Target=T>;
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors; 1 warning emitted

Some errors have detailed explanations: E0308, E0658.
For more information about an error, try `rustc --explain E0308`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jul 24, 2021
=== stdout ===
=== stderr ===
warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/74280.rs:2:12
  |
2 | #![feature(type_alias_impl_trait)]
  |            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #63063 <rust-lang/rust#63063> for more information

error: concrete type differs from previous defining opaque type use
 --> /home/runner/work/glacier/glacier/ices/74280.rs:7:13
  |
7 |     let y = || -> Test { () };
  |             ^^^^^^^^^^^^^^^^^ expected `i32`, got `()`
  |
note: previous use here
 --> /home/runner/work/glacier/glacier/ices/74280.rs:6:1
  |
6 | fn test() -> Test {
  | ^^^^^^^^^^^^^^^^^

error: aborting due to previous error; 1 warning emitted

==============
dtolnay added a commit to dtolnay/async-trait that referenced this issue Jul 29, 2021
As of nightly-2021-07-29:

    error[E0557]: feature has been removed
     --> tests/test.rs:3:33
      |
    3 |     feature(min_specialization, min_type_alias_impl_trait)
      |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^ feature has been removed
      |
      = note: removed in favor of full type_alias_impl_trait

    error[E0658]: `impl Trait` in type aliases is unstable
        --> tests/test.rs:1299:22
         |
    1299 |         type Assoc = impl Sized;
         |                      ^^^^^^^^^^
         |
         = note: see issue #63063 <rust-lang/rust#63063> for more information
         = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jul 29, 2021
=== stdout ===
=== stderr ===
error[E0557]: feature has been removed
 --> /home/runner/work/glacier/glacier/ices/53092.rs:1:12
  |
1 | #![feature(min_type_alias_impl_trait)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^ feature has been removed
  |
  = note: removed in favor of full type_alias_impl_trait

error[E0658]: `impl Trait` in type aliases is unstable
 --> /home/runner/work/glacier/glacier/ices/53092.rs:4:18
  |
4 | type Bug<T, U> = impl Fn(T) -> U + Copy;
  |                  ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #63063 <rust-lang/rust#63063> for more information
  = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0557, E0658.
For more information about an error, try `rustc --explain E0557`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Oct 19, 2021
=== stdout ===
=== stderr ===
error: bounds on `type`s in this context have no effect
 --> /home/runner/work/glacier/glacier/ices/83479.rs:1:24
  |
1 |   type PairCoupledTypes: Trait<
  |  ________________________^
2 | |     [u32; {
3 | |         static FOO: usize;
4 | |     }],
5 | | > = impl Trait<
  | |_^

error: free static item without body
 --> /home/runner/work/glacier/glacier/ices/83479.rs:3:9
  |
3 |         static FOO: usize;
  |         ^^^^^^^^^^^^^^^^^-
  |                          |
  |                          help: provide a definition for the static: `= <expr>;`

error: free static item without body
 --> /home/runner/work/glacier/glacier/ices/83479.rs:7:9
  |
7 |         static FOO: usize;
  |         ^^^^^^^^^^^^^^^^^-
  |                          |
  |                          help: provide a definition for the static: `= <expr>;`

error[E0405]: cannot find trait `Trait` in this scope
 --> /home/runner/work/glacier/glacier/ices/83479.rs:1:24
  |
1 | type PairCoupledTypes: Trait<
  |                        ^^^^^ not found in this scope

error[E0405]: cannot find trait `Trait` in this scope
 --> /home/runner/work/glacier/glacier/ices/83479.rs:5:10
  |
5 | > = impl Trait<
  |          ^^^^^ not found in this scope

error[E0658]: `impl Trait` in type aliases is unstable
 --> /home/runner/work/glacier/glacier/ices/83479.rs:5:5
  |
5 |   > = impl Trait<
  |  _____^
6 | |     [u32; {
7 | |         static FOO: usize;
8 | |     }],
9 | | >;
  | |_^
  |
  = note: see issue #63063 <rust-lang/rust#63063> for more information
  = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable

error[E0601]: `main` function not found in crate `83479`
 --> /home/runner/work/glacier/glacier/ices/83479.rs:1:1
  |
1 | / type PairCoupledTypes: Trait<
2 | |     [u32; {
3 | |         static FOO: usize;
4 | |     }],
... |
8 | |     }],
9 | | >;
  | |__^ consider adding a `main` function to `/home/runner/work/glacier/glacier/ices/83479.rs`

error: aborting due to 7 previous errors

Some errors have detailed explanations: E0405, E0601, E0658.
For more information about an error, try `rustc --explain E0405`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Oct 20, 2021
=== stdout ===
=== stderr ===
error[E0557]: feature has been removed
 --> /home/runner/work/glacier/glacier/ices/87258.rs:1:12
  |
1 | #![feature(min_type_alias_impl_trait)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^ feature has been removed
  |
  = note: removed in favor of full type_alias_impl_trait

error[E0658]: `impl Trait` in type aliases is unstable
  --> /home/runner/work/glacier/glacier/ices/87258.rs:27:30
   |
27 |     type FooFuture<'a, 'b> = impl Future<Output = Result<(), Self::Error>>;
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #63063 <rust-lang/rust#63063> for more information
   = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable

error[E0601]: `main` function not found in crate `87258`
  --> /home/runner/work/glacier/glacier/ices/87258.rs:1:1
   |
1  | / #![feature(min_type_alias_impl_trait)]
2  | | #![feature(generic_associated_types)]
3  | | use std::future::Future;
4  | |
...  |
35 | |     }
36 | | }
   | |_^ consider adding a `main` function to `/home/runner/work/glacier/glacier/ices/87258.rs`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0557, E0601, E0658.
For more information about an error, try `rustc --explain E0557`.
==============
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet