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

bug: default impl trait bound on associated type not found #7060

Closed
MagisterDallis opened this issue Jan 12, 2025 · 0 comments · Fixed by #7067
Closed

bug: default impl trait bound on associated type not found #7060

MagisterDallis opened this issue Jan 12, 2025 · 0 comments · Fixed by #7067
Labels
bug Something isn't working

Comments

@MagisterDallis
Copy link
Contributor

Bug Report

Cairo version:
6837d54

Current behavior:

    fn next(ref self: T) -> Option<Self::Item>;

    fn advance_by<+Destruct<T>, +Destruct<Self::Item>>(
        ref self: T, n: usize,
    ) -> Result<
        (), NonZero<usize>,
    > {
        let mut n = n;
        let mut res = Result::Ok(());
        while let Option::Some(nz_n) = n.try_into() {
            if let Option::Some(_) = Self::next(ref self) {
                n -= 1;
            } else {
                res = Result::Err(nz_n);
                break;
            }
        };
        res
    }
}

Implementing this should work in theory, but in practice, the following test fails to compile because:

#[test]
fn test_advance_by() {
    let mut iter = array![1_u8, 2, 3, 4].into_iter();

    assert_eq!(iter.advance_by(2), Result::Ok(()));
    assert_eq!(iter.next(), Option::Some(3));
    assert_eq!(iter.advance_by(0), Result::Ok(()));
    assert_eq!(iter.advance_by(100), Result::Err(99));
}
error: Trait has no implementation in context: core::traits::Destruct::<Iterator::Item>.
 --> corelib/src/test/iter_test.cairo:5:21
    assert_eq!(iter.advance_by(2), Result::Ok(()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant