File tree 1 file changed +27
-2
lines changed
crates/ide/src/inlay_hints
1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,17 @@ pub(super) fn hints(
29
29
_ => None ,
30
30
} )
31
31
. last ( ) ;
32
- let range =
33
- outer_paren_pat. as_ref ( ) . map_or_else ( || pat. syntax ( ) , |it| it. syntax ( ) ) . text_range ( ) ;
32
+ let range = outer_paren_pat. as_ref ( ) . map_or_else (
33
+ || match pat {
34
+ // for ident patterns that @ bind a name, render the un-ref patterns in front of the inner pattern
35
+ // instead of the name as that makes it more clear and doesn't really change the outcome
36
+ ast:: Pat :: IdentPat ( it) => {
37
+ it. pat ( ) . map_or_else ( || it. syntax ( ) . text_range ( ) , |it| it. syntax ( ) . text_range ( ) )
38
+ }
39
+ it => it. syntax ( ) . text_range ( ) ,
40
+ } ,
41
+ |it| it. syntax ( ) . text_range ( ) ,
42
+ ) ;
34
43
let pattern_adjustments = sema. pattern_adjustments ( pat) ;
35
44
pattern_adjustments. iter ( ) . for_each ( |ty| {
36
45
let reference = ty. is_reference ( ) ;
@@ -123,4 +132,20 @@ fn __(
123
132
}"# ,
124
133
) ;
125
134
}
135
+
136
+ #[ test]
137
+ fn hints_binding_modes_complex_ident_pat ( ) {
138
+ check_with_config (
139
+ InlayHintsConfig { binding_mode_hints : true , ..DISABLED_CONFIG } ,
140
+ r#"
141
+ struct Struct {
142
+ field: &'static str,
143
+ }
144
+ fn foo(s @ Struct { field, .. }: &Struct) {}
145
+ //^^^^^^^^^^^^^^^^^^^^^^^^ref
146
+ //^^^^^^^^^^^^^^^^^^^^&
147
+ //^^^^^ref
148
+ "# ,
149
+ ) ;
150
+ }
126
151
}
You can’t perform that action at this time.
0 commit comments