-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 slice binary search signature mismatch #41590
Conversation
The signature for `std::slice::binary_search` is now parameterized over `Borrow`, as in `core::SliceExt`
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
Thanks for the PR! We'll make sure that @aturon or another reviewer takes a look soon. |
The error message "the trait bound pub fn binary_search_by_key<'a, B, F, Q>(&'a self, b: &Q, f: F) -> Result<usize, usize>
where F: FnMut(&'a T) -> B,
B: Borrow<Q>,
Q: Ord + ?Sized to pub fn binary_search_by_key<'a, B, F, Q>(&'a self, b: &Q, f: F) -> Result<usize, usize>
where F: FnMut(&'a T) -> &'a B, // Note the type of the return value
B: Borrow<Q>,
Q: Ord + ?Sized , and change the line 27 of test let r = xs.binary_search_by_key(&key, |e| &e.topic); to let r = xs.binary_search_by_key(key, |e| &e.topic); . However, this is a breaking-change. |
It might be possible to add a cc @rust-lang/libs, does anyone recall how we even got to a place where |
Added in #37761 the orginal intention was to generalize a bunch, we then backed it out because of breakage. I suspect it was just forgotten to back out the libcore changes, and the reviewer (me) wasn't paying enough attention to backing out the changes. I would personally desire a crater run for this PR before we land it, as the last one turned up lots of breakage so we may not be able to land. |
@alexcrichton Hm, that's not quite my read of #37761. It looks to me like the PR originally included similar generalizations to other functions, but never included a change to In any case, seems like a crater run is in order. |
@aturon the original commit (I think?) did indeed only change libcore wrt binary_search, I must be misremembering.
Agreed. |
Ok, seems that we should add a type annotation for the |
So the tests now fail with |
@circuitfox Changing all 4 appearance of |
@mzji You're right. Changing |
@circuitfox And that's shorter. 😄 |
@brson @eddyb @alexcrichton Could someone do a crater run? |
ping @brson @eddyb @alexcrichton reminder that this is waiting on a crater run! |
I've started building toolchains for crater |
I've started the crate build for crater. |
Actual root regressions below.
|
So what are the next steps here @aturon @alexcrichton ? |
The next step is for the @rust-lang/libs team to decide whether this is acceptable breakage and whether or not to merge this PR. The |
The libs team discussed this PR during triage and the conclusion was to close, and I've posted more comments on the tracking issue |
Remove Borrow bound from SliceExt::binary_search #37761 added a Borrow bound to `binary_search` and `binary_search_by_key` in `core::SliceExt`, but did not add it to the methods in `std::slice`. #41590 attempted to add this bound to `std::slice` but was not merged due to breakage. This PR removes the bound in `core::SliceExt`, so that these methods will have the same signature in `core` and `std`. Fixes #41561
…ig, r=alexcrichton Remove Borrow bound from SliceExt::binary_search rust-lang#37761 added a Borrow bound to `binary_search` and `binary_search_by_key` in `core::SliceExt`, but did not add it to the methods in `std::slice`. rust-lang#41590 attempted to add this bound to `std::slice` but was not merged due to breakage. This PR removes the bound in `core::SliceExt`, so that these methods will have the same signature in `core` and `std`. Fixes rust-lang#41561
…richton Remove Borrow bound from SliceExt::binary_search #37761 added a Borrow bound to `binary_search` and `binary_search_by_key` in `core::SliceExt`, but did not add it to the methods in `std::slice`. #41590 attempted to add this bound to `std::slice` but was not merged due to breakage. This PR removes the bound in `core::SliceExt`, so that these methods will have the same signature in `core` and `std`. Fixes #41561
#37761 paramaterized
binary_search
overBorrow
incore::SliceExt
. This PR does the same forstd::slice
, so that the std and core slice APIs match.Fixes #41561