don't add redundant help for object safety violations

This commit is contained in:
Ryan Mehri 2023-10-26 08:20:49 -07:00
parent 4fd68eb47b
commit af6b84aaab
No known key found for this signature in database
GPG key ID: CEAFB62465F3A716
4 changed files with 75 additions and 35 deletions

View file

@ -104,9 +104,15 @@ 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();
for violation in reported_violations {
// 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.
let mut potential_solutions: Vec<_> =
reported_violations.into_iter().map(|violation| violation.solution()).collect();
potential_solutions.sort();
// Allows us to skip suggesting that the same item should be moved to another trait multiple times.
potential_solutions.dedup();
for solution in potential_solutions {
solution.add_to(&mut err);
}
}