diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2024-09-01 11:04:45 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2024-09-01 11:22:50 +0200 |
| commit | e233c3ae22ed5b2020b8b79e97d2fe6f1da6852e (patch) | |
| tree | e44fcee93d63cb014cb786d46129d4688012a552 /src/tools/rust-analyzer/crates/hir | |
| parent | fc9ff795199f24b40a19e11735b1956462107d0c (diff) | |
| download | rust-e233c3ae22ed5b2020b8b79e97d2fe6f1da6852e.tar.gz rust-e233c3ae22ed5b2020b8b79e97d2fe6f1da6852e.zip | |
Complete desugared and resugared async fn in trait impls
Diffstat (limited to 'src/tools/rust-analyzer/crates/hir')
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir/src/lib.rs | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs index 74ec5227b0e..9536f125584 100644 --- a/src/tools/rust-analyzer/crates/hir/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs @@ -2207,51 +2207,33 @@ impl Function { db.function_data(self.id).is_async() } - /// Whether this function is a `fn` that returns `impl Future`. - pub fn is_desugar_async(self, db: &dyn HirDatabase) -> bool { - if self.is_async(db) || self.is_const(db) { - return false; + pub fn returns_impl_future(self, db: &dyn HirDatabase) -> bool { + if self.is_async(db) { + return true; } let Some(impl_traits) = self.ret_type(db).as_impl_traits(db) else { return false }; - let Some(future_trait_id) = db.lang_item(self.ty(db).env.krate, LangItem::Future).and_then(|t| t.as_trait()) else { return false; }; - - let Some(size_trait_id) = + let Some(sized_trait_id) = db.lang_item(self.ty(db).env.krate, LangItem::Sized).and_then(|t| t.as_trait()) else { return false; }; - let Some(sync_trait_id) = - db.lang_item(self.ty(db).env.krate, LangItem::Sync).and_then(|t| t.as_trait()) - else { - return false; - }; - - // TODO: There's no `LangItem::Send`. How do we get the id of `Send` trait? - // let Some(send_trait_id) = db.lang_item(self.ty(db).env.krate, LangItem::Send).and_then(|t| t.as_trait()) else { - // eprint!("no future_trait_id\n"); - // return false - // }; - - let allowed_to_leaked_types = vec![size_trait_id, sync_trait_id]; - let mut has_impl_future = false; - let mut has_types_not_allow_to_leaked = false; - for impl_trait in impl_traits { - if impl_trait.id == future_trait_id { - has_impl_future = true; - } else if !allowed_to_leaked_types.contains(&impl_trait.id) { - has_types_not_allow_to_leaked = true; - } - } - - has_impl_future && !has_types_not_allow_to_leaked + impl_traits + .filter(|t| { + let fut = t.id == future_trait_id; + has_impl_future |= fut; + !fut && t.id != sized_trait_id + }) + // all traits but the future trait must be auto traits + .all(|t| t.is_auto(db)) + && has_impl_future } /// Does this function have `#[test]` attribute? |
