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

Type inference issues with IntoIterator #11242

Closed
cynecx opened this issue Jan 9, 2022 · 2 comments
Closed

Type inference issues with IntoIterator #11242

cynecx opened this issue Jan 9, 2022 · 2 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@cynecx
Copy link
Contributor

cynecx commented Jan 9, 2022

#[test]
fn double_into_iter() {
    check_types(
        r#"
//- /main.rs crate:main deps:core
use core::iter::IntoIterator;

fn intoiter_issue<A, B>(foo: A)
where
    A: IntoIterator<Item = B>,
    B: IntoIterator<Item = usize>,
{
    for x in foo {
    //  ^ B
        for m in x {
        //  ^ usize
        }
    }
}

//- /core.rs crate:core
pub mod iter {
    pub trait Iterator {
        type Item;
    }

    pub trait IntoIterator {
        type Item;
        type IntoIter: Iterator<Item = Self::Item>;
        // #[lang = "into_iter"]
        fn into_iter(self) -> Self::IntoIter;
    }

    // Uncomment this impl and type inference/test works/passes.
    impl<I: Iterator> IntoIterator for I {
        type Item = I::Item;
        type IntoIter = I;

        fn into_iter(self) -> I {
            self
        }
    }
}
"#,
    );
}

rust-analyzer version: 0f8c96c (current master)

rustc version: rustc 1.60.0-nightly (a7e2e3396 2022-01-08)

thread 'tests::traits::double_into_iter' panicked at 'assertion failed: `(left == right)`
  left: `"{unknown}"`,
 right: `"B"`',

Something weird is going on here because it works without the impl<I: Iterator> Iterator for I impl.

@Veykril Veykril added the A-ty type system / type inference / traits / method resolution label Jan 9, 2022
@jhgg
Copy link
Contributor

jhgg commented Jan 10, 2022

Dupe of #10653 / #9990

flodiebold added a commit to flodiebold/rust-analyzer that referenced this issue Mar 3, 2022
bors bot added a commit that referenced this issue Mar 3, 2022
11610: Add a (currently failing) test for #11242 r=flodiebold a=flodiebold



Co-authored-by: Florian Diebold <[email protected]>
@flodiebold flodiebold added the C-bug Category: bug label Mar 31, 2022
@flodiebold
Copy link
Member

Yeah, duplicate of #10653

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants