|
1 | 1 | use rustc_data_structures::fx::FxIndexMap; |
2 | 2 | use rustc_errors::ErrorGuaranteed; |
3 | | -use rustc_hir::OpaqueTyOrigin; |
4 | | -use rustc_hir::def::DefKind; |
5 | 3 | use rustc_hir::def_id::LocalDefId; |
6 | 4 | use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, TyCtxtInferExt as _}; |
7 | | -use rustc_infer::traits::{Obligation, ObligationCause}; |
8 | 5 | use rustc_macros::extension; |
9 | 6 | use rustc_middle::ty::visit::TypeVisitableExt; |
10 | 7 | use rustc_middle::ty::{ |
11 | 8 | self, GenericArgKind, GenericArgs, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, |
12 | 9 | TypingMode, |
13 | 10 | }; |
14 | 11 | use rustc_span::Span; |
15 | | -use rustc_trait_selection::error_reporting::InferCtxtErrorExt; |
16 | 12 | use rustc_trait_selection::traits::ObligationCtxt; |
17 | 13 | use tracing::{debug, instrument}; |
18 | 14 |
|
@@ -303,91 +299,7 @@ impl<'tcx> InferCtxt<'tcx> { |
303 | 299 | return Ty::new_error(self.tcx, e); |
304 | 300 | } |
305 | 301 |
|
306 | | - // `definition_ty` does not live in of the current inference context, |
307 | | - // so lets make sure that we don't accidentally misuse our current `infcx`. |
308 | | - match check_opaque_type_well_formed( |
309 | | - self.tcx, |
310 | | - self.next_trait_solver(), |
311 | | - opaque_type_key.def_id, |
312 | | - instantiated_ty.span, |
313 | | - definition_ty, |
314 | | - ) { |
315 | | - Ok(hidden_ty) => hidden_ty, |
316 | | - Err(guar) => Ty::new_error(self.tcx, guar), |
317 | | - } |
318 | | - } |
319 | | -} |
320 | | - |
321 | | -/// This logic duplicates most of `check_opaque_meets_bounds`. |
322 | | -/// FIXME(oli-obk): Also do region checks here and then consider removing |
323 | | -/// `check_opaque_meets_bounds` entirely. |
324 | | -fn check_opaque_type_well_formed<'tcx>( |
325 | | - tcx: TyCtxt<'tcx>, |
326 | | - next_trait_solver: bool, |
327 | | - def_id: LocalDefId, |
328 | | - definition_span: Span, |
329 | | - definition_ty: Ty<'tcx>, |
330 | | -) -> Result<Ty<'tcx>, ErrorGuaranteed> { |
331 | | - // Only check this for TAIT. RPIT already supports `tests/ui/impl-trait/nested-return-type2.rs` |
332 | | - // on stable and we'd break that. |
333 | | - let opaque_ty_hir = tcx.hir().expect_opaque_ty(def_id); |
334 | | - let OpaqueTyOrigin::TyAlias { .. } = opaque_ty_hir.origin else { |
335 | | - return Ok(definition_ty); |
336 | | - }; |
337 | | - let param_env = tcx.param_env(def_id); |
338 | | - |
339 | | - let mut parent_def_id = def_id; |
340 | | - while tcx.def_kind(parent_def_id) == DefKind::OpaqueTy { |
341 | | - parent_def_id = tcx.local_parent(parent_def_id); |
342 | | - } |
343 | | - |
344 | | - // FIXME(#132279): This should eventually use the already defined hidden types |
345 | | - // instead. Alternatively we'll entirely remove this function given we also check |
346 | | - // the opaque in `check_opaque_meets_bounds` later. |
347 | | - let infcx = tcx |
348 | | - .infer_ctxt() |
349 | | - .with_next_trait_solver(next_trait_solver) |
350 | | - .build(TypingMode::analysis_in_body(tcx, parent_def_id)); |
351 | | - let ocx = ObligationCtxt::new_with_diagnostics(&infcx); |
352 | | - let identity_args = GenericArgs::identity_for_item(tcx, def_id); |
353 | | - |
354 | | - // Require that the hidden type actually fulfills all the bounds of the opaque type, even without |
355 | | - // the bounds that the function supplies. |
356 | | - let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), identity_args); |
357 | | - ocx.eq(&ObligationCause::misc(definition_span, def_id), param_env, opaque_ty, definition_ty) |
358 | | - .map_err(|err| { |
359 | | - infcx |
360 | | - .err_ctxt() |
361 | | - .report_mismatched_types( |
362 | | - &ObligationCause::misc(definition_span, def_id), |
363 | | - param_env, |
364 | | - opaque_ty, |
365 | | - definition_ty, |
366 | | - err, |
367 | | - ) |
368 | | - .emit() |
369 | | - })?; |
370 | | - |
371 | | - // Require the hidden type to be well-formed with only the generics of the opaque type. |
372 | | - // Defining use functions may have more bounds than the opaque type, which is ok, as long as the |
373 | | - // hidden type is well formed even without those bounds. |
374 | | - let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed( |
375 | | - definition_ty.into(), |
376 | | - ))); |
377 | | - ocx.register_obligation(Obligation::misc(tcx, definition_span, def_id, param_env, predicate)); |
378 | | - |
379 | | - // Check that all obligations are satisfied by the implementation's |
380 | | - // version. |
381 | | - let errors = ocx.select_all_or_error(); |
382 | | - |
383 | | - // This is fishy, but we check it again in `check_opaque_meets_bounds`. |
384 | | - // Remove once we can prepopulate with known hidden types. |
385 | | - let _ = infcx.take_opaque_types(); |
386 | | - |
387 | | - if errors.is_empty() { |
388 | | - Ok(definition_ty) |
389 | | - } else { |
390 | | - Err(infcx.err_ctxt().report_fulfillment_errors(errors)) |
| 302 | + definition_ty |
391 | 303 | } |
392 | 304 | } |
393 | 305 |
|
|
0 commit comments