File tree 1 file changed +27
-17
lines changed
crates/ide/src/inlay_hints
1 file changed +27
-17
lines changed Original file line number Diff line number Diff line change @@ -67,28 +67,23 @@ fn should_not_display_type_hint(
67
67
return true ;
68
68
}
69
69
70
- if let Some ( hir:: Adt :: Struct ( s) ) = pat_ty. as_adt ( ) {
71
- if s. fields ( db) . is_empty ( ) && s. name ( db) . to_smol_str ( ) == bind_pat. to_string ( ) {
72
- return true ;
73
- }
74
- }
75
-
76
- if config. hide_closure_initialization_hints {
77
- if let Some ( parent) = bind_pat. syntax ( ) . parent ( ) {
78
- if let Some ( it) = ast:: LetStmt :: cast ( parent) {
79
- if let Some ( ast:: Expr :: ClosureExpr ( closure) ) = it. initializer ( ) {
80
- if closure_has_block_body ( & closure) {
81
- return true ;
82
- }
83
- }
84
- }
85
- }
70
+ if sema. resolve_bind_pat_to_const ( bind_pat) . is_some ( ) {
71
+ return true ;
86
72
}
87
73
88
74
for node in bind_pat. syntax ( ) . ancestors ( ) {
89
75
match_ast ! {
90
76
match node {
91
- ast:: LetStmt ( it) => return it. ty( ) . is_some( ) ,
77
+ ast:: LetStmt ( it) => {
78
+ if config. hide_closure_initialization_hints {
79
+ if let Some ( ast:: Expr :: ClosureExpr ( closure) ) = it. initializer( ) {
80
+ if closure_has_block_body( & closure) {
81
+ return true ;
82
+ }
83
+ }
84
+ }
85
+ return it. ty( ) . is_some( )
86
+ } ,
92
87
// FIXME: We might wanna show type hints in parameters for non-top level patterns as well
93
88
ast:: Param ( it) => return it. ty( ) . is_some( ) ,
94
89
ast:: MatchArm ( _) => return pat_is_enum_variant( db, bind_pat, pat_ty) ,
@@ -567,6 +562,21 @@ fn main() {
567
562
) ;
568
563
}
569
564
565
+ #[ test]
566
+ fn const_pats_have_no_type_hints ( ) {
567
+ check_types (
568
+ r#"
569
+ const FOO: usize = 0;
570
+
571
+ fn main() {
572
+ match 0 {
573
+ FOO => (),
574
+ _ => ()
575
+ }
576
+ }"# ,
577
+ ) ;
578
+ }
579
+
570
580
#[ test]
571
581
fn let_statement ( ) {
572
582
check_types (
You can’t perform that action at this time.
0 commit comments