-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Conversation
HIR ty lowering was modified cc @fmease |
tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr
Outdated
Show resolved
Hide resolved
12aa567
to
7de7c36
Compare
There was a problem hiding this 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
}
@rustbot author |
err.multipart_suggestions( | ||
"remove the generics arguments from one of the path segments", | ||
args.into_iter().map(|span| vec![(span, String::new())]), | ||
Applicability::MaybeIncorrect, | ||
); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
let segments: Vec<_> = match err_extend { | ||
GenericsArgsErrExtend::DefVariant(segments) => segments.iter().collect(), | ||
_ => segments.collect(), | ||
}; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@rustbot author |
…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(()); | ```
ad95c62
to
23daa8c
Compare
@bors r+ rollup |
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.
…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
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.
Fix #93993.