File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
crates/ide/src/inlay_hints Expand file tree Collapse file tree 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(
2929 _ => None ,
3030 } )
3131 . 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+ ) ;
3443 let pattern_adjustments = sema. pattern_adjustments ( pat) ;
3544 pattern_adjustments. iter ( ) . for_each ( |ty| {
3645 let reference = ty. is_reference ( ) ;
@@ -123,4 +132,20 @@ fn __(
123132}"# ,
124133 ) ;
125134 }
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+ }
126151}
You can’t perform that action at this time.
0 commit comments