aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-03-08 21:21:08 +0000
committerKirill Bulatov <[email protected]>2020-03-08 21:21:08 +0000
commit605dc98451816545577b8c23c998df490481c95b (patch)
treef253961081f924dc66b64efb74a9a992d6ceaf02
parentaff82cf7ac172f213cb5dcca637cb2c5332294c1 (diff)
Omit unit struct hints
-rw-r--r--crates/ra_ide/src/inlay_hints.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 69098a630..cf0cbdbd0 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -119,6 +119,12 @@ fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_
119 return true; 119 return true;
120 } 120 }
121 121
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
122 for node in bind_pat.syntax().ancestors() { 128 for node in bind_pat.syntax().ancestors() {
123 match_ast! { 129 match_ast! {
124 match node { 130 match node {
@@ -943,4 +949,30 @@ fn main() {
943 "### 949 "###
944 ); 950 );
945 } 951 }
952
953 #[test]
954 fn unit_structs_have_no_type_hints() {
955 let (analysis, file_id) = single_file(
956 r#"
957enum CustomResult<T, E> {
958 Ok(T),
959 Err(E),
960}
961use CustomResult::*;
962
963struct SyntheticSyntax;
964
965fn 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 }
946} 978}