@@ -2207,51 +2207,33 @@ impl Function {
22072207 db. function_data ( self . id ) . is_async ( )
22082208 }
22092209
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 ;
22142213 }
22152214
22162215 let Some ( impl_traits) = self . ret_type ( db) . as_impl_traits ( db) else { return false } ;
2217-
22182216 let Some ( future_trait_id) =
22192217 db. lang_item ( self . ty ( db) . env . krate , LangItem :: Future ) . and_then ( |t| t. as_trait ( ) )
22202218 else {
22212219 return false ;
22222220 } ;
2223-
2224- let Some ( size_trait_id) =
2221+ let Some ( sized_trait_id) =
22252222 db. lang_item ( self . ty ( db) . env . krate , LangItem :: Sized ) . and_then ( |t| t. as_trait ( ) )
22262223 else {
22272224 return false ;
22282225 } ;
22292226
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-
22442227 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
22552237 }
22562238
22572239 /// Does this function have `#[test]` attribute?
0 commit comments