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 belong on the enum, not the variant #134981

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

estebank
Copy link
Contributor

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

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs Outdated Show resolved Hide resolved
@@ -1118,6 +1118,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
for (what, span) in types_and_spans {
err.span_label(span, format!("not allowed on {what}"));
}
if segments.clone().any(|segment| {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if segments.clone().any(|segment| {
if segments.as_ref().any(|segment| {

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

segments is a impl Iterator + Clone`, so cloning it is cheap and doesn't really allocate much 😅

If it was a Vec, then I wouldn't need to clone it, it'd be .iter() and nothing else.

@@ -279,6 +279,8 @@ LL | Enum::<()>::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
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't add anything? Doesn't this just regurgitate the message and labels?

Also, generic arguments are permitted on variants — provided none are provided to the owning enum. Option::None::<i32> is legal, so is Option::<i32>::None. However Option::<i32>::None::<i32> is not. I'd say this would be a helpful thing to point out (in a concise manner ofc). E.g., having a label pointing at the parent generic args (which we have here) stating sth. along the lines of "due to this" (er, you get my point).

(On mobile rn, couldn't look more carefully)

Copy link
Contributor Author

@estebank estebank Dec 31, 2024

Choose a reason for hiding this comment

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

Wanted to make the smallest diff that would address this. I agree that this should likely have a structured suggestion, like others in the test file, but that would have needed more code to address (I've noticed that the amount of wrangling needed for structured suggestions pushes "obviously good wanted changes" to "we might not want to land this").

I also tried getting the path segment for the enum, but the Res wasn't Def(Enum, _) as I expected so left it as a note for now. But sure, we can not land this, it's not big loss.

```
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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