rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.27k stars 1.61k forks source link

Don't show type hints on `let foo = {struct literal};` #8259

Open jplatte opened 3 years ago

jplatte commented 3 years ago

A type hint on a variable that is simply let-bound to a struct literal seems rather pointless:

Screenshot_2021-03-30_131929

See also #3796, which was about chaining type hints for struct literals.

flodiebold commented 3 years ago

It becomes useful as soon as the struct has a type parameter, so I'm not sure if we want to introduce special handling just for this case.

jplatte commented 3 years ago

Special handling for when the type has type (or consts) generics should be easy though, no?

Also, that would still repeat the type name needlessly. A turbofish hint would be an interesting alternative, i.e.

// what the user wrote
let foobar = FooBar { field };
// current type hint
let foobar: FooBar<BazQux> = FooBar { field };
// turbofish hint
let foobar = FooBar::<BazQux> { field };
jplatte commented 2 years ago

Since #10761 did the same thing for constructor functions, it seems like most of the infrastructure for detecting cases like this is already in place. Can this be labeled S-actionable?