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

decide if we should do backtracking in impl resolution #4148

Closed
brson opened this issue Dec 10, 2012 · 9 comments
Closed

decide if we should do backtracking in impl resolution #4148

brson opened this issue Dec 10, 2012 · 9 comments
Labels
A-trait-system Area: Trait system

Comments

@brson
Copy link
Contributor

brson commented Dec 10, 2012

This is the next thing blocking removal of iter-trait:

trait MyIter<A> {
    fn myeach(&self, blk: fn(v: &A) -> bool);
}
trait ExtendedIter<A> {
    fn myeachi(&self, blk: fn(uint, v: &A) -> bool);
}

impl <A, IA: MyIter<A>> IA: ExtendedIter<A> {
    fn myeachi(&self, blk: fn(uint, v: &A) -> bool) { }
}

impl<A> &[A]: MyIter<A> {
    fn myeach(&self, blk: fn(v: &A) -> bool) { }
}

fn main() {
    let v = ~[0];
    for v.myeachi |_i, _j| { }
}
/home/brian/dev/rust/src/test/run-pass/test.rs:18:8: 18:17 error: failed to find an implementation of trait @MyIter<<V3>> for <V4>
/home/brian/dev/rust/src/test/run-pass/test.rs:18     for v.myeachi |_i, _j| { }
@nikomatsakis
Copy link
Contributor

Fixing this is a bit of a doozy, but it needs to be done anyhow. This basically requires rewriting the impl res. strategy to be "backtracking". That is, in order to decide if the method eachi() is applicable, we need to recurse and decide whether A is implemented for the proposed type. This is tied in with us deciding what limits (if any) we wish to place on impls; I think that @pcwalton and I have generally come to the feeling that we should place very few, and just beef up our resolution algorithminstead.

@catamorphism
Copy link
Contributor

Bumping to 0.7

@catamorphism
Copy link
Contributor

Seems non-critical for 0.7. Nominating for milestone 3, feature-complete.

@nikomatsakis
Copy link
Contributor

cc #5527

@graydon
Copy link
Contributor

graydon commented May 2, 2013

accepted as well defined

@emberian
Copy link
Member

Triage bump

@erickt
Copy link
Contributor

erickt commented Aug 3, 2013

Still an unfixed as of 2460170. I updated the code to the latest syntax:

trait MyIter<T> {
    fn myeach(&self, blk: &fn(&T) -> bool);
}

trait ExtendedIter<T> {
    fn myeachi(&self, blk: &fn(uint, &T) -> bool);
}

impl<T, IT: MyIter<T>> ExtendedIter<T> for IT {
    fn myeachi(&self, blk: &fn(uint, &T) -> bool) { }
}

impl<'self, T> MyIter<T> for &'self [T] {
    fn myeach(&self, blk: &fn(&T) -> bool) { }
}

fn main() {
    let v = ~[0];
    for v.myeachi |_i, _j| { }
}

@flaper87
Copy link
Contributor

Triage bump. Updated example (kept it close to the original one).

trait MyIter<T> {
    fn myeach(&self, blk: &fn(&T) -> bool);
}

trait ExtendedIter<T> {
    fn myeachi(&self, blk: &fn(uint, &T) -> bool);
}

impl<T, IT: MyIter<T>> ExtendedIter<T> for IT {
    fn myeachi(&self, blk: &fn(uint, &T) -> bool) { }
}

impl<'a, T> MyIter<T> for &'a [T] {
    fn myeach(&self, blk: &fn(&T) -> bool) { }
}

fn main() {
    let v = ~[0];
    let iter = v.myeachi(|b, &a| {false});
}

@nikomatsakis
Copy link
Contributor

This issue is really not relevant anymore. Trait reform implemented backtracking and more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

No branches or pull requests

7 participants