@@ -597,6 +597,16 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
597
597
598
598
// Create an obligation for `Source: CoerceUnsized<Target>`.
599
599
let cause = self . cause ( self . cause . span , ObligationCauseCode :: Coercion { source, target } ) ;
600
+ let obligation = Obligation :: new (
601
+ self . tcx ,
602
+ cause,
603
+ self . fcx . param_env ,
604
+ ty:: TraitRef :: new ( self . tcx , coerce_unsized_did, [ coerce_source, coerce_target] ) ,
605
+ ) ;
606
+ if self . predicate_must_hold_modulo_regions ( & obligation) {
607
+ coercion. obligations . push ( obligation) ;
608
+ return Ok ( coercion) ;
609
+ }
600
610
601
611
// Use a FIFO queue for this custom fulfillment procedure.
602
612
//
@@ -605,12 +615,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
605
615
// and almost never more than 3. By using a SmallVec we avoid an
606
616
// allocation, at the (very small) cost of (occasionally) having to
607
617
// shift subsequent elements down when removing the front element.
608
- let mut queue: SmallVec < [ PredicateObligation < ' tcx > ; 4 ] > = smallvec ! [ Obligation :: new(
609
- self . tcx,
610
- cause,
611
- self . fcx. param_env,
612
- ty:: TraitRef :: new( self . tcx, coerce_unsized_did, [ coerce_source, coerce_target] )
613
- ) ] ;
618
+ let mut queue: SmallVec < [ PredicateObligation < ' tcx > ; 4 ] > = smallvec ! [ obligation] ;
614
619
615
620
// Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
616
621
// emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where
0 commit comments