From 605dc98451816545577b8c23c998df490481c95b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 8 Mar 2020 23:21:08 +0200 Subject: Omit unit struct hints --- crates/ra_ide/src/inlay_hints.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'crates/ra_ide/src') 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_ 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 { + 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###" + [] + "### + ); + } } -- cgit v1.2.3