@@ -6,9 +6,10 @@ use std::sync::Arc;
6
6
7
7
use arrayvec:: ArrayVec ;
8
8
use hir_def:: {
9
- lang_item:: LangItemTarget , resolver:: HasResolver , resolver:: Resolver , AssocItemId , AstItemDef ,
10
- HasModule , ImplId , TraitId ,
9
+ lang_item:: LangItemTarget , resolver:: HasResolver , resolver:: Resolver , type_ref :: Mutability ,
10
+ AssocItemId , AstItemDef , HasModule , ImplId , TraitId ,
11
11
} ;
12
+ use hir_expand:: name:: Name ;
12
13
use ra_db:: CrateId ;
13
14
use ra_prof:: profile;
14
15
use rustc_hash:: FxHashMap ;
@@ -17,7 +18,7 @@ use crate::{
17
18
db:: HirDatabase ,
18
19
ty:: primitive:: { FloatBitness , Uncertain } ,
19
20
ty:: { utils:: all_super_traits, Ty , TypeCtor } ,
20
- AssocItem , Crate , Function , Mutability , Name , Trait ,
21
+ AssocItem , Function ,
21
22
} ;
22
23
23
24
use super :: { autoderef, Canonical , InEnvironment , TraitEnvironment , TraitRef } ;
@@ -87,23 +88,27 @@ impl CrateImplBlocks {
87
88
fingerprint. and_then ( |f| self . impls . get ( & f) ) . into_iter ( ) . flatten ( ) . copied ( )
88
89
}
89
90
90
- pub fn lookup_impl_blocks_for_trait ( & self , tr : Trait ) -> impl Iterator < Item = ImplId > + ' _ {
91
- self . impls_by_trait . get ( & tr. id ) . into_iter ( ) . flatten ( ) . copied ( )
91
+ pub fn lookup_impl_blocks_for_trait ( & self , tr : TraitId ) -> impl Iterator < Item = ImplId > + ' _ {
92
+ self . impls_by_trait . get ( & tr) . into_iter ( ) . flatten ( ) . copied ( )
92
93
}
93
94
94
95
pub fn all_impls < ' a > ( & ' a self ) -> impl Iterator < Item = ImplId > + ' a {
95
96
self . impls . values ( ) . chain ( self . impls_by_trait . values ( ) ) . flatten ( ) . copied ( )
96
97
}
97
98
}
98
99
99
- fn def_crates ( db : & impl HirDatabase , cur_crate : Crate , ty : & Ty ) -> Option < ArrayVec < [ Crate ; 2 ] > > {
100
+ fn def_crates (
101
+ db : & impl HirDatabase ,
102
+ cur_crate : CrateId ,
103
+ ty : & Ty ,
104
+ ) -> Option < ArrayVec < [ CrateId ; 2 ] > > {
100
105
// Types like slice can have inherent impls in several crates, (core and alloc).
101
106
// The corresponding impls are marked with lang items, so we can use them to find the required crates.
102
107
macro_rules! lang_item_crate {
103
108
( $( $name: expr) ,+ $( , ) ?) => { {
104
109
let mut v = ArrayVec :: <[ LangItemTarget ; 2 ] >:: new( ) ;
105
110
$(
106
- v. extend( db. lang_item( cur_crate. crate_id , $name. into( ) ) ) ;
111
+ v. extend( db. lang_item( cur_crate, $name. into( ) ) ) ;
107
112
) +
108
113
v
109
114
} } ;
@@ -112,7 +117,7 @@ fn def_crates(db: &impl HirDatabase, cur_crate: Crate, ty: &Ty) -> Option<ArrayV
112
117
let lang_item_targets = match ty {
113
118
Ty :: Apply ( a_ty) => match a_ty. ctor {
114
119
TypeCtor :: Adt ( def_id) => {
115
- return Some ( std:: iter:: once ( def_id. module ( db) . krate . into ( ) ) . collect ( ) )
120
+ return Some ( std:: iter:: once ( def_id. module ( db) . krate ) . collect ( ) )
116
121
}
117
122
TypeCtor :: Bool => lang_item_crate ! ( "bool" ) ,
118
123
TypeCtor :: Char => lang_item_crate ! ( "char" ) ,
@@ -136,7 +141,7 @@ fn def_crates(db: &impl HirDatabase, cur_crate: Crate, ty: &Ty) -> Option<ArrayV
136
141
LangItemTarget :: ImplBlockId ( it) => Some ( it) ,
137
142
_ => None ,
138
143
} )
139
- . map ( |it| it. module ( db) . krate . into ( ) )
144
+ . map ( |it| it. module ( db) . krate )
140
145
. collect ( ) ;
141
146
Some ( res)
142
147
}
@@ -193,14 +198,9 @@ pub(crate) fn iterate_method_candidates<T>(
193
198
let environment = TraitEnvironment :: lower ( db, resolver) ;
194
199
let ty = InEnvironment { value : ty. clone ( ) , environment } ;
195
200
for derefed_ty in autoderef:: autoderef ( db, resolver. krate ( ) , ty) {
196
- if let Some ( result) = iterate_inherent_methods (
197
- & derefed_ty,
198
- db,
199
- name,
200
- mode,
201
- krate. into ( ) ,
202
- & mut callback,
203
- ) {
201
+ if let Some ( result) =
202
+ iterate_inherent_methods ( & derefed_ty, db, name, mode, krate, & mut callback)
203
+ {
204
204
return Some ( result) ;
205
205
}
206
206
if let Some ( result) = iterate_trait_method_candidates (
@@ -283,11 +283,11 @@ fn iterate_inherent_methods<T>(
283
283
db : & impl HirDatabase ,
284
284
name : Option < & Name > ,
285
285
mode : LookupMode ,
286
- krate : Crate ,
286
+ krate : CrateId ,
287
287
mut callback : impl FnMut ( & Ty , AssocItem ) -> Option < T > ,
288
288
) -> Option < T > {
289
289
for krate in def_crates ( db, krate, & ty. value ) ? {
290
- let impls = db. impls_in_crate ( krate. crate_id ) ;
290
+ let impls = db. impls_in_crate ( krate) ;
291
291
292
292
for impl_block in impls. lookup_impl_blocks ( & ty. value ) {
293
293
for & item in db. impl_data ( impl_block) . items . iter ( ) {
@@ -327,7 +327,7 @@ pub(crate) fn implements_trait(
327
327
ty : & Canonical < Ty > ,
328
328
db : & impl HirDatabase ,
329
329
resolver : & Resolver ,
330
- krate : Crate ,
330
+ krate : CrateId ,
331
331
trait_ : TraitId ,
332
332
) -> bool {
333
333
if ty. value . inherent_trait ( ) == Some ( trait_) {
@@ -337,7 +337,7 @@ pub(crate) fn implements_trait(
337
337
}
338
338
let env = TraitEnvironment :: lower ( db, resolver) ;
339
339
let goal = generic_implements_goal ( db, env, trait_, ty. clone ( ) ) ;
340
- let solution = db. trait_solve ( krate, goal) ;
340
+ let solution = db. trait_solve ( krate. into ( ) , goal) ;
341
341
342
342
solution. is_some ( )
343
343
}
@@ -348,11 +348,11 @@ impl Ty {
348
348
pub fn iterate_impl_items < T > (
349
349
self ,
350
350
db : & impl HirDatabase ,
351
- krate : Crate ,
351
+ krate : CrateId ,
352
352
mut callback : impl FnMut ( AssocItem ) -> Option < T > ,
353
353
) -> Option < T > {
354
354
for krate in def_crates ( db, krate, & self ) ? {
355
- let impls = db. impls_in_crate ( krate. crate_id ) ;
355
+ let impls = db. impls_in_crate ( krate) ;
356
356
357
357
for impl_block in impls. lookup_impl_blocks ( & self ) {
358
358
for & item in db. impl_data ( impl_block) . items . iter ( ) {
0 commit comments