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

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

Merged
merged 2 commits into from
Feb 12, 2025

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Dec 31, 2024

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 #93993.

@rustbot
Copy link
Collaborator

rustbot commented Dec 31, 2024

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 31, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 31, 2024

HIR ty lowering was modified

cc @fmease

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not that they aren't allowed on enum variants at all, they are only forbidden if they are already specified on the enum type:

type OptionU32 = Option<u32>;
fn main() {
    Some::<u32>; // ok
    Option::Some::<u32>; // ok
    Option::<u32>::Some::<u32>; // ERROR
    OptionU32::Some; // ok
    OptionU32::Some::<u32>; // ERROR
}

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 14, 2025

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 14, 2025
@estebank estebank changed the title Explain that in paths generics belong on the enum, not the variant Explain that in paths generics can't be set on both the enum and the variant Jan 30, 2025
@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 30, 2025
Comment on lines 1541 to 1520
err.multipart_suggestions(
"remove the generics arguments from one of the path segments",
args.into_iter().map(|span| vec![(span, String::new())]),
Applicability::MaybeIncorrect,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vibe: I feel like making this a suggestion is not worth it and that the 6 additional lines in the error message add more noise. I would personally prefer to only make this a help message

r=me with or without that change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a few different alternatives on how to communicate this, because previously we didn't point at the previous type args:

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(());
   |

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
   |
LL |     Enum::<()>::TSVariant::<()>(());
   |           ^^^^              ^^

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
   |           |     |           type argument on the variant
   |           |     not allowed on tuple variant `TSVariant`
   |           type argument on the 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

I wasn't happy with any of them, tbh. They are all verbose, at lesat the suggestion one has the chance of being understood by the widest amount of people. One other option is to emit a specific error:

error[E0109]: type arguments are not allowed on enum `Enum` and tuple variant `TSVariant` at the same time
  --> $DIR/enum-variant-generic-args.rs:54:29
   |
LL |     Enum::<()>::TSVariant::<()>(());
   |            ^^   ---------   ^^ type argument on the variant
   |            |     
   |            type argument on the 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

Any preference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe also pointing to the generic args on the enum inline

error[E0109]: type arguments are not allowed on variant `SVariant`
  --> $DIR/enum-variant-generic-args.rs:72:28
   |
LL |     Enum::<()>::SVariant::<()> { v: () };
   |                 --------   ^^ type argument not allowed
   |                 |
   |                 not allowed on variant `SVariant`
   |
   = note: generic arguments are not allowed on both an enum and its variant's path segment simultaneously
   = help: consider removing the redundant generic arguments from the variant's path

I feel like we should be opinionated here and suggest keeping the args on the enum.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the current output?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer my suggestion from the last comment over the status quo. It's also still broken in the AliasFixed error message, isn't it?

I think stating both "not allowed on enum Enum" and "not allowed on tuple variant TSVariant" is confusing. I would chnage the first to "already specified on enum Enum" maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the AliasFixed examples it's not valid to turbofish the alias or the variant, I don't expect this PR to affect anything there (though it may be a good follow up PR to consolidate the errors for each segment into a single one).

Comment on lines 1050 to 1053
let segments: Vec<_> = match err_extend {
GenericsArgsErrExtend::DefVariant(segments) => segments.iter().collect(),
_ => segments.collect(),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree with lcnr about how having extra spans and things in the error message for the enum arguments too is confusing. Can you just remove this so we keep the current set of segments, then I think this is good to merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 10, 2025

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 10, 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.
…c args

```
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(());
   |
```
@estebank
Copy link
Contributor Author

@BoxyUwU changed

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 12, 2025
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 12, 2025

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 12, 2025

📌 Commit 23daa8c has been approved by BoxyUwU

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 12, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request 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 added a commit to rust-lang-ci/rust that referenced this pull request Feb 12, 2025
…llaumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#134981 ( Explain that in paths generics can't be set on both the enum and the variant)
 - rust-lang#136698 (Replace i686-unknown-redox target with i586-unknown-redox)
 - rust-lang#136767 (improve host/cross target checking)
 - rust-lang#136829 ([rustdoc] Move line numbers into the `<code>` directly)
 - rust-lang#136875 (Rustc dev guide subtree update)
 - rust-lang#136900 (compiler: replace `ExternAbi::name` calls with formatters)
 - rust-lang#136913 (Put kobzol back on review rotation)
 - rust-lang#136915 (documentation fix: `f16` and `f128` are not double-precision)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 262079b into rust-lang:master Feb 12, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 12, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request 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
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

supplying generic args to variant and enum results in weird error
6 participants