Skip to content

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

Open
@pitdicker

Description

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

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Mar 27, 2024
djc

djc commented on Mar 27, 2024

@djc
Contributor

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.

added
T-langRelevant to the language team
S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Mar 28, 2024
cuviper

cuviper commented on Mar 29, 2024

@cuviper
Member

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>(...);
added
T-typesRelevant to the types team, which will review and decide on the PR/issue.
on Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-langRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cuviper@djc@pitdicker@fmease@jieyouxu

        Issue actions

          Enum variants can't be imported via type alias · Issue #123131 · rust-lang/rust