3520: Omit unit struct hints r=matklad a=SomeoneToIgnore

Closes https://github.com/rust-analyzer/rust-analyzer/issues/3488

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This commit is contained in:
bors[bot] 2020-03-09 08:08:23 +00:00 committed by GitHub
commit 51a50e3f50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -119,6 +119,12 @@ fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_
return true;
}
if let Some(Adt::Struct(s)) = pat_ty.as_adt() {
if s.fields(db).is_empty() && s.name(db).to_string() == bind_pat.syntax().to_string() {
return true;
}
}
for node in bind_pat.syntax().ancestors() {
match_ast! {
match node {
@ -943,4 +949,30 @@ fn main() {
"###
);
}
#[test]
fn unit_structs_have_no_type_hints() {
let (analysis, file_id) = single_file(
r#"
enum CustomResult<T, E> {
Ok(T),
Err(E),
}
use CustomResult::*;
struct SyntheticSyntax;
fn main() {
match Ok(()) {
Ok(_) => (),
Err(SyntheticSyntax) => (),
}
}"#,
);
assert_debug_snapshot!(analysis.inlay_hints(file_id, Some(8)).unwrap(), @r###"
[]
"###
);
}
}