rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Inlay type hints not so useful in for loop on `impl IntoIterator<Item: Trait>`

Open antonilol opened this issue 1 year ago • 3 comments

rust-analyzer version: 0.4.2069-standalone

rustc version: rustc 1.80.1 (3f5fd8dd4 2024-08-06)

editor or extension: code oss

relevant settings: None

code snippet to reproduce:

pub fn count_bytes(iter: impl IntoIterator<Item: AsRef<[u8]>>) -> usize {
    let mut count = 0;

    for bytes in iter {
        count += bytes.as_ref().len();
    }

    count
}

screenshot (with inlay hints): image

<impl IntoIterator as IntoIterator>::Item this is true for all for loops, in this case impl AsRef<[u8]> would be (more) useful.

antonilol avatar Aug 12 '24 21:08 antonilol

I agree with you that we can give more useful information in this inlay hint but impl AsRef might be confusing cause r-a uses impl Trait things for displaying opaque types

ShoyuVanilla avatar Aug 13 '24 01:08 ShoyuVanilla

I think displaying it as impl AsRef<[u8]> would be pretty natural here. And we already have some heuristics anyway:

image

lnicola avatar Aug 13 '24 05:08 lnicola

Oh, that makes sense

ShoyuVanilla avatar Aug 13 '24 05:08 ShoyuVanilla