@@ -2,7 +2,7 @@ use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
2
2
use super :: { DefineOpaqueTypes , InferResult } ;
3
3
use crate :: errors:: OpaqueHiddenTypeDiag ;
4
4
use crate :: infer:: { DefiningAnchor , InferCtxt , InferOk } ;
5
- use crate :: traits;
5
+ use crate :: traits:: { self , PredicateObligation } ;
6
6
use hir:: def_id:: { DefId , LocalDefId } ;
7
7
use hir:: OpaqueTyOrigin ;
8
8
use rustc_data_structures:: fx:: FxIndexMap ;
@@ -48,9 +48,15 @@ impl<'tcx> InferCtxt<'tcx> {
48
48
span : Span ,
49
49
param_env : ty:: ParamEnv < ' tcx > ,
50
50
) -> 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
+
51
56
if !value. has_opaque_types ( ) {
52
57
return InferOk { value, obligations : vec ! [ ] } ;
53
58
}
59
+
54
60
let mut obligations = vec ! [ ] ;
55
61
let replace_opaque_type = |def_id : DefId | {
56
62
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> {
521
527
origin : hir:: OpaqueTyOrigin ,
522
528
a_is_expected : bool ,
523
529
) -> InferResult < ' tcx , ( ) > {
524
- let tcx = self . tcx ;
525
- let OpaqueTypeKey { def_id, substs } = opaque_type_key;
526
-
527
530
// Ideally, we'd get the span where *this specific `ty` came
528
531
// from*, but right now we just use the span from the overall
529
532
// value being folded. In simple cases like `-> impl Foo`,
530
533
// these are the same span, but not in cases like `-> (impl
531
534
// Foo, impl Bar)`.
532
535
let span = cause. span ;
533
536
let prev = self . inner . borrow_mut ( ) . opaque_types ( ) . register (
534
- OpaqueTypeKey { def_id , substs } ,
537
+ opaque_type_key ,
535
538
OpaqueHiddenType { ty : hidden_ty, span } ,
536
539
origin,
537
540
) ;
@@ -543,6 +546,26 @@ impl<'tcx> InferCtxt<'tcx> {
543
546
Vec :: new ( )
544
547
} ;
545
548
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 ;
546
569
let item_bounds = tcx. explicit_item_bounds ( def_id) ;
547
570
548
571
for ( predicate, _) in item_bounds. subst_iter_copied ( tcx, substs) {
@@ -555,14 +578,15 @@ impl<'tcx> InferCtxt<'tcx> {
555
578
// FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too.
556
579
ty:: Alias ( ty:: Projection , projection_ty)
557
580
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 ( ) =>
559
583
{
560
584
self . infer_projection (
561
585
param_env,
562
586
projection_ty,
563
587
cause. clone ( ) ,
564
588
0 ,
565
- & mut obligations,
589
+ obligations,
566
590
)
567
591
}
568
592
// Replace all other mentions of the same opaque type with the hidden type,
@@ -588,10 +612,10 @@ impl<'tcx> InferCtxt<'tcx> {
588
612
predicate. kind ( ) . skip_binder ( )
589
613
{
590
614
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 ;
593
618
}
594
- trace ! ( "{:#?}" , projection. term) ;
595
619
}
596
620
// Require that the predicate holds for the concrete type.
597
621
debug ! ( ?predicate) ;
@@ -602,7 +626,6 @@ impl<'tcx> InferCtxt<'tcx> {
602
626
predicate,
603
627
) ) ;
604
628
}
605
- Ok ( InferOk { value : ( ) , obligations } )
606
629
}
607
630
}
608
631
0 commit comments