@@ -239,15 +239,14 @@ impl InherentImpls {
239239 }
240240}
241241
242- impl Ty {
243- pub fn def_crates (
244- & self ,
245- db : & dyn HirDatabase ,
246- cur_crate : CrateId ,
247- ) -> Option < ArrayVec < CrateId , 2 > > {
248- // Types like slice can have inherent impls in several crates, (core and alloc).
249- // The corresponding impls are marked with lang items, so we can use them to find the required crates.
250- macro_rules! lang_item_crate {
242+ pub fn def_crates (
243+ db : & dyn HirDatabase ,
244+ ty : & Ty ,
245+ cur_crate : CrateId ,
246+ ) -> Option < ArrayVec < CrateId , 2 > > {
247+ // Types like slice can have inherent impls in several crates, (core and alloc).
248+ // The corresponding impls are marked with lang items, so we can use them to find the required crates.
249+ macro_rules! lang_item_crate {
251250 ( $( $name: expr) ,+ $( , ) ?) => { {
252251 let mut v = ArrayVec :: <LangItemTarget , 2 >:: new( ) ;
253252 $(
@@ -257,51 +256,50 @@ impl Ty {
257256 } } ;
258257 }
259258
260- let mod_to_crate_ids = |module : ModuleId | Some ( std:: iter:: once ( module. krate ( ) ) . collect ( ) ) ;
259+ let mod_to_crate_ids = |module : ModuleId | Some ( std:: iter:: once ( module. krate ( ) ) . collect ( ) ) ;
261260
262- let lang_item_targets = match self . kind ( & Interner ) {
263- TyKind :: Adt ( AdtId ( def_id) , _) => {
264- return mod_to_crate_ids ( def_id. module ( db. upcast ( ) ) ) ;
265- }
266- TyKind :: Foreign ( id) => {
267- return mod_to_crate_ids (
268- from_foreign_def_id ( * id) . lookup ( db. upcast ( ) ) . module ( db. upcast ( ) ) ,
269- ) ;
270- }
271- TyKind :: Scalar ( Scalar :: Bool ) => lang_item_crate ! ( "bool" ) ,
272- TyKind :: Scalar ( Scalar :: Char ) => lang_item_crate ! ( "char" ) ,
273- TyKind :: Scalar ( Scalar :: Float ( f) ) => match f {
274- // There are two lang items: one in libcore (fXX) and one in libstd (fXX_runtime)
275- FloatTy :: F32 => lang_item_crate ! ( "f32" , "f32_runtime" ) ,
276- FloatTy :: F64 => lang_item_crate ! ( "f64" , "f64_runtime" ) ,
277- } ,
278- & TyKind :: Scalar ( Scalar :: Int ( t) ) => {
279- lang_item_crate ! ( primitive:: int_ty_to_string( t) )
280- }
281- & TyKind :: Scalar ( Scalar :: Uint ( t) ) => {
282- lang_item_crate ! ( primitive:: uint_ty_to_string( t) )
283- }
284- TyKind :: Str => lang_item_crate ! ( "str_alloc" , "str" ) ,
285- TyKind :: Slice ( _) => lang_item_crate ! ( "slice_alloc" , "slice" ) ,
286- TyKind :: Raw ( Mutability :: Not , _) => lang_item_crate ! ( "const_ptr" ) ,
287- TyKind :: Raw ( Mutability :: Mut , _) => lang_item_crate ! ( "mut_ptr" ) ,
288- TyKind :: Dyn ( _) => {
289- return self . dyn_trait ( ) . and_then ( |trait_| {
290- mod_to_crate_ids ( GenericDefId :: TraitId ( trait_) . module ( db. upcast ( ) ) )
291- } ) ;
292- }
293- _ => return None ,
294- } ;
295- let res = lang_item_targets
296- . into_iter ( )
297- . filter_map ( |it| match it {
298- LangItemTarget :: ImplDefId ( it) => Some ( it) ,
299- _ => None ,
300- } )
301- . map ( |it| it. lookup ( db. upcast ( ) ) . container . krate ( ) )
302- . collect ( ) ;
303- Some ( res)
304- }
261+ let lang_item_targets = match ty. kind ( & Interner ) {
262+ TyKind :: Adt ( AdtId ( def_id) , _) => {
263+ return mod_to_crate_ids ( def_id. module ( db. upcast ( ) ) ) ;
264+ }
265+ TyKind :: Foreign ( id) => {
266+ return mod_to_crate_ids (
267+ from_foreign_def_id ( * id) . lookup ( db. upcast ( ) ) . module ( db. upcast ( ) ) ,
268+ ) ;
269+ }
270+ TyKind :: Scalar ( Scalar :: Bool ) => lang_item_crate ! ( "bool" ) ,
271+ TyKind :: Scalar ( Scalar :: Char ) => lang_item_crate ! ( "char" ) ,
272+ TyKind :: Scalar ( Scalar :: Float ( f) ) => match f {
273+ // There are two lang items: one in libcore (fXX) and one in libstd (fXX_runtime)
274+ FloatTy :: F32 => lang_item_crate ! ( "f32" , "f32_runtime" ) ,
275+ FloatTy :: F64 => lang_item_crate ! ( "f64" , "f64_runtime" ) ,
276+ } ,
277+ & TyKind :: Scalar ( Scalar :: Int ( t) ) => {
278+ lang_item_crate ! ( primitive:: int_ty_to_string( t) )
279+ }
280+ & TyKind :: Scalar ( Scalar :: Uint ( t) ) => {
281+ lang_item_crate ! ( primitive:: uint_ty_to_string( t) )
282+ }
283+ TyKind :: Str => lang_item_crate ! ( "str_alloc" , "str" ) ,
284+ TyKind :: Slice ( _) => lang_item_crate ! ( "slice_alloc" , "slice" ) ,
285+ TyKind :: Raw ( Mutability :: Not , _) => lang_item_crate ! ( "const_ptr" ) ,
286+ TyKind :: Raw ( Mutability :: Mut , _) => lang_item_crate ! ( "mut_ptr" ) ,
287+ TyKind :: Dyn ( _) => {
288+ return ty. dyn_trait ( ) . and_then ( |trait_| {
289+ mod_to_crate_ids ( GenericDefId :: TraitId ( trait_) . module ( db. upcast ( ) ) )
290+ } ) ;
291+ }
292+ _ => return None ,
293+ } ;
294+ let res = lang_item_targets
295+ . into_iter ( )
296+ . filter_map ( |it| match it {
297+ LangItemTarget :: ImplDefId ( it) => Some ( it) ,
298+ _ => None ,
299+ } )
300+ . map ( |it| it. lookup ( db. upcast ( ) ) . container . krate ( ) )
301+ . collect ( ) ;
302+ Some ( res)
305303}
306304
307305/// Look up the method with the given name, returning the actual autoderefed
@@ -628,7 +626,7 @@ fn iterate_inherent_methods(
628626 visible_from_module : Option < ModuleId > ,
629627 callback : & mut dyn FnMut ( & Ty , AssocItemId ) -> bool ,
630628) -> bool {
631- let def_crates = match self_ty . value . def_crates ( db, krate) {
629+ let def_crates = match def_crates ( db, & self_ty . value , krate) {
632630 Some ( k) => k,
633631 None => return false ,
634632 } ;
0 commit comments