2
2
//! ```no_run
3
3
//! let /* & */ (/* ref */ x,) = &(0,);
4
4
//! ```
5
+ use std:: mem;
6
+
5
7
use hir:: Mutability ;
6
8
use ide_db:: famous_defs:: FamousDefs ;
7
9
8
10
use span:: EditionedFileId ;
9
11
use syntax:: ast:: { self , AstNode } ;
10
12
11
- use crate :: { InlayHint , InlayHintPosition , InlayHintsConfig , InlayKind } ;
13
+ use crate :: { InlayHint , InlayHintLabel , InlayHintPosition , InlayHintsConfig , InlayKind } ;
12
14
13
15
pub ( super ) fn hints (
14
16
acc : & mut Vec < InlayHint > ,
@@ -42,7 +44,18 @@ pub(super) fn hints(
42
44
} ,
43
45
|it| it. syntax ( ) . text_range ( ) ,
44
46
) ;
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
+ } ;
45
57
let pattern_adjustments = sema. pattern_adjustments ( pat) ;
58
+ let mut was_mut_last = false ;
46
59
pattern_adjustments. iter ( ) . for_each ( |ty| {
47
60
let reference = ty. is_reference ( ) ;
48
61
let mut_reference = ty. is_mutable_reference ( ) ;
@@ -51,17 +64,15 @@ pub(super) fn hints(
51
64
( true , false ) => "&" ,
52
65
_ => return ,
53
66
} ;
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) ;
64
71
} ) ;
72
+ hint. pad_right = was_mut_last;
73
+ if !hint. label . parts . is_empty ( ) {
74
+ acc. push ( hint) ;
75
+ }
65
76
match pat {
66
77
ast:: Pat :: IdentPat ( pat) if pat. ref_token ( ) . is_none ( ) && pat. mut_token ( ) . is_none ( ) => {
67
78
let bm = sema. binding_mode_of_pat ( pat) ?;
@@ -117,6 +128,13 @@ fn __(
117
128
(x,): &mut (u32,)
118
129
//^^^^&mut
119
130
//^ ref mut
131
+ (x,): &mut &mut (u32,)
132
+ //^^^^&mut &mut
133
+ //^ ref mut
134
+ (x,): &&(u32,)
135
+ //^^^^&&
136
+ //^ ref
137
+
120
138
) {
121
139
let (x,) = (0,);
122
140
let (x,) = &(0,);
0 commit comments