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

Add ByNeed and Predicate traits #27517

Closed
SimonSapin opened this issue Aug 4, 2015 · 5 comments
Closed

Add ByNeed and Predicate traits #27517

SimonSapin opened this issue Aug 4, 2015 · 5 comments
Labels
B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@SimonSapin
Copy link
Contributor

#18424 "Implement collections reform" was closed with one part left not implemented yet:

Tracking issue for rust-lang/rfcs#235, there are a number of sub-issues associated with this:

[...]

Backwards compatible changes that will require additional language features:

In particular, making Iterator::position generic over a Predicate trait would help replacing [T]::position_elem, which was deprecated in #26914, without the verbosity of .position(|i| i == &x)

CC @alexcrichton, @aturon

@bluss
Copy link
Member

bluss commented Aug 4, 2015

This should sync method names with &str and their pattern API if possible IMO, and futher API inspiration from there as well. The substring search algorithm we use does in theory work on all "orderable alphabets".

@Gankra
Copy link
Contributor

Gankra commented Aug 4, 2015

To my knowledge ByNeed and Predicate were totally busted and are unimplementable because of mumble mumble something something overlapping implementation stuff. In particular this RFC was merged while closures were known to be Boxed which somehow avoided conflicts. Now unboxed closures exist so everything falls apart.

Not even specialization is supposed to be able to fix this.

This is all vague out-of-cache memory though, @aturon should be able to recall the precise details if pressed.

Something about () -> T being ByNeed<Self> and ByNeed<T>

@aturon
Copy link
Member

aturon commented Aug 4, 2015

Yeah, for example, the following fails to compile:

trait Foo<T> {}

impl<T, U> Foo<U> for T where T: Fn(&U) -> bool {}
impl<'a, T> Foo<T> for &'a T {}

and as @gankro mentioned I was hoping specialization would solve it, but doing so requires some crazypants rules.

Still, there are other ways to address this, possibly including getting the compiler to reason more about #[fundamental], adding explicit "low-priority" impls to specialization, or introducing negative bounds.

@aturon
Copy link
Member

aturon commented Aug 4, 2015

(To be clear, the reason the example fails to compile is that in principle you could have &T: Fn(&T) -> bool, in which case both impls would apply; specialization as proposed doesn't help because neither impl is strictly more general. But since the relevant types/traits here are marked #[fundamental], some negative reasoning is already permitted, and if we took full advantage might be enough to work around this limitation.)

@steveklabnik steveklabnik added A-libs B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. labels Aug 4, 2015
@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Aug 11, 2015
@alexcrichton
Copy link
Member

Lots of time has passed since these were originally designed, so they would likely basically require another RFC to be added today, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants