-
Notifications
You must be signed in to change notification settings - Fork 13k
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
slice: allow [T]::contains to accept any Q where T: Borrow<Q> #43020
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This is most useful to allow matching string literals against a `[String]`, or bytestring literals against a `[Vec<u8>]`. Since `Vec<T>` derefs to `[T]`, this also applies to `Vec<String>` and `Vec<Vec<u8>>`.
BTW, something similar can be done for |
Hmm, the error in https://travis-ci.org/rust-lang/rust/jobs/249466135 is interesting -- looks like maybe we should implement |
One option here would be to have something like The other option might be to implement Thoughts? |
I just bumped into this today. I've got a |
@@ -110,7 +110,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest { | |||
where I: IntoIterator<Item=DefIdForest> | |||
{ | |||
let mut ret = DefIdForest::empty(); | |||
let mut next_ret = SmallVec::new(); | |||
let mut next_ret: SmallVec<[DefId; 1]> = SmallVec::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like an unrelated change? Unless inference is failing, as I suspect it is, in which case I'm not sure we'd be able to land this -- too much breakage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, inference was failing in this case.
@golddranks , a workaround would be to use a |
@vitalyd Unfortunately that's not an acceptable workaround if a |
@golddranks , you mean if you don't have control over the Your workaround using |
Note, this PR is closely related to:
The latter is a PR doing something similar for |
Yeah the inference breaking is unfortunate :( seems like this could have been fixed before 1.0, but it's too late now. @aturon Do you think it's worth adding |
Maybe we should do that cargobomb run first before thinking the plan B? |
I'm fine with that. Note that inference wasn't the only thing failing -- https://travis-ci.org/rust-lang/rust/jobs/249466135 has an example of code that was accepted earlier (extra &) now failing. |
@brson Flagging for crater run! |
Why Borrow and not PartialEq? |
ping @alexcrichton, @brson, @tomprince, and @frewsxcv for a crater run! |
Crater does not work any more. @tomprince has cargobomb running against PRs. Maybe he can do it. I will add this to my list. |
Looking at the PR's travis log, this failed cargotest -- clap had inference failures. So I worry that we shouldn't do this. However, in order to run cargobomb, we'll need to get the artifacts; this may not work due to the cargotest failure but I guess we can try: @bors try |
🔒 Merge conflict |
Looks like the merge conflict needs to be resolved, then the try run, then cargobomb. |
I agree with @jethrogb that it seems to make more sense to use
|
@bors try |
@Sid0 could you take a look at rebasing? In order to get artifacts, I believe we'll need to do alter the CI for this job to not build rustbook - I don't see how we'll get to the deploy stage otherwise. I don't know how to achieve that off the top of my head, so I'll look into it. |
I'm going to close this out of inactivity, but please feel free to resubmit! |
This allows `contains` to be used on slices to search for elements that satisfy a partial equality with the slice item type, rather than an identity. This closes rust-lang#42671. Note that string literals need to be referenced in this implementation due to `str` not implementing `Sized`. It’s likely this will have to go through a Crater run to test for breakage (see rust-lang#43020).
Generalise slice::contains over PartialEq This allows `contains` to be used on slices to search for elements that satisfy a partial equality with the slice item type, rather than an identity. This closes #42671. Note that string literals need to be referenced in this implementation due to `str` not implementing `Sized`. It’s likely this will have to go through a Crater run to test for breakage (see #43020).
This is most useful to allow matching string literals against a
[String]
, or bytestring literals against a[Vec<u8>]
.Since
Vec<T>
derefs to[T]
, this also applies toVec<String>
andVec<Vec<u8>>
.This implements https://internals.rust-lang.org/t/vec-contains-should-accept-anything-that-t-implements-borrow-for/5455 -- I'm really not sure about the stability guarantees required here, so some guidance would be really appreciated. Thanks :)