Skip to content

Type inference issues with IntoIterator  #11242

Closed as not planned
Closed as not planned
@cynecx

Description

@cynecx
#[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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions