@@ -17,6 +17,7 @@ pub struct InlayHintsConfig {
17
17
pub parameter_hints : bool ,
18
18
pub chaining_hints : bool ,
19
19
pub closure_return_type_hints : bool ,
20
+ // FIXME: ternary option here, on off non-noisy
20
21
pub lifetime_elision_hints : bool ,
21
22
pub hide_named_constructor_hints : bool ,
22
23
pub max_length : Option < usize > ,
@@ -135,15 +136,12 @@ fn lifetime_hints(
135
136
let ret_type = func. ret_type ( ) ;
136
137
let self_param = param_list. self_param ( ) ;
137
138
139
+ // FIXME: don't use already used lifetimenames
140
+
138
141
let mut allocated_lifetimes = vec ! [ ] ;
139
142
let mut gen_name = {
140
- let mut iter = 'a' ..;
141
- let allocated_lifetimes = & mut allocated_lifetimes;
142
- move || {
143
- if let Some ( it) = iter. next ( ) {
144
- allocated_lifetimes. push ( SmolStr :: from_iter ( [ '\'' , it] ) )
145
- }
146
- }
143
+ let mut gen = ( 'a' ..) . map ( |it| SmolStr :: from_iter ( [ '\'' , it] ) ) ;
144
+ move || gen. next ( ) . unwrap_or_else ( SmolStr :: default)
147
145
} ;
148
146
149
147
let potential_lt_refs: Vec < _ > = param_list
@@ -152,7 +150,13 @@ fn lifetime_hints(
152
150
let ty = it. ty ( ) ?;
153
151
// FIXME: look into the nested types here and check path types
154
152
match ty {
155
- ast:: Type :: RefType ( r) => Some ( r) ,
153
+ ast:: Type :: RefType ( r) => Some ( (
154
+ it. pat ( ) . and_then ( |it| match it {
155
+ ast:: Pat :: IdentPat ( p) => p. name ( ) ,
156
+ _ => None ,
157
+ } ) ,
158
+ r,
159
+ ) ) ,
156
160
_ => None ,
157
161
}
158
162
} )
@@ -180,13 +184,16 @@ fn lifetime_hints(
180
184
// allocate names
181
185
if let Some ( self_param) = & self_param {
182
186
if is_elided ( self_param. lifetime ( ) ) {
183
- gen_name ( ) ;
187
+ allocated_lifetimes . push ( SmolStr :: new_inline ( "'self" ) ) ;
184
188
}
185
189
}
186
- potential_lt_refs. iter ( ) . for_each ( |it | {
190
+ potential_lt_refs. iter ( ) . for_each ( |( name , it ) | {
187
191
// FIXME: look into the nested types here and check path types
188
192
if is_elided ( it. lifetime ( ) ) {
189
- gen_name ( ) ;
193
+ allocated_lifetimes. push (
194
+ name. as_ref ( )
195
+ . map_or_else ( || gen_name ( ) , |it| SmolStr :: from_iter ( [ "'" , it. text ( ) . as_str ( ) ] ) ) ,
196
+ ) ;
190
197
}
191
198
} ) ;
192
199
@@ -200,7 +207,7 @@ fn lifetime_hints(
200
207
}
201
208
} else {
202
209
match potential_lt_refs. as_slice ( ) {
203
- [ r ] => match fetch_lt_text ( r. lifetime ( ) ) {
210
+ [ ( _ , r ) ] => match fetch_lt_text ( r. lifetime ( ) ) {
204
211
LifetimeKind :: Elided => allocated_lifetimes. get ( 0 ) . cloned ( ) ,
205
212
LifetimeKind :: Named ( name) => Some ( name) ,
206
213
LifetimeKind :: Static => None ,
@@ -246,7 +253,7 @@ fn lifetime_hints(
246
253
0
247
254
} ;
248
255
249
- for p in potential_lt_refs. iter ( ) {
256
+ for ( _ , p ) in potential_lt_refs. iter ( ) {
250
257
if is_elided ( p. lifetime ( ) ) {
251
258
let t = p. amp_token ( ) ?;
252
259
let lt = allocated_lifetimes[ idx] . clone ( ) ;
@@ -2015,8 +2022,8 @@ fn empty_gpl<>(a: &()) {}
2015
2022
// ^'a ^'a
2016
2023
fn partial<'b>(a: &(), b: &'b ()) {}
2017
2024
// ^'a, $ ^'a
2018
- fn partial<'b >(a: &'b (), b: &()) {}
2019
- // ^'a , $ ^'a
2025
+ fn partial<'a >(a: &'a (), b: &()) {}
2026
+ // ^'b , $ ^'b
2020
2027
2021
2028
fn single_ret(a: &()) -> &() {}
2022
2029
// ^^^^^^^^^^<'a>
@@ -2030,11 +2037,11 @@ fn foo<'c>(a: &'c ()) -> &() {}
2030
2037
2031
2038
impl () {
2032
2039
fn foo(&self) -> &() {}
2033
- // ^^^<'a >
2034
- // ^'a ^'a
2040
+ // ^^^<'self >
2041
+ // ^'self ^'self
2035
2042
fn foo(&self, a: &()) -> &() {}
2036
- // ^^^<'a , 'b >
2037
- // ^'a ^'b ^'a $
2043
+ // ^^^<'self , 'a >
2044
+ // ^'self ^'a ^'self $
2038
2045
}
2039
2046
"# ,
2040
2047
) ;
0 commit comments