22//! ```no_run
33//! let /* & */ (/* ref */ x,) = &(0,);
44//! ```
5+ use std:: mem;
6+
57use hir:: Mutability ;
68use ide_db:: famous_defs:: FamousDefs ;
79
810use span:: EditionedFileId ;
911use syntax:: ast:: { self , AstNode } ;
1012
11- use crate :: { InlayHint , InlayHintPosition , InlayHintsConfig , InlayKind } ;
13+ use crate :: { InlayHint , InlayHintLabel , InlayHintPosition , InlayHintsConfig , InlayKind } ;
1214
1315pub ( super ) fn hints (
1416 acc : & mut Vec < InlayHint > ,
@@ -42,7 +44,18 @@ pub(super) fn hints(
4244 } ,
4345 |it| it. syntax ( ) . text_range ( ) ,
4446 ) ;
47+ let mut hint = InlayHint {
48+ range,
49+ kind : InlayKind :: BindingMode ,
50+ label : InlayHintLabel :: default ( ) ,
51+ text_edit : None ,
52+ position : InlayHintPosition :: Before ,
53+ pad_left : false ,
54+ pad_right : false ,
55+ resolve_parent : Some ( pat. syntax ( ) . text_range ( ) ) ,
56+ } ;
4557 let pattern_adjustments = sema. pattern_adjustments ( pat) ;
58+ let mut was_mut_last = false ;
4659 pattern_adjustments. iter ( ) . for_each ( |ty| {
4760 let reference = ty. is_reference ( ) ;
4861 let mut_reference = ty. is_mutable_reference ( ) ;
@@ -51,17 +64,15 @@ pub(super) fn hints(
5164 ( true , false ) => "&" ,
5265 _ => return ,
5366 } ;
54- acc. push ( InlayHint {
55- range,
56- kind : InlayKind :: BindingMode ,
57- label : r. into ( ) ,
58- text_edit : None ,
59- position : InlayHintPosition :: Before ,
60- pad_left : false ,
61- pad_right : mut_reference,
62- resolve_parent : Some ( pat. syntax ( ) . text_range ( ) ) ,
63- } ) ;
67+ if mem:: replace ( & mut was_mut_last, mut_reference) {
68+ hint. label . append_str ( " " ) ;
69+ }
70+ hint. label . append_str ( r) ;
6471 } ) ;
72+ hint. pad_right = was_mut_last;
73+ if !hint. label . parts . is_empty ( ) {
74+ acc. push ( hint) ;
75+ }
6576 match pat {
6677 ast:: Pat :: IdentPat ( pat) if pat. ref_token ( ) . is_none ( ) && pat. mut_token ( ) . is_none ( ) => {
6778 let bm = sema. binding_mode_of_pat ( pat) ?;
@@ -117,6 +128,13 @@ fn __(
117128 (x,): &mut (u32,)
118129 //^^^^&mut
119130 //^ ref mut
131+ (x,): &mut &mut (u32,)
132+ //^^^^&mut &mut
133+ //^ ref mut
134+ (x,): &&(u32,)
135+ //^^^^&&
136+ //^ ref
137+
120138) {
121139 let (x,) = (0,);
122140 let (x,) = &(0,);
0 commit comments