Skip to content

Commit 51a50e3

Browse files
Merge #3520
3520: Omit unit struct hints r=matklad a=SomeoneToIgnore Closes #3488 Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2 parents 5b3d97e + 605dc98 commit 51a50e3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

crates/ra_ide/src/inlay_hints.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_
119119
return true;
120120
}
121121

122+
if let Some(Adt::Struct(s)) = pat_ty.as_adt() {
123+
if s.fields(db).is_empty() && s.name(db).to_string() == bind_pat.syntax().to_string() {
124+
return true;
125+
}
126+
}
127+
122128
for node in bind_pat.syntax().ancestors() {
123129
match_ast! {
124130
match node {
@@ -943,4 +949,30 @@ fn main() {
943949
"###
944950
);
945951
}
952+
953+
#[test]
954+
fn unit_structs_have_no_type_hints() {
955+
let (analysis, file_id) = single_file(
956+
r#"
957+
enum CustomResult<T, E> {
958+
Ok(T),
959+
Err(E),
960+
}
961+
use CustomResult::*;
962+
963+
struct SyntheticSyntax;
964+
965+
fn main() {
966+
match Ok(()) {
967+
Ok(_) => (),
968+
Err(SyntheticSyntax) => (),
969+
}
970+
}"#,
971+
);
972+
973+
assert_debug_snapshot!(analysis.inlay_hints(file_id, Some(8)).unwrap(), @r###"
974+
[]
975+
"###
976+
);
977+
}
946978
}

0 commit comments

Comments
 (0)