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

Complete assoc. types on paths without a trait #4149

Closed
wants to merge 1 commit into from
Closed

Complete assoc. types on paths without a trait #4149

wants to merge 1 commit into from

Conversation

jonas-schievink
Copy link
Contributor

There might be a reason for why this was not done before, so maybe this broke something subtle?

@@ -532,7 +532,10 @@ fn is_valid_candidate(
let data = db.const_data(c);
name.map_or(true, |name| data.name.as_ref() == Some(name)) && receiver_ty.is_none()
}
_ => false,
AssocItemId::TypeAliasId(t) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r? @flodiebold

From the look of it, the old code looks correct, as it only uses the values namespace. I would expect two similar fuctions, one for consttants & methods, and one for types. The caller can then select the appropriate namespace

Copy link
Member

@flodiebold flodiebold Apr 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, method_resolution is for values only, and associated types resolution has different rules. (You can't just write S::Item if S is a struct implementing Iterator, the only situation where you can write T::AssociatedType where T is a type is when T is a type parameter. I thought you could do this as well before I actually implemented it!)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might still be a good idea to replace _ with explicit match & comment

@r###"
[
CompletionItem {
label: "Assoc",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... so this completion is actually wrong, rustc will complain about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh great, not sure how I missed that :/

I think this is actually a bug in rustc, namely rust-lang/rust#22519. But yeah, rust-analyzer shouldn't suggest something that doesn't work.

Copy link
Member

@flodiebold flodiebold Apr 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, that issue doesn't propose allowing foo::S::AssocTy. It's rather about the fact that even if T is a type parameter, <T>::AssocTy doesn't work.

(Edit: Ok, eddyb's last comment does refer to allowing this, but still it doesn't seem like this will change anytime soon.)

@flodiebold
Copy link
Member

The code that resolves this associated type shorthand is currently here; the proper way to fix this would probably to extract that logic so it can be used to list all possible associated types, and then expose that through the ra_hir APIs.

@jonas-schievink jonas-schievink deleted the assoc-complete branch June 5, 2020 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants