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

Impl trait in type aliases: defining use via struct #66980

Closed
dhardy opened this issue Dec 3, 2019 · 2 comments
Closed

Impl trait in type aliases: defining use via struct #66980

dhardy opened this issue Dec 3, 2019 · 2 comments
Labels
F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@dhardy
Copy link
Contributor

dhardy commented Dec 3, 2019

Sub-issue of #63063

It should be possible for the defining implementation of Type-Alias-Impl-Trait (aka TAIT) to be a struct usage:

#![feature(type_alias_impl_trait)]
type A = impl Drop;

struct S {
    a: A,
}

fn foo() -> S {
    S { a: Box::new(1) }
}

First issue: currently, non-defining uses of TAIT in the defining scope are not allowed; see this comment.

Second issue: defining usage via a struct field.

Related cases:

  • compound type aliases are already supported: type B = (A, ()); where A is TAIT (also applies to array types)
  • enum usages usually (when N>1) do not involve all variants and often do not involve all type-components, so extension to enum would only be possible in very limited circumstances: already supported for Option but not other enums
@Centril Centril added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Dec 3, 2019
@jackh726
Copy link
Member

jackh726 commented Feb 4, 2021

Current errors on master:

error[E0308]: mismatched types
 --> src/main.rs:9:12
  |
2 | type A = impl Drop;
  |          --------- the expected opaque type
...
9 |     S { a: Box::new(1) }
  |            ^^^^^^^^^^^ expected opaque type, found struct `Box`
  |
  = note: expected opaque type `impl Drop`
                  found struct `Box<{integer}>`

error: could not find defining uses
 --> src/main.rs:2:10
  |
2 | type A = impl Drop;
  |          ^^^^^^^^^

error: aborting due to 2 previous errors

@oli-obk
Copy link
Contributor

oli-obk commented Feb 19, 2021

This is a duplicate of #64445

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-lang Relevant to the language team, which will review and decide on the PR/issue.
Development

No branches or pull requests

4 participants