Skip to content

Show common iterators as impl Iterator within nested types #7647

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

Open
jyn514 opened this issue Feb 12, 2021 · 7 comments
Open

Show common iterators as impl Iterator within nested types #7647

jyn514 opened this issue Feb 12, 2021 · 7 comments
Labels
A-inlay-hints inlay/inline hints C-enhancement Category: enhancement E-unknown It's unclear if the issue is E-hard or E-easy without digging in S-actionable Someone could pick this issue up and work on it right now

Comments

@jyn514
Copy link
Member

jyn514 commented Feb 12, 2021

"Common iterators" is intentionally in scare quotes because I don't want to bikeshed exactly what set that should be here. Basically the request is for things like vec![0].into_iter().flat_map(|| ...) to be shown as Iterator<Item = i32> instead of FlatMap<IntoIter<i32>>. As an example, this snippet:

image

could instead be |...| -> impl Iterator<Item = ConditionalPass>.

@jyn514
Copy link
Member Author

jyn514 commented Feb 12, 2021

This is similar to #3138, but with a concrete suggestion for iterators rather than "shorten all long types".

@Veykril
Copy link
Member

Veykril commented Feb 12, 2021

We already do this shortening for hints for bare iterator types coming from std::iter(#6154)
image
so I suppose you are asking to extend this "shortening" for to also apply if the iterator types are nested inside other types, as for example the closure in your screenshot?

@jyn514
Copy link
Member Author

jyn514 commented Feb 12, 2021

Oh neat, I didn't realize you did. Yes, it would be great to extend it to nested types :)

@jyn514 jyn514 changed the title Show "common iterators" as impl Iterator Show common iterators as impl Iterator within nested types Feb 12, 2021
@Veykril Veykril added E-unknown It's unclear if the issue is E-hard or E-easy without digging in S-actionable Someone could pick this issue up and work on it right now labels Feb 12, 2021
@Veykril
Copy link
Member

Veykril commented Feb 12, 2021

This might be tricky to implement actually as currently we merely have to check if the type implements Iterator and lives in std::iter to replace the inlay hint, otherwise we just display the HIR Type. To get this nested shortening working we would have to change how the formatting works, or maybe replace types with synthetic impl Iterator types? 🤔

@Veykril Veykril added the A-inlay-hints inlay/inline hints label Dec 17, 2021
@Veykril
Copy link
Member

Veykril commented Jan 14, 2023

This seems to have been implemented at some point

@Veykril Veykril closed this as completed Jan 14, 2023
@HKalbasi
Copy link
Member

I still got this (on 09-01-2023):
image
Or is the issue discussed here is something different?

@Veykril
Copy link
Member

Veykril commented Jan 14, 2023

Ah, I tested nested iterators where this seems to work i.e impl Iterator<Item = impl Iterator<...>>.

@Veykril Veykril reopened this Jan 14, 2023
@Veykril Veykril added the C-enhancement Category: enhancement label Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inlay-hints inlay/inline hints C-enhancement Category: enhancement E-unknown It's unclear if the issue is E-hard or E-easy without digging in S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

3 participants