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

unresolved-method of impl IntoIterator<Item=...> as return type #14680

Closed
boozook opened this issue Apr 28, 2023 · 2 comments
Closed

unresolved-method of impl IntoIterator<Item=...> as return type #14680

boozook opened this issue Apr 28, 2023 · 2 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@boozook
Copy link

boozook commented Apr 28, 2023

rust-analyzer version: 0.4.1493-standalone (237ffa3 2023-04-27)

rustc version: rustc 1.70.0-nightly (84dd17b56 2023-04-14)

Screenshot 2023-04-29 at 02 58 02

Unfortunately I can't isolate it right now, but probably that will be easy:

  • use cargo crate
  • create config = cargo::util::config::Config::default()
  • create workspace = cargo::core::workspace::Workspace::new(&manifest_path, &*config)
  • call this with workspace.members(), e.g.: filter_packages_with_metadata(workspace.members())
    Something like this. 🙄
Code from screenshot
fn filter_packages_with_metadata<'i, I: Iterator<Item = &'i Package> + 'i>(iter: I) -> Vec<(PackageId, toml::Value)> {
	filter_packages_with_metadata_iter(iter).into_iter().collect()
}

fn filter_packages_with_metadata_iter<'i, I>(iter: I) -> impl IntoIterator<Item = (PackageId, toml::Value)> + 'i
	where I: Iterator<Item = &'i Package> + 'i {
	iter.filter_map(|p| {
		    p.manifest()
		     .custom_metadata()
		     .map(|meta| {
			     meta.as_table()
			         .map(|t| t.get("my-metadata"))
			         .flatten()
			         .map(|meta| (p.package_id(), meta))
		     })
		     .flatten()
	    })
	    .filter_map(|(id, v)| toml::Value::try_from(v).ok().map(|v| (id, v)))
}
@boozook boozook added the C-bug Category: bug label Apr 28, 2023
@lowr lowr added the A-ty type system / type inference / traits / method resolution label Apr 30, 2023
@lowr
Copy link
Contributor

lowr commented Apr 30, 2023

This is a chalk issue. Minimum repro:

fn foo() -> impl IntoIterator<Item = ()> {
    []
}

fn test() {
    let v: Vec<_> = foo().into_iter().collect();
                  //^^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved method
}

bors added a commit to rust-lang/chalk that referenced this issue Jun 14, 2023
Generate clauses for placeholder associated types

Currently, we don't generate clauses for placeholder associated types (`TyKind::AssociatedType`) except for some `FromEnv`s. This leads to `NoSolution` for goals like `(IntoIterator::IntoIter)<Opaque>: Iterator` where `Opaque = impl IntoIterator`.

For every associated type in a trait definition

```rust
trait Foo {
    type Assoc<'a, T>: Bar<U = Ty> where WC;
}
```

chalk with this patch generates

```rust
forall<Self, 'a, T> {
    Implemented((Foo::Assoc<'a, T>)<Self>: Bar) :- WC.
    AliasEq(<<(Foo::Assoc<'a, T>)<Self>> as Bar>::U = Ty) :- WC.
}
```

To be honest, I'm not entirely sure if `AssociatedTyDatum::to_program_clauses()` is the best place to generate those clauses in, but analogous clauses for placeholder opaque types are generated in `OpaqueTyDatum::to_program_clauses()`, which I modeled after.

Spotted in rust-lang/rust-analyzer#14680.
@Veykril
Copy link
Member

Veykril commented Apr 7, 2024

Fixed by rust-lang/chalk#795

@Veykril Veykril closed this as completed Apr 7, 2024
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

3 participants