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

Enum variants can't be imported via type alias #123131

Open
pitdicker opened this issue Mar 27, 2024 · 2 comments
Open

Enum variants can't be imported via type alias #123131

pitdicker opened this issue Mar 27, 2024 · 2 comments
Labels
A-typesystem Area: The type system C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@pitdicker
Copy link
Contributor

In chrono 0.4.36 we renamed a LocalResult enum to MappedLocalTime, and added a type alias with the name LocalResult.
This turned out to be a breaking change because enum variants can't be imported through a type alias.

enum MappedLocalTime {
    Single,
    Ambiguous,
    None,
}

type LocalResult = MappedLocalTime;

use LocalResult::*;

Gives the error:

    Checking alias v0.1.0 (C:\Users\dicke\Documents\alias)
error[E0432]: unresolved import `LocalResult`
 --> src\main.rs:9:5
  |
9 | use LocalResult::*; // fails
  |     ^^^^^^^^^^^ `LocalResult` is a type alias, not a module

For more information about this error, try `rustc --explain E0432`.
error: could not compile `alias` (bin "alias") due to previous error

I expected the type alias to behave identical to the enum.

Maybe related to RFC 2338 Type alias enum variants.

@pitdicker pitdicker added the C-bug Category: This is a bug. label Mar 27, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 27, 2024
@djc
Copy link
Contributor

djc commented Mar 27, 2024

I expected the type alias to behave identical to the enum.

Maybe related to RFC 2338 Type alias enum variants.

As the author of that RFC, I would also have expected this, but of course the RFC doesn't specify explicitly. Tracking issue: #49683.

@jieyouxu jieyouxu added A-typesystem Area: The type system T-lang Relevant to the language team, which will review and decide on the PR/issue. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 28, 2024
@cuviper
Copy link
Member

cuviper commented Mar 29, 2024

If the type alias sets generic parameters, should that carry through?

use std::result::Result::Err;

// We need full args for `Result<T, E>`
return Err::<i32, &str>(...);
use std::io::Result::Err;

// Since `io::Result<T>` already sets `E = io::Error`, do we only need `T`?
return Err::<i32>(...);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants