diff options
| author | bors <bors@rust-lang.org> | 2025-05-11 09:22:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-05-11 09:22:50 +0000 |
| commit | 16c1c54a2921d5ace22e4a71c0ba7d4ef4b8aec7 (patch) | |
| tree | ee1976f371fa411a6fa71321f9e21d4c0f81ff48 | |
| parent | 9a7e19f2b66c472811b4bff02695c7a03f3f4151 (diff) | |
| parent | 13178c75cea866d3a84a570b9ae984508c2127db (diff) | |
| download | rust-16c1c54a2921d5ace22e4a71c0ba7d4ef4b8aec7.tar.gz rust-16c1c54a2921d5ace22e4a71c0ba7d4ef4b8aec7.zip | |
Auto merge of #140902 - azhogin:azhogin/async-drop-open-drop-for-adt-fix, r=oli-obk
Async drop fix for async_drop_in_place<T> layout for unspecified T
Fix for https://github.com/rust-lang/rust/issues/140423.
Layout of `async_drop_in_place<T>::{closure}` is calculated for unspecified T from dataflow_const_prop `try_make_constant`.
`@oli-obk,` do you think, it may be a better solution to add check like `if !args[0].is_fully_specialized() { return None; }` in `fn async_drop_coroutine_layout`?
And could you, pls, recommend, how to implement `is_fully_specialized()` in a most simple way?
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 3 | ||||
| -rw-r--r-- | tests/ui/async-await/async-drop/open-drop-error.rs | 21 |
2 files changed, 24 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 2d69a1c2b55..dda0faa3afe 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1924,6 +1924,9 @@ impl<'tcx> TyCtxt<'tcx> { def_id: DefId, args: GenericArgsRef<'tcx>, ) -> Option<&'tcx CoroutineLayout<'tcx>> { + if args[0].has_placeholders() || args[0].has_non_region_param() { + return None; + } let instance = InstanceKind::AsyncDropGlue(def_id, Ty::new_coroutine(self, def_id, args)); self.mir_shims(instance).coroutine_layout_raw() } diff --git a/tests/ui/async-await/async-drop/open-drop-error.rs b/tests/ui/async-await/async-drop/open-drop-error.rs new file mode 100644 index 00000000000..1d97eee5210 --- /dev/null +++ b/tests/ui/async-await/async-drop/open-drop-error.rs @@ -0,0 +1,21 @@ +//@ compile-flags: -Zmir-enable-passes=+DataflowConstProp +//@ edition: 2021 +//@ build-pass +#![feature(async_drop)] +#![allow(incomplete_features)] + +use std::mem::ManuallyDrop; +use std::{ + future::async_drop_in_place, + pin::{pin, Pin}, +}; +fn main() { + a(b) +} +fn b() {} +fn a<C>(d: C) { + let e = pin!(ManuallyDrop::new(d)); + let f = unsafe { Pin::map_unchecked_mut(e, |g| &mut **g) }; + let h = unsafe { async_drop_in_place(f.get_unchecked_mut()) }; + h; +} |
