@@ -2,7 +2,7 @@ use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
22use super :: { DefineOpaqueTypes , InferResult } ;
33use crate :: errors:: OpaqueHiddenTypeDiag ;
44use crate :: infer:: { DefiningAnchor , InferCtxt , InferOk } ;
5- use crate :: traits;
5+ use crate :: traits:: { self , PredicateObligation } ;
66use hir:: def_id:: { DefId , LocalDefId } ;
77use hir:: OpaqueTyOrigin ;
88use rustc_data_structures:: fx:: FxIndexMap ;
@@ -48,9 +48,15 @@ impl<'tcx> InferCtxt<'tcx> {
4848 span : Span ,
4949 param_env : ty:: ParamEnv < ' tcx > ,
5050 ) -> InferOk < ' tcx , T > {
51+ // We handle opaque types differently in the new solver.
52+ if self . tcx . trait_solver_next ( ) {
53+ return InferOk { value, obligations : vec ! [ ] } ;
54+ }
55+
5156 if !value. has_opaque_types ( ) {
5257 return InferOk { value, obligations : vec ! [ ] } ;
5358 }
59+
5460 let mut obligations = vec ! [ ] ;
5561 let replace_opaque_type = |def_id : DefId | {
5662 def_id. as_local ( ) . is_some_and ( |def_id| self . opaque_type_origin ( def_id) . is_some ( ) )
@@ -521,17 +527,14 @@ impl<'tcx> InferCtxt<'tcx> {
521527 origin : hir:: OpaqueTyOrigin ,
522528 a_is_expected : bool ,
523529 ) -> InferResult < ' tcx , ( ) > {
524- let tcx = self . tcx ;
525- let OpaqueTypeKey { def_id, substs } = opaque_type_key;
526-
527530 // Ideally, we'd get the span where *this specific `ty` came
528531 // from*, but right now we just use the span from the overall
529532 // value being folded. In simple cases like `-> impl Foo`,
530533 // these are the same span, but not in cases like `-> (impl
531534 // Foo, impl Bar)`.
532535 let span = cause. span ;
533536 let prev = self . inner . borrow_mut ( ) . opaque_types ( ) . register (
534- OpaqueTypeKey { def_id , substs } ,
537+ opaque_type_key ,
535538 OpaqueHiddenType { ty : hidden_ty, span } ,
536539 origin,
537540 ) ;
@@ -543,6 +546,26 @@ impl<'tcx> InferCtxt<'tcx> {
543546 Vec :: new ( )
544547 } ;
545548
549+ self . add_item_bounds_for_hidden_type (
550+ opaque_type_key,
551+ cause,
552+ param_env,
553+ hidden_ty,
554+ & mut obligations,
555+ ) ;
556+
557+ Ok ( InferOk { value : ( ) , obligations } )
558+ }
559+
560+ pub fn add_item_bounds_for_hidden_type (
561+ & self ,
562+ OpaqueTypeKey { def_id, substs } : OpaqueTypeKey < ' tcx > ,
563+ cause : ObligationCause < ' tcx > ,
564+ param_env : ty:: ParamEnv < ' tcx > ,
565+ hidden_ty : Ty < ' tcx > ,
566+ obligations : & mut Vec < PredicateObligation < ' tcx > > ,
567+ ) {
568+ let tcx = self . tcx ;
546569 let item_bounds = tcx. explicit_item_bounds ( def_id) ;
547570
548571 for ( predicate, _) in item_bounds. subst_iter_copied ( tcx, substs) {
@@ -555,14 +578,15 @@ impl<'tcx> InferCtxt<'tcx> {
555578 // FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too.
556579 ty:: Alias ( ty:: Projection , projection_ty)
557580 if !projection_ty. has_escaping_bound_vars ( )
558- && !tcx. is_impl_trait_in_trait ( projection_ty. def_id ) =>
581+ && !tcx. is_impl_trait_in_trait ( projection_ty. def_id )
582+ && !tcx. trait_solver_next ( ) =>
559583 {
560584 self . infer_projection (
561585 param_env,
562586 projection_ty,
563587 cause. clone ( ) ,
564588 0 ,
565- & mut obligations,
589+ obligations,
566590 )
567591 }
568592 // Replace all other mentions of the same opaque type with the hidden type,
@@ -588,10 +612,10 @@ impl<'tcx> InferCtxt<'tcx> {
588612 predicate. kind ( ) . skip_binder ( )
589613 {
590614 if projection. term . references_error ( ) {
591- // No point on adding these obligations since there's a type error involved.
592- return Ok ( InferOk { value : ( ) , obligations : vec ! [ ] } ) ;
615+ // No point on adding any obligations since there's a type error involved.
616+ obligations. clear ( ) ;
617+ return ;
593618 }
594- trace ! ( "{:#?}" , projection. term) ;
595619 }
596620 // Require that the predicate holds for the concrete type.
597621 debug ! ( ?predicate) ;
@@ -602,7 +626,6 @@ impl<'tcx> InferCtxt<'tcx> {
602626 predicate,
603627 ) ) ;
604628 }
605- Ok ( InferOk { value : ( ) , obligations } )
606629 }
607630}
608631
0 commit comments