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

Type alias can't access enum variants if the enum is a type parameter default #114736

Open
Aegrithas opened this issue Aug 11, 2023 · 1 comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@Aegrithas
Copy link

Given an enum and type alias like so:

type A<T = E> = T;

enum E {
    
    V
    
}

I would expect A::V, A::<>::V and possibly A::<_>::V to refer to E::V.

However, these all generate the same error message:

error[E0599]: no associated item named `V` found for type `_` in the current scope
 --> src/main.rs:2:25
  |
2 |     println!("{:?}", A::V);
  |                         ^ associated item not found in `_`

Note that specifying T explicitly (e.g. A::<E>::V) works as expected.

Meta

rustc --version --verbose:

rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-pc-windows-msvc
release: 1.71.1
LLVM version: 16.0.5

I also got the same behavior on stable, beta and nightly in the playground.

@Aegrithas Aegrithas added the C-bug Category: This is a bug. label Aug 11, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 11, 2023
@fmease
Copy link
Member

fmease commented Aug 11, 2023

Generic parameter defaults are not used as a fallback when type inference fails. This is a known limitation.
The feature default_type_parameter_fallback (tracking issue, RFC) has never been properly implemented and it has stalled.

Related / duplicate issues: #83687, #96300, #98931 (, #27336).

In your case, <A>::V would force the default type to be used (admittedly this is awkward).

@rustbot label -needs-triage T-compiler A-inference

@rustbot rustbot added A-inference Area: Type inference T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 11, 2023
@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants