Skip to content

supplying generic args to variant and enum results in weird error #93993

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
lcnr opened this issue Feb 14, 2022 · 2 comments · Fixed by #134981
Closed

supplying generic args to variant and enum results in weird error #93993

lcnr opened this issue Feb 14, 2022 · 2 comments · Fixed by #134981
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Feb 14, 2022

fn main() {
    let x = Option::<u32>::Some::<u32>(3);
}

results in

[E0109]: type arguments are not allowed for this type
 --> src/main.rs:2:35
  |
2 |     let x = Option::<u32>::Some::<u32>(3);
  |                                   ^^^ type argument not allowed

this error is far from ideal. we ideally mention that variants may only have generic arguments if their enum doesn't have any. not sure what's the best wording here or how to best achieve this

@lcnr lcnr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 14, 2022
@estebank
Copy link
Contributor

At the very least the wording should be type arguments are not allowed for enum variants.

@compiler-errors
Copy link
Member

error[E0109]: type arguments are not allowed on tuple variant `Some`
 --> src/main.rs:2:35
  |
2 |     let x = Option::<u32>::Some::<u32>(3);
  |                            ----   ^^^ type argument not allowed
  |                            |
  |                            not allowed on tuple variant `Some`

estebank added a commit to estebank/rust that referenced this issue Dec 31, 2024
```
error[E0109]: type arguments are not allowed on tuple variant `TSVariant`
  --> $DIR/enum-variant-generic-args.rs:54:29
   |
LL |     TSVariant::<()>(());
   |     ---------   ^^ type argument not allowed
   |     |
   |     not allowed on tuple variant `TSVariant`
   |
   = note: type arguments are not allowed for enum variants; specify them on the enum itself
```

Fix rust-lang#93993.
estebank added a commit to estebank/rust that referenced this issue Dec 31, 2024
```
error[E0109]: type arguments are not allowed on tuple variant `TSVariant`
  --> $DIR/enum-variant-generic-args.rs:54:29
   |
LL |     TSVariant::<()>(());
   |     ---------   ^^ type argument not allowed
   |     |
   |     not allowed on tuple variant `TSVariant`
   |
   = note: type arguments are not allowed for enum variants; specify them on the enum itself
```

Fix rust-lang#93993.
estebank added a commit to estebank/rust that referenced this issue Jan 30, 2025
…variant

```
error[E0109]: type arguments are not allowed on tuple variant `TSVariant`
  --> $DIR/enum-variant-generic-args.rs:54:29
   |
LL |     Enum::<()>::TSVariant::<()>(());
   |                 ---------   ^^ type argument not allowed
   |                 |
   |                 not allowed on tuple variant `TSVariant`
   |
   = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other
help: remove the generics arguments from one of the path segments
   |
LL -     Enum::<()>::TSVariant::<()>(());
LL +     Enum::TSVariant::<()>(());
   |
LL -     Enum::<()>::TSVariant::<()>(());
LL +     Enum::<()>::TSVariant(());
   |
```

Fix rust-lang#93993.
estebank added a commit to estebank/rust that referenced this issue Feb 4, 2025
…variant

```
error[E0109]: type arguments are not allowed on enum `Enum` and tuple variant `TSVariant`
  --> $DIR/enum-variant-generic-args.rs:54:12
   |
LL |     Enum::<()>::TSVariant::<()>(());
   |     ----   ^^   ---------   ^^ type argument not allowed
   |     |           |
   |     |           not allowed on tuple variant `TSVariant`
   |     not allowed on enum `Enum`
   |
   = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other
help: remove the generics arguments from one of the path segments
   |
LL -     Enum::<()>::TSVariant::<()>(());
LL +     Enum::<()>::TSVariant(());
   |
```

Fix rust-lang#93993.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 12, 2025
 Explain that in paths generics can't be set on both the enum and the variant

```
error[E0109]: type arguments are not allowed on tuple variant `TSVariant`
  --> $DIR/enum-variant-generic-args.rs:54:29
   |
LL |     Enum::<()>::TSVariant::<()>(());
   |                 ---------   ^^ type argument not allowed
   |                 |
   |                 not allowed on tuple variant `TSVariant`
   |
   = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other
help: remove the generics arguments from one of the path segments
   |
LL -     Enum::<()>::TSVariant::<()>(());
LL +     Enum::TSVariant::<()>(());
   |
LL -     Enum::<()>::TSVariant::<()>(());
LL +     Enum::<()>::TSVariant(());
   |
```

Fix rust-lang#93993.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 12, 2025
 Explain that in paths generics can't be set on both the enum and the variant

```
error[E0109]: type arguments are not allowed on tuple variant `TSVariant`
  --> $DIR/enum-variant-generic-args.rs:54:29
   |
LL |     Enum::<()>::TSVariant::<()>(());
   |                 ---------   ^^ type argument not allowed
   |                 |
   |                 not allowed on tuple variant `TSVariant`
   |
   = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other
help: remove the generics arguments from one of the path segments
   |
LL -     Enum::<()>::TSVariant::<()>(());
LL +     Enum::TSVariant::<()>(());
   |
LL -     Enum::<()>::TSVariant::<()>(());
LL +     Enum::<()>::TSVariant(());
   |
```

Fix rust-lang#93993.
@bors bors closed this as completed in 1b98d0e Feb 12, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 12, 2025
Rollup merge of rust-lang#134981 - estebank:issue-93993, r=BoxyUwU

 Explain that in paths generics can't be set on both the enum and the variant

```
error[E0109]: type arguments are not allowed on tuple variant `TSVariant`
  --> $DIR/enum-variant-generic-args.rs:54:29
   |
LL |     Enum::<()>::TSVariant::<()>(());
   |                 ---------   ^^ type argument not allowed
   |                 |
   |                 not allowed on tuple variant `TSVariant`
   |
   = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other
help: remove the generics arguments from one of the path segments
   |
LL -     Enum::<()>::TSVariant::<()>(());
LL +     Enum::TSVariant::<()>(());
   |
LL -     Enum::<()>::TSVariant::<()>(());
LL +     Enum::<()>::TSVariant(());
   |
```

Fix rust-lang#93993.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants