Skip to content

Can't construct type alias for tuple struct #43209

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

Closed
philipc opened this issue Jul 13, 2017 · 1 comment
Closed

Can't construct type alias for tuple struct #43209

philipc opened this issue Jul 13, 2017 · 1 comment

Comments

@philipc
Copy link
Contributor

philipc commented Jul 13, 2017

The following code fails to compile, but it seems correct to me:

struct Foo(u32);
type Bar = Foo;

fn main() {
    let foo = Foo(1);
    let bar = Bar(2);
    // error[E0423]: expected function, found type alias `Bar`
}

One alternative is use Foo as Bar;, but that doesn't allow me to give a different doc comment for Bar.

#42601 is a closely related issue (or even the same).

Meta

rustc 1.18.0 (03fc9d6 2017-06-06)
binary: rustc
commit-hash: 03fc9d6
commit-date: 2017-06-06
host: x86_64-unknown-linux-gnu
release: 1.18.0
LLVM version: 3.9

@petrochenkov
Copy link
Contributor

This is a duplicate of several previously closed issues.

type Bar = Foo; is a type alias, it defines a name only in type namespace and doesn't know anything about the constructor function associated with Foo.

I don't think type can be changed to introduce names into value namespace now, so this issue is unlikely to be fixed as is (#42601 is a bit different because Self is reserved and currently unused in value namespace, so we can make it resolve to the constructor function when used in value context).

If we had fn aliases in addition to type aliases you could write something like fn Bar = Foo; to alias the constructor. For now fn Bar(arg: u32) -> Bar { Foo(arg) } can be used (possibly combined with type Bar = Foo; into a convenience macro).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants