11use assists:: utils:: FamousDefs ;
2- use hir:: { known, Adt , AssocItem , Callable , HirDisplay , Semantics , Type } ;
2+ use hir:: { known, HirDisplay , Semantics } ;
33use ide_db:: RootDatabase ;
44use stdx:: to_lower_snake_case;
55use syntax:: {
@@ -120,7 +120,7 @@ fn get_chaining_hints(
120120 return None ;
121121 }
122122 if matches ! ( expr, ast:: Expr :: PathExpr ( _) ) {
123- if let Some ( Adt :: Struct ( st) ) = ty. as_adt ( ) {
123+ if let Some ( hir :: Adt :: Struct ( st) ) = ty. as_adt ( ) {
124124 if st. fields ( sema. db ) . is_empty ( ) {
125125 return None ;
126126 }
@@ -208,7 +208,7 @@ fn get_bind_pat_hints(
208208fn hint_iterator (
209209 sema : & Semantics < RootDatabase > ,
210210 config : & InlayHintsConfig ,
211- ty : & Type ,
211+ ty : & hir :: Type ,
212212) -> Option < SmolStr > {
213213 let db = sema. db ;
214214 let strukt = std:: iter:: successors ( Some ( ty. clone ( ) ) , |ty| ty. remove_ref ( ) )
@@ -218,17 +218,13 @@ fn hint_iterator(
218218 if krate. declaration_name ( db) . as_deref ( ) != Some ( "core" ) {
219219 return None ;
220220 }
221- // assert this type comes from `core::iter`
222- strukt
223- . module ( db)
224- . path_to_root ( db)
225- . into_iter ( )
226- . rev ( )
227- . find ( |module| module. name ( db) == Some ( known:: iter) ) ?;
228221 let iter_trait = FamousDefs ( sema, krate) . core_iter_Iterator ( ) ?;
222+ let iter_mod = FamousDefs ( sema, krate) . core_iter ( ) ?;
223+ // assert this type comes from `core::iter`
224+ iter_mod. visibility_of ( db, & iter_trait. into ( ) ) . filter ( |& vis| vis == hir:: Visibility :: Public ) ?;
229225 if ty. impls_trait ( db, iter_trait, & [ ] ) {
230226 let assoc_type_item = iter_trait. items ( db) . into_iter ( ) . find_map ( |item| match item {
231- AssocItem :: TypeAlias ( alias) if alias. name ( db) == known:: Item => Some ( alias) ,
227+ hir :: AssocItem :: TypeAlias ( alias) if alias. name ( db) == known:: Item => Some ( alias) ,
232228 _ => None ,
233229 } ) ?;
234230 if let Some ( ty) = ty. normalize_trait_assoc_type ( db, iter_trait, & [ ] , assoc_type_item) {
@@ -248,8 +244,8 @@ fn hint_iterator(
248244 None
249245}
250246
251- fn pat_is_enum_variant ( db : & RootDatabase , bind_pat : & ast:: IdentPat , pat_ty : & Type ) -> bool {
252- if let Some ( Adt :: Enum ( enum_data) ) = pat_ty. as_adt ( ) {
247+ fn pat_is_enum_variant ( db : & RootDatabase , bind_pat : & ast:: IdentPat , pat_ty : & hir :: Type ) -> bool {
248+ if let Some ( hir :: Adt :: Enum ( enum_data) ) = pat_ty. as_adt ( ) {
253249 let pat_text = bind_pat. to_string ( ) ;
254250 enum_data
255251 . variants ( db)
@@ -264,15 +260,15 @@ fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::IdentPat, pat_ty: &Typ
264260fn should_not_display_type_hint (
265261 sema : & Semantics < RootDatabase > ,
266262 bind_pat : & ast:: IdentPat ,
267- pat_ty : & Type ,
263+ pat_ty : & hir :: Type ,
268264) -> bool {
269265 let db = sema. db ;
270266
271267 if pat_ty. is_unknown ( ) {
272268 return true ;
273269 }
274270
275- if let Some ( Adt :: Struct ( s) ) = pat_ty. as_adt ( ) {
271+ if let Some ( hir :: Adt :: Struct ( s) ) = pat_ty. as_adt ( ) {
276272 if s. fields ( db) . is_empty ( ) && s. name ( db) . to_string ( ) == bind_pat. to_string ( ) {
277273 return true ;
278274 }
@@ -316,7 +312,7 @@ fn should_not_display_type_hint(
316312
317313fn should_show_param_name_hint (
318314 sema : & Semantics < RootDatabase > ,
319- callable : & Callable ,
315+ callable : & hir :: Callable ,
320316 param_name : & str ,
321317 argument : & ast:: Expr ,
322318) -> bool {
@@ -363,7 +359,7 @@ fn is_enum_name_similar_to_param_name(
363359 param_name : & str ,
364360) -> bool {
365361 match sema. type_of_expr ( argument) . and_then ( |t| t. as_adt ( ) ) {
366- Some ( Adt :: Enum ( e) ) => to_lower_snake_case ( & e. name ( sema. db ) . to_string ( ) ) == param_name,
362+ Some ( hir :: Adt :: Enum ( e) ) => to_lower_snake_case ( & e. name ( sema. db ) . to_string ( ) ) == param_name,
367363 _ => false ,
368364 }
369365}
@@ -384,7 +380,7 @@ fn is_obvious_param(param_name: &str) -> bool {
384380 param_name. len ( ) == 1 || is_obvious_param_name
385381}
386382
387- fn get_callable ( sema : & Semantics < RootDatabase > , expr : & ast:: Expr ) -> Option < Callable > {
383+ fn get_callable ( sema : & Semantics < RootDatabase > , expr : & ast:: Expr ) -> Option < hir :: Callable > {
388384 match expr {
389385 ast:: Expr :: CallExpr ( expr) => sema. type_of_expr ( & expr. expr ( ) ?) ?. as_callable ( sema. db ) ,
390386 ast:: Expr :: MethodCallExpr ( expr) => sema. resolve_method_call_as_callable ( expr) ,
0 commit comments