@@ -2207,51 +2207,33 @@ impl Function {
2207
2207
db. function_data ( self . id ) . is_async ( )
2208
2208
}
2209
2209
2210
- /// Whether this function is a `fn` that returns `impl Future`.
2211
- pub fn is_desugar_async ( self , db : & dyn HirDatabase ) -> bool {
2212
- if self . is_async ( db) || self . is_const ( db) {
2213
- return false ;
2210
+ pub fn returns_impl_future ( self , db : & dyn HirDatabase ) -> bool {
2211
+ if self . is_async ( db) {
2212
+ return true ;
2214
2213
}
2215
2214
2216
2215
let Some ( impl_traits) = self . ret_type ( db) . as_impl_traits ( db) else { return false } ;
2217
-
2218
2216
let Some ( future_trait_id) =
2219
2217
db. lang_item ( self . ty ( db) . env . krate , LangItem :: Future ) . and_then ( |t| t. as_trait ( ) )
2220
2218
else {
2221
2219
return false ;
2222
2220
} ;
2223
-
2224
- let Some ( size_trait_id) =
2221
+ let Some ( sized_trait_id) =
2225
2222
db. lang_item ( self . ty ( db) . env . krate , LangItem :: Sized ) . and_then ( |t| t. as_trait ( ) )
2226
2223
else {
2227
2224
return false ;
2228
2225
} ;
2229
2226
2230
- let Some ( sync_trait_id) =
2231
- db. lang_item ( self . ty ( db) . env . krate , LangItem :: Sync ) . and_then ( |t| t. as_trait ( ) )
2232
- else {
2233
- return false ;
2234
- } ;
2235
-
2236
- // TODO: There's no `LangItem::Send`. How do we get the id of `Send` trait?
2237
- // let Some(send_trait_id) = db.lang_item(self.ty(db).env.krate, LangItem::Send).and_then(|t| t.as_trait()) else {
2238
- // eprint!("no future_trait_id\n");
2239
- // return false
2240
- // };
2241
-
2242
- let allowed_to_leaked_types = vec ! [ size_trait_id, sync_trait_id] ;
2243
-
2244
2227
let mut has_impl_future = false ;
2245
- let mut has_types_not_allow_to_leaked = false ;
2246
- for impl_trait in impl_traits {
2247
- if impl_trait. id == future_trait_id {
2248
- has_impl_future = true ;
2249
- } else if !allowed_to_leaked_types. contains ( & impl_trait. id ) {
2250
- has_types_not_allow_to_leaked = true ;
2251
- }
2252
- }
2253
-
2254
- has_impl_future && !has_types_not_allow_to_leaked
2228
+ impl_traits
2229
+ . filter ( |t| {
2230
+ let fut = t. id == future_trait_id;
2231
+ has_impl_future |= fut;
2232
+ !fut && t. id != sized_trait_id
2233
+ } )
2234
+ // all traits but the future trait must be auto traits
2235
+ . all ( |t| t. is_auto ( db) )
2236
+ && has_impl_future
2255
2237
}
2256
2238
2257
2239
/// Does this function have `#[test]` attribute?
0 commit comments