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

Fix 'where Self:' warnings by splitting 'OrdSubsetSliceExt' up into 'OrdSubsetSliceExt' and 'OrdSubsetSliceExtMut' #3

Closed
wants to merge 1 commit into from

Conversation

expenses
Copy link

This gets rid of a bunch of warnings such as:

warning: the trait `slice_ext::OrdSubsetSliceExt` cannot be made into an object ord_subset, ord_subset
  --> src/slice_ext.rs:42:5
   |
42 | /     fn ord_subset_sort(&mut self)
43 | |     where
44 | |         Self: AsMut<[T]>,
45 | |         T: OrdSubset;
   | |_____________________^
   |
   = note: #[warn(where_clauses_object_safety)] on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a      hard error in a future release!
   = note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>
   = note: method `ord_subset_sort` references the `Self` type in where clauses

The linked issue is rust-lang/rust#51443. Unfortunately, the best solution I've been able to come up with so far is to split up OrdSubsetSliceExt into two traits, OrdSubsetSliceExt, and OrdSubsetSliceExtMut which requires AsMut<[T]>.

… 'OrdSubsetSliceExt' and 'OrdSubsetSliceExtMut'
@Emerentius
Copy link
Owner

Thanks for the PR and the notice.

The trait was never intented to be used as an object, it's just there to extend [T]. The regular sort methods are all just methods on [T] without a trait, too after all. But, as it's going to break in the future anyway, no point in just allowing the warning.

I think it's best to reduce the implementors to just [T]. Any type that coerces via Deref or UnsizedCoercions like the usual suspects, arrays and vecs, will continue to work. Types that are only AsRef<T> or AsMut<T> will have to convert explicitly.

The (temporary) branch object_safety has the trait changes. I just need to adapt the tests so that they call the sort methods directly on the source types and not the slices that as_ref() or as_mut() gives.

@expenses
Copy link
Author

Oh ok, cool thanks.

@Emerentius
Copy link
Owner

The situation here is kinda shitty. See also issue #4. The lint is a false positive, that I can't deactivate and that I can't work around without a breaking change. For now, I'm going to keep the status quo.

@Emerentius Emerentius closed this Sep 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants