@@ -99,6 +99,9 @@ fn get_chaining_hints(
9999 return None ;
100100 }
101101
102+ let krate = sema. scope ( expr. syntax ( ) ) . module ( ) . map ( |it| it. krate ( ) ) ;
103+ let famous_defs = FamousDefs ( & sema, krate) ;
104+
102105 let mut tokens = expr
103106 . syntax ( )
104107 . siblings_with_tokens ( Direction :: Next )
@@ -128,7 +131,7 @@ fn get_chaining_hints(
128131 acc. push ( InlayHint {
129132 range : expr. syntax ( ) . text_range ( ) ,
130133 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 ( || {
132135 ty. display_truncated ( sema. db , config. max_length ) . to_string ( ) . into ( )
133136 } ) ,
134137 } ) ;
@@ -188,6 +191,9 @@ fn get_bind_pat_hints(
188191 return None ;
189192 }
190193
194+ let krate = sema. scope ( pat. syntax ( ) ) . module ( ) . map ( |it| it. krate ( ) ) ;
195+ let famous_defs = FamousDefs ( & sema, krate) ;
196+
191197 let ty = sema. type_of_pat ( & pat. clone ( ) . into ( ) ) ?;
192198
193199 if should_not_display_type_hint ( sema, & pat, & ty) {
@@ -196,7 +202,7 @@ fn get_bind_pat_hints(
196202 acc. push ( InlayHint {
197203 range : pat. syntax ( ) . text_range ( ) ,
198204 kind : InlayKind :: TypeHint ,
199- label : hint_iterator ( sema, config, & ty)
205+ label : hint_iterator ( sema, & famous_defs , config, & ty)
200206 . unwrap_or_else ( || ty. display_truncated ( sema. db , config. max_length ) . to_string ( ) . into ( ) ) ,
201207 } ) ;
202208
@@ -206,6 +212,7 @@ fn get_bind_pat_hints(
206212/// Checks if the type is an Iterator from std::iter and replaces its hint with an `impl Iterator<Item = Ty>`.
207213fn hint_iterator (
208214 sema : & Semantics < RootDatabase > ,
215+ famous_defs : & FamousDefs ,
209216 config : & InlayHintsConfig ,
210217 ty : & hir:: Type ,
211218) -> Option < SmolStr > {
@@ -214,11 +221,11 @@ fn hint_iterator(
214221 . last ( )
215222 . and_then ( |strukt| strukt. as_adt ( ) ) ?;
216223 let krate = strukt. krate ( db) ?;
217- if krate. display_name ( db ) . as_deref ( ) != Some ( " core" ) {
224+ if krate != famous_defs . core ( ) ? {
218225 return None ;
219226 }
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 ( ) ?;
222229 // assert this struct comes from `core::iter`
223230 iter_mod. visibility_of ( db, & strukt. into ( ) ) . filter ( |& vis| vis == hir:: Visibility :: Public ) ?;
224231 if ty. impls_trait ( db, iter_trait, & [ ] ) {
@@ -230,7 +237,7 @@ fn hint_iterator(
230237 const LABEL_START : & str = "impl Iterator<Item = " ;
231238 const LABEL_END : & str = ">" ;
232239
233- let ty_display = hint_iterator ( sema, config, & ty)
240+ let ty_display = hint_iterator ( sema, famous_defs , config, & ty)
234241 . map ( |assoc_type_impl| assoc_type_impl. to_string ( ) )
235242 . unwrap_or_else ( || {
236243 ty. display_truncated (
0 commit comments