Skip to content

Commit 92b2f28

Browse files
w
1 parent 8de4c72 commit 92b2f28

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,16 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
597597

598598
// Create an obligation for `Source: CoerceUnsized<Target>`.
599599
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+
}
600610

601611
// Use a FIFO queue for this custom fulfillment procedure.
602612
//
@@ -605,12 +615,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
605615
// and almost never more than 3. By using a SmallVec we avoid an
606616
// allocation, at the (very small) cost of (occasionally) having to
607617
// 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];
614619

615620
// Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
616621
// emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where

0 commit comments

Comments
 (0)