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

Sort the errors from arguments checking so that suggestions are handled properly #112762

Merged
merged 2 commits into from
Jun 20, 2023

Conversation

chenyukang
Copy link
Member

@chenyukang chenyukang commented Jun 18, 2023

Fixes #112507

The algorithm of find_issue does not make sure the index comes out in order, which will make suggesting remove or add arguments broken in some cases.

Modifying the algorithm to obey order involves much more trivial change, so it's better to order the errors after iterations.

@rustbot
Copy link
Collaborator

rustbot commented Jun 18, 2023

r? @oli-obk

(rustbot has picked a reviewer for you, use r? to override)

@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 Jun 18, 2023
// sort errors with same type by the order they appear in the source
// so that suggestion will be handled properly, see #112507
errors.sort_by(|a, b| match (a, b) {
(Error::Missing(i), Error::Missing(j)) => i.cmp(j),
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 you could probably just derive Ord on Error and just use .sort()?

Copy link
Member Author

Choose a reason for hiding this comment

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

we need to customize PartialOrd for Error and I think only ordering on Missing and Extra is enough(which will involve adding or removing arguments).

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it hurts to just totally sort the list. I think right now the sort implementation is not actually valid because it returns Equal for other elements 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I just validated with some playground code, it won't sort in some cases, let me fix it 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

But actually, this implementation is enough, because it makes sure the consecutive Extra and Missing ordered 😆, which is the scenario that makes sub-suggestions buggy.

Anyway, let's make it all ordered.

@@ -55,6 +55,34 @@ pub(crate) enum Error<'tcx> {
Permutation(Vec<(ExpectedIdx, ProvidedIdx)>),
}

impl Ord for Error<'_> {
fn cmp(&self, other: &Self) -> Ordering {
let key = |error: &Error<'_>| -> usize {
Copy link
Member Author

Choose a reason for hiding this comment

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

@compiler-errors do you know any better method for this?
I want the same Error type ordered into the same group.

Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the default for derive(PartialOrd)? I think it first sorts by enum discriminant and then by fields lexicographically.

@compiler-errors
Copy link
Member

r=me after changing to derive(PartialOrd, Ord) (unless there's some other problem with that approach)

r? @compiler-errors

@rustbot rustbot assigned compiler-errors and unassigned oli-obk Jun 20, 2023
@compiler-errors compiler-errors 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 Jun 20, 2023
@chenyukang
Copy link
Member Author

Need to derive for too many other substructs such as Compatibility -> TypeError, and TypeError has other enum types which can not derive default.

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jun 20, 2023

📌 Commit aba1cf1 has been approved by compiler-errors

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 20, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 20, 2023
…llaumeGomez

Rollup of 6 pull requests

Successful merges:

 - rust-lang#112464 (Fix windows `Socket::connect_timeout` overflow)
 - rust-lang#112720 (Rustdoc: search: color item type and reduce size to avoid clashing)
 - rust-lang#112762 (Sort the errors from arguments checking so that suggestions are handled properly)
 - rust-lang#112786 (change binders from tuple structs to named fields)
 - rust-lang#112794 (Fix linker failures when #[global_allocator] is used in a dependency)
 - rust-lang#112819 (Disable feature(unboxed_closures, fn_traits) in weird-exprs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6c5e212 into rust-lang:master Jun 20, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jun 20, 2023
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.

ice: E0061: remove the extra arguments suggestion malformed
5 participants