1
1
use assists:: utils:: FamousDefs ;
2
- use hir:: { known, Adt , AssocItem , Callable , HirDisplay , Semantics , Type } ;
2
+ use hir:: { known, HirDisplay , Semantics } ;
3
3
use ide_db:: RootDatabase ;
4
4
use stdx:: to_lower_snake_case;
5
5
use syntax:: {
@@ -120,7 +120,7 @@ fn get_chaining_hints(
120
120
return None ;
121
121
}
122
122
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 ( ) {
124
124
if st. fields ( sema. db ) . is_empty ( ) {
125
125
return None ;
126
126
}
@@ -208,7 +208,7 @@ fn get_bind_pat_hints(
208
208
fn hint_iterator (
209
209
sema : & Semantics < RootDatabase > ,
210
210
config : & InlayHintsConfig ,
211
- ty : & Type ,
211
+ ty : & hir :: Type ,
212
212
) -> Option < SmolStr > {
213
213
let db = sema. db ;
214
214
let strukt = std:: iter:: successors ( Some ( ty. clone ( ) ) , |ty| ty. remove_ref ( ) )
@@ -218,17 +218,13 @@ fn hint_iterator(
218
218
if krate. declaration_name ( db) . as_deref ( ) != Some ( "core" ) {
219
219
return None ;
220
220
}
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) ) ?;
228
221
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 ) ?;
229
225
if ty. impls_trait ( db, iter_trait, & [ ] ) {
230
226
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) ,
232
228
_ => None ,
233
229
} ) ?;
234
230
if let Some ( ty) = ty. normalize_trait_assoc_type ( db, iter_trait, & [ ] , assoc_type_item) {
@@ -248,8 +244,8 @@ fn hint_iterator(
248
244
None
249
245
}
250
246
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 ( ) {
253
249
let pat_text = bind_pat. to_string ( ) ;
254
250
enum_data
255
251
. variants ( db)
@@ -264,15 +260,15 @@ fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::IdentPat, pat_ty: &Typ
264
260
fn should_not_display_type_hint (
265
261
sema : & Semantics < RootDatabase > ,
266
262
bind_pat : & ast:: IdentPat ,
267
- pat_ty : & Type ,
263
+ pat_ty : & hir :: Type ,
268
264
) -> bool {
269
265
let db = sema. db ;
270
266
271
267
if pat_ty. is_unknown ( ) {
272
268
return true ;
273
269
}
274
270
275
- if let Some ( Adt :: Struct ( s) ) = pat_ty. as_adt ( ) {
271
+ if let Some ( hir :: Adt :: Struct ( s) ) = pat_ty. as_adt ( ) {
276
272
if s. fields ( db) . is_empty ( ) && s. name ( db) . to_string ( ) == bind_pat. to_string ( ) {
277
273
return true ;
278
274
}
@@ -316,7 +312,7 @@ fn should_not_display_type_hint(
316
312
317
313
fn should_show_param_name_hint (
318
314
sema : & Semantics < RootDatabase > ,
319
- callable : & Callable ,
315
+ callable : & hir :: Callable ,
320
316
param_name : & str ,
321
317
argument : & ast:: Expr ,
322
318
) -> bool {
@@ -363,7 +359,7 @@ fn is_enum_name_similar_to_param_name(
363
359
param_name : & str ,
364
360
) -> bool {
365
361
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,
367
363
_ => false ,
368
364
}
369
365
}
@@ -384,7 +380,7 @@ fn is_obvious_param(param_name: &str) -> bool {
384
380
param_name. len ( ) == 1 || is_obvious_param_name
385
381
}
386
382
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 > {
388
384
match expr {
389
385
ast:: Expr :: CallExpr ( expr) => sema. type_of_expr ( & expr. expr ( ) ?) ?. as_callable ( sema. db ) ,
390
386
ast:: Expr :: MethodCallExpr ( expr) => sema. resolve_method_call_as_callable ( expr) ,
0 commit comments