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

Don't add redundant help for object safety violations #117200

Merged
merged 2 commits into from
Nov 27, 2023

Conversation

rmehri01
Copy link
Contributor

Fixes #117186

r? WaffleLapkin

@rustbot
Copy link
Collaborator

rustbot commented Oct 26, 2023

Could not assign reviewer from: WaffleLapkin.
User(s) WaffleLapkin are either the PR author, already assigned, or on vacation, and there are no other candidates.
Use r? to specify someone else to assign.

@rustbot
Copy link
Collaborator

rustbot commented Oct 26, 2023

r? @spastorino

(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 Oct 26, 2023
@rust-log-analyzer

This comment has been minimized.

@@ -62,7 +62,6 @@ LL | trait NonObjectSafe4 {
| -------------- this trait cannot be made into an object...
LL | fn foo(&self, s: &Self);
| ^^^^^ ...because method `foo` references the `Self` type in this parameter
= help: consider moving `foo` to another trait
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 this is a change we want. Note that this mentions a different foo than the previous messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay, sorry about that, I pushed a different solution that doesn't change the other tests

@spastorino
Copy link
Member

@WaffleLapkin are you taking care of this review? can you assign it to yourselve?.
My only thought from skimming it quickly is ... why are we reporting twice in the first place?, do we have an idea why we insert 2 times in this list?.

@WaffleLapkin
Copy link
Member

@spastorino I can take the review.

The cause is that there can be multiple problems with the same item, we want to highlight all of them, but the proposed solution is the same for all problems — move the item to another trait.

@spastorino
Copy link
Member

spastorino commented Oct 27, 2023

The cause is that there can be multiple problems with the same item, we want to highlight all of them, but the proposed solution is the same for all problems — move the item to another trait.

Makes sense, I guess I'd hide from consumers the existence of that vector that tracks already suggested "solutions".

@bors
Copy link
Contributor

bors commented Oct 30, 2023

☔ The latest upstream changes (presumably #117405) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

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

This looks fine.

Please add a comment, fix conflicts and use @rustbot review to ask me for review again =)

@@ -103,9 +103,11 @@ pub fn report_object_safety_error<'tcx>(
if trait_span.is_some() {
let mut reported_violations: Vec<_> = reported_violations.into_iter().collect();
reported_violations.sort();

let mut reported_names = vec![];
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a little comment explaining why this is needed like "allows us to skip suggesting moving the same item to another trait multiple times" or something?

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! Do you think there is a better way of doing this to hide the vector, maybe by taking in the list of violations up front for example or is it okay as is?

Copy link
Member

Choose a reason for hiding this comment

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

We could create an ObjectSafetyViolationSolution enum, which would be returned from solution, then deduplicated, then added to the error. Something like

let mut potential_solutions: Vec<_> = reported_violations.into_iter().map(...::solution).collect();
potential_solutions.sort();
potential_solutions.dedup();
potential_solutions.for_each(|solution| solution.add_to(&mut err));

Do you want to try doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see, that sounds better, I'll give it a try!

@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 Nov 26, 2023
@rmehri01
Copy link
Contributor Author

@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 Nov 26, 2023
@WaffleLapkin
Copy link
Member

@rustbot author (#117200 (comment))

@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 Nov 26, 2023
// Only provide the help if its a local trait, otherwise it's not actionable.
violation.solution(&mut err);

// Only provide the help if its a local trait, otherwise it's not actionable.
Copy link
Member

Choose a reason for hiding this comment

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

Please move this to the if

@rmehri01
Copy link
Contributor Author

@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 Nov 26, 2023
Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

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

Thanks, I like this fix :)

@WaffleLapkin
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 27, 2023

📌 Commit ee96a7a has been approved by WaffleLapkin

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 Nov 27, 2023
@rmehri01
Copy link
Contributor Author

Thanks for the help, I like this one much more too! 😄

@bors
Copy link
Contributor

bors commented Nov 27, 2023

⌛ Testing commit ee96a7a with merge 6eb9524...

@bors
Copy link
Contributor

bors commented Nov 27, 2023

☀️ Test successful - checks-actions
Approved by: WaffleLapkin
Pushing 6eb9524 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 27, 2023
@bors bors merged commit 6eb9524 into rust-lang:master Nov 27, 2023
@rustbot rustbot added this to the 1.76.0 milestone Nov 27, 2023
@rmehri01 rmehri01 deleted the repeated_help branch November 27, 2023 21:52
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6eb9524): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.1% [-1.1%, -1.1%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.1% [2.1%, 4.1%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 674.379s -> 675.422s (0.15%)
Artifact size: 313.34 MiB -> 313.36 MiB (0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

Don't show the same help multiple times for object safety violations
7 participants