Skip to content

into_iterator not resolved or completed on Vec<{unknown}> #10297

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

Closed
lnicola opened this issue Sep 20, 2021 · 4 comments · Fixed by #10373
Closed

into_iterator not resolved or completed on Vec<{unknown}> #10297

lnicola opened this issue Sep 20, 2021 · 4 comments · Fixed by #10373
Labels
A-ty type system / type inference / traits / method resolution S-actionable Someone could pick this issue up and work on it right now

Comments

@lnicola
Copy link
Member

lnicola commented Sep 20, 2021

It feels like we could offer into_iter here, since the impl is not constrained in any way:

fn main() {
    let mut x = Vec::new();
    x.into_iter();
}

// impl<T, A: Allocator> IntoIterator for Vec<T, A>
@lnicola lnicola added A-ty type system / type inference / traits / method resolution S-actionable Someone could pick this issue up and work on it right now labels Sep 20, 2021
@iDawer
Copy link
Contributor

iDawer commented Sep 25, 2021

Reproduced (update: minicore: from => minicore: sized )

#[test]
fn issue_10297() {
    check(
        r#"
//- minicore: iterator, sized
struct Vec<T>;
impl<T> IntoIterator for Vec<T> {
    type Item = ();
    type IntoIter = ();
    fn into_iter(self);
}
fn main() {
    let x: Vec<_>;
    x.$0;
}
"#,
        expect![[r#"
                me into_iter() (as IntoIterator) fn(self) -> <Self as IntoIterator>::IntoIter
            "#]],
    )
}

Without minicore: sized the test is fine

@lnicola lnicola changed the title into_iterator not resolved or complete on Vec<{unknown}> into_iterator not resolved or completed on Vec<{unknown}> Sep 25, 2021
@iDawer
Copy link
Contributor

iDawer commented Sep 26, 2021

Some logs:

iterate_trait_method_candidates: trait.name=IntoIterator
[crates/hir_ty/src/method_resolution.rs:696] &goal = Canonical {
    value: InEnvironment {
        environment: Env([]),
        goal: Implemented(AdtId(StructId(StructId(0)))<[?0 := {error}]>: TraitId(2)),
    },
    binders: [],
}
chalk program:
#[upstream]
#[non_enumerable]
#[object_safe]
#[lang(sized)]
trait Sized {}
#[upstream]
#[non_enumerable]
#[object_safe]
trait Iterator {
  type Item: Sized;
}
#[upstream]
#[non_enumerable]
#[object_safe]
trait IntoIterator {
  type Item: Sized;
  type IntoIter: Iterator + Iterator<Item=<Self as IntoIterator>::Item> + Sized;
}
impl<_1_0> IntoIterator for Vec<_1_0>
where
  _1_0: Sized
{
  type Item = ();
  type IntoIter = ();
}
struct Vec<_1_0>
where
  _1_0: Sized
{}

[crates/hir_ty/src/method_resolution.rs:698] db.trait_solve(krate, goal.cast(&Interner)) = None

As far I can interpret the goal is Vec<{error}>: IntoIterator. This drills down to solving {error}: Sized which then results in No possible solution. I'm not sure where is the problem: in passing error types to Chalk or Chalk failing to report ambiguity?

@flodiebold
Copy link
Member

flodiebold commented Sep 27, 2021

I think that's this FIXME:
https://github.com/rust-analyzer/rust-analyzer/blob/009e6ceb1ddcd27a9ced3bcb7d0ef823379185a1/crates/hir/src/lib.rs#L2604
It should probably just do this:
https://github.com/rust-analyzer/rust-analyzer/blob/009e6ceb1ddcd27a9ced3bcb7d0ef823379185a1/crates/hir/src/lib.rs#L2658

The error type is legitimate here, it comes from fallback for the uninferred variable. But we need to handle that when using the type for completion etc. (In theory we'd want something like the 'type before fallback' (but with canonicalized variables).)

@lnicola
Copy link
Member Author

lnicola commented Sep 27, 2021

Yeah, that works ^.

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 S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants