@@ -99,6 +99,9 @@ fn get_chaining_hints(
99
99
return None ;
100
100
}
101
101
102
+ let krate = sema. scope ( expr. syntax ( ) ) . module ( ) . map ( |it| it. krate ( ) ) ;
103
+ let famous_defs = FamousDefs ( & sema, krate) ;
104
+
102
105
let mut tokens = expr
103
106
. syntax ( )
104
107
. siblings_with_tokens ( Direction :: Next )
@@ -128,7 +131,7 @@ fn get_chaining_hints(
128
131
acc. push ( InlayHint {
129
132
range : expr. syntax ( ) . text_range ( ) ,
130
133
kind : InlayKind :: ChainingHint ,
131
- label : hint_iterator ( sema, config, & ty) . unwrap_or_else ( || {
134
+ label : hint_iterator ( sema, & famous_defs , config, & ty) . unwrap_or_else ( || {
132
135
ty. display_truncated ( sema. db , config. max_length ) . to_string ( ) . into ( )
133
136
} ) ,
134
137
} ) ;
@@ -188,6 +191,9 @@ fn get_bind_pat_hints(
188
191
return None ;
189
192
}
190
193
194
+ let krate = sema. scope ( pat. syntax ( ) ) . module ( ) . map ( |it| it. krate ( ) ) ;
195
+ let famous_defs = FamousDefs ( & sema, krate) ;
196
+
191
197
let ty = sema. type_of_pat ( & pat. clone ( ) . into ( ) ) ?;
192
198
193
199
if should_not_display_type_hint ( sema, & pat, & ty) {
@@ -196,7 +202,7 @@ fn get_bind_pat_hints(
196
202
acc. push ( InlayHint {
197
203
range : pat. syntax ( ) . text_range ( ) ,
198
204
kind : InlayKind :: TypeHint ,
199
- label : hint_iterator ( sema, config, & ty)
205
+ label : hint_iterator ( sema, & famous_defs , config, & ty)
200
206
. unwrap_or_else ( || ty. display_truncated ( sema. db , config. max_length ) . to_string ( ) . into ( ) ) ,
201
207
} ) ;
202
208
@@ -206,6 +212,7 @@ fn get_bind_pat_hints(
206
212
/// Checks if the type is an Iterator from std::iter and replaces its hint with an `impl Iterator<Item = Ty>`.
207
213
fn hint_iterator (
208
214
sema : & Semantics < RootDatabase > ,
215
+ famous_defs : & FamousDefs ,
209
216
config : & InlayHintsConfig ,
210
217
ty : & hir:: Type ,
211
218
) -> Option < SmolStr > {
@@ -214,11 +221,11 @@ fn hint_iterator(
214
221
. last ( )
215
222
. and_then ( |strukt| strukt. as_adt ( ) ) ?;
216
223
let krate = strukt. krate ( db) ?;
217
- if krate. display_name ( db ) . as_deref ( ) != Some ( " core" ) {
224
+ if krate != famous_defs . core ( ) ? {
218
225
return None ;
219
226
}
220
- let iter_trait = FamousDefs ( sema , krate ) . core_iter_Iterator ( ) ?;
221
- let iter_mod = FamousDefs ( sema , krate ) . core_iter ( ) ?;
227
+ let iter_trait = famous_defs . core_iter_Iterator ( ) ?;
228
+ let iter_mod = famous_defs . core_iter ( ) ?;
222
229
// assert this struct comes from `core::iter`
223
230
iter_mod. visibility_of ( db, & strukt. into ( ) ) . filter ( |& vis| vis == hir:: Visibility :: Public ) ?;
224
231
if ty. impls_trait ( db, iter_trait, & [ ] ) {
@@ -230,7 +237,7 @@ fn hint_iterator(
230
237
const LABEL_START : & str = "impl Iterator<Item = " ;
231
238
const LABEL_END : & str = ">" ;
232
239
233
- let ty_display = hint_iterator ( sema, config, & ty)
240
+ let ty_display = hint_iterator ( sema, famous_defs , config, & ty)
234
241
. map ( |assoc_type_impl| assoc_type_impl. to_string ( ) )
235
242
. unwrap_or_else ( || {
236
243
ty. display_truncated (
0 commit comments