|
1 | 1 | use std::{fmt, iter, mem}; |
2 | 2 |
|
3 | 3 | use rustc_abi::{FIRST_VARIANT, FieldIdx, VariantIdx}; |
4 | | -use rustc_hir::def::DefKind; |
5 | 4 | use rustc_hir::lang_items::LangItem; |
6 | 5 | use rustc_index::Idx; |
7 | 6 | use rustc_middle::mir::*; |
8 | 7 | use rustc_middle::ty::adjustment::PointerCoercion; |
9 | 8 | use rustc_middle::ty::util::IntTypeExt; |
10 | 9 | use rustc_middle::ty::{self, GenericArg, GenericArgsRef, Ty, TyCtxt}; |
11 | | -use rustc_middle::{bug, span_bug, traits}; |
| 10 | +use rustc_middle::{bug, span_bug}; |
12 | 11 | use rustc_span::{DUMMY_SP, Spanned, dummy_spanned}; |
13 | 12 | use tracing::{debug, instrument}; |
14 | 13 |
|
@@ -218,65 +217,20 @@ where |
218 | 217 | let tcx = self.tcx(); |
219 | 218 | let span = self.source_info.span; |
220 | 219 |
|
221 | | - let (fut_ty, drop_fn_def_id, trait_args) = if call_destructor_only { |
| 220 | + let async_drop_fn_def_id = if call_destructor_only { |
222 | 221 | // Resolving obj.<AsyncDrop::drop>() |
223 | | - let trait_ref = |
224 | | - ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::AsyncDrop, span), [drop_ty]); |
225 | | - let (drop_trait, trait_args) = match tcx.codegen_select_candidate( |
226 | | - ty::TypingEnv::fully_monomorphized().as_query_input(trait_ref), |
227 | | - ) { |
228 | | - Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData { |
229 | | - impl_def_id, |
230 | | - args, |
231 | | - .. |
232 | | - })) => (*impl_def_id, *args), |
233 | | - impl_source => { |
234 | | - span_bug!(span, "invalid `AsyncDrop` impl_source: {:?}", impl_source); |
235 | | - } |
236 | | - }; |
237 | | - // impl_item_refs may be empty if drop fn is not implemented in 'impl AsyncDrop for ...' |
238 | | - // (#140974). |
239 | | - // Such code will report error, so just generate sync drop here and return |
240 | | - let Some(drop_fn_def_id) = |
241 | | - tcx.associated_item_def_ids(drop_trait).first().and_then(|&def_id| { |
242 | | - if tcx.def_kind(def_id) == DefKind::AssocFn |
243 | | - && tcx.check_args_compatible(def_id, trait_args) |
244 | | - { |
245 | | - Some(def_id) |
246 | | - } else { |
247 | | - None |
248 | | - } |
249 | | - }) |
250 | | - else { |
251 | | - tcx.dcx().span_delayed_bug( |
252 | | - self.elaborator.body().span, |
253 | | - "AsyncDrop type without correct `async fn drop(...)`.", |
254 | | - ); |
255 | | - return self.new_block( |
256 | | - unwind, |
257 | | - TerminatorKind::Drop { |
258 | | - place, |
259 | | - target: succ, |
260 | | - unwind: unwind.into_action(), |
261 | | - replace: false, |
262 | | - drop: None, |
263 | | - async_fut: None, |
264 | | - }, |
265 | | - ); |
266 | | - }; |
267 | | - let drop_fn = Ty::new_fn_def(tcx, drop_fn_def_id, trait_args); |
268 | | - let sig = drop_fn.fn_sig(tcx); |
269 | | - let sig = tcx.instantiate_bound_regions_with_erased(sig); |
270 | | - (sig.output(), drop_fn_def_id, trait_args) |
| 222 | + let async_drop_trait = tcx.require_lang_item(LangItem::AsyncDrop, span); |
| 223 | + tcx.associated_item_def_ids(async_drop_trait)[0] |
271 | 224 | } else { |
272 | 225 | // Resolving async_drop_in_place<T> function for drop_ty |
273 | | - let drop_fn_def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, span); |
274 | | - let trait_args = tcx.mk_args(&[drop_ty.into()]); |
275 | | - let sig = tcx.fn_sig(drop_fn_def_id).instantiate(tcx, trait_args).skip_norm_wip(); |
276 | | - let sig = tcx.instantiate_bound_regions_with_erased(sig); |
277 | | - (sig.output(), drop_fn_def_id, trait_args) |
| 226 | + tcx.require_lang_item(LangItem::AsyncDropInPlace, span) |
278 | 227 | }; |
279 | 228 |
|
| 229 | + let fut_ty = tcx |
| 230 | + .instantiate_bound_regions_with_erased( |
| 231 | + Ty::new_fn_def(tcx, async_drop_fn_def_id, [drop_ty]).fn_sig(tcx), |
| 232 | + ) |
| 233 | + .output(); |
280 | 234 | let fut = self.new_temp(fut_ty); |
281 | 235 |
|
282 | 236 | // #1:pin_obj_bb >>> obj_ref = &mut obj |
@@ -370,7 +324,7 @@ where |
370 | 324 | unwind, |
371 | 325 | call_statements, |
372 | 326 | TerminatorKind::Call { |
373 | | - func: Operand::function_handle(tcx, drop_fn_def_id, trait_args, span), |
| 327 | + func: Operand::function_handle(tcx, async_drop_fn_def_id, [drop_ty.into()], span), |
374 | 328 | args: [Spanned { node: Operand::Move(drop_arg), span: DUMMY_SP }].into(), |
375 | 329 | destination: fut.into(), |
376 | 330 | target: Some(drop_term_bb), |
|
0 commit comments