-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Improve compiler error message for wrong generic parameter order #72271
Conversation
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
You'll need to add a regression test in |
Okay. But is my approach right though? |
@rakshith-ravi: this looks like the right idea, yes! I'll leave some more detailed comments soon. I would just use one |
#72441 will definitely interfere with this unfortunately |
Sounds fun. I'm looking forward to it xD Can you please help me understand what exactly that PR does? |
@rakshith-ravi Yeah definitely! Are you active on the |
Yup. You'll find me as |
@doctorn I've merged your branch into mine. So all merge conflicts are now resolved. You can merge this into master once #72441 gets merged. @varkor I've added the changes you suggested as well. Sorting it out with a sort function call now, and removed those 3 Still need to update the tests. Will get on that soon |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@rakshith-ravi: once #72441 is merged, could you rebase over it? That would make it easier to review changes (it's frustrating that GitHub doesn't support dependent pull requests). |
Ignore me |
@@ -133,6 +134,7 @@ LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, ' | |||
| ^^ | |||
| | |||
= note: type arguments must be provided before lifetime arguments |
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.
Wait hold on, shouldn't type arguments be provided after lifetime arguments?
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.
Huh. Yes, they should be. But that didn't come from my PR though, so I'm scared to touch it. 😆
I mean, I know exactly where this error is thrown, but I'm not sure I should be doing it lol
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.
☔ The latest upstream changes (presumably #72778) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
This is looking good, thanks @rakshith-ravi! Just a few comments!
src/test/ui/const-generics/const-arg-type-arg-misordered.stderr
Outdated
Show resolved
Hide resolved
☔ The latest upstream changes (presumably #72935) made this pull request unmergeable. Please resolve the merge conflicts. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
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.
This is looking good! I just have a couple of comments about refactoring! After that, could you squash your commits down to one or two (e.g. by rebasing), and then I think we'll be good to go!
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Sorry about the spam, my laptop isn't good enough for me to build this repo, so I'm trying my best to figure out the code without building it. |
You can use |
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.
This is looking good! Just a few more comments. (Sorry I didn't spot that you had updated the pull request earlier.)
src/librustc_typeck/astconv.rs
Outdated
Self::generic_arg_mismatch_err(tcx.sess, arg, kind.descr()); | ||
// We're going to iterate over the parameters to sort them out, and | ||
// show that order to the user as a possible order for the parameters | ||
let mut ordered_params = defs.params.clone(); |
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.
Instead of two very similar match conditions, could we do something like the following?
let (ordered_params, mut params_present) = defs.params.clone().map(|param| (param, match param.kind { … })).sort_by_key(|(_, ord)| ord);
params_present.dedup();
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.
This was marked as resolved, but we're still matching on param.kind
twice?
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.
Yeah the code mentioned there doesn't seem to compile. It seems to complain something about not being able to convert from map to tuple
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 couldn't quite think off the top of my head what the types would be, so it may require a little adaption, but I think it would be good to only match on param.kind
once if that results in cleaner code.
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.
Alright, cool. I'll come up with something
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.
Hey @varkor. I'm getting this error:
the trait `std::hash::Hash` is not implemented for `rustc_middle::ty::GenericParamDef`
when trying to insert a GenericParamDef into a hashset.
Any idea how I can overcome this?
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.
My idea was not to use a hash set any more: we're using a vector instead, but because it's sorted, once we dedup
, the elements will be unique.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
See if you can get something like this to work. In any case, I think it should be good after that, so could you squash your commits down to one or two commits to keep the history clean, and then I think it's ready to merge :) |
src/librustc_typeck/astconv.rs
Outdated
}) | ||
.collect::<Vec<(ParamKindOrd, GenericParamDef)>>(); | ||
param_types_present.sort_by_key(|(ord, _)| *ord); | ||
let mut param_types_present = param_types_present |
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.
Can you simply use unzip
for this part?
One more comment; sorry for being so picky! |
No worries. Sorry, I didn't know |
@rakshith-ravi: great, thanks for your hard work! Could you squash your changes down to 1 or 2 commits? After that, it's good to be merged :) |
Squashed 😄 |
Thanks @rakshith-ravi! @bors r+ rollup |
📌 Commit 0624a5a has been approved by |
Improve compiler error message for wrong generic parameter order - Added optional "help" parameter that shows a help message on the compiler error if required. - Added a simple ordered parameter as a sample help. @varkor will make more changes as required. Let me know if I'm heading in the right direction. Fixes rust-lang#68437 r? @varkor
Improve compiler error message for wrong generic parameter order - Added optional "help" parameter that shows a help message on the compiler error if required. - Added a simple ordered parameter as a sample help. @varkor will make more changes as required. Let me know if I'm heading in the right direction. Fixes rust-lang#68437 r? @varkor
Improve compiler error message for wrong generic parameter order - Added optional "help" parameter that shows a help message on the compiler error if required. - Added a simple ordered parameter as a sample help. @varkor will make more changes as required. Let me know if I'm heading in the right direction. Fixes rust-lang#68437 r? @varkor
…arth Rollup of 9 pull requests Successful merges: - rust-lang#72271 (Improve compiler error message for wrong generic parameter order) - rust-lang#72493 ( move leak-check to during coherence, candidate eval) - rust-lang#73398 (A way forward for pointer equality in const eval) - rust-lang#73472 (Clean up E0689 explanation) - rust-lang#73496 (Account for multiple impl/dyn Trait in return type when suggesting `'_`) - rust-lang#73515 (Add second message for LiveDrop errors) - rust-lang#73567 (Clarify --extern documentation.) - rust-lang#73572 (Fix typos in doc comments) - rust-lang#73590 (bootstrap: no `config.toml` exists regression) Failed merges: r? @ghost
@varkor will make more changes as required. Let me know if I'm heading in the right direction.
Fixes #68437
r? @varkor