Skip to content

Commit 0fdca30

Browse files
committed
Auto merge of #22193 - pnkfelix:cleanup-pr22012, r=eddyb
PR #22012 followup: clean up vtable::check_object_cast by reusing `fresh_ty` (hat tip to nikomatsakis, who was the one who pointed out this simplification to the logic.)
2 parents 3ef8ff1 + f27b3e2 commit 0fdca30

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/librustc_typeck/check/vtable.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use check::{FnCtxt, structurally_resolved_type};
11+
use check::{FnCtxt};
1212
use check::demand;
1313
use middle::traits::{self, ObjectSafetyViolation, MethodViolationCode};
1414
use middle::traits::{Obligation, ObligationCause};
@@ -66,20 +66,11 @@ pub fn check_object_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
6666
demand::suptype(fcx, source_expr.span, source_expected_ty, source_ty);
6767

6868
debug!("check_object_cast postunify source_ty={}", source_ty.repr(tcx));
69-
let source_ty = structurally_resolved_type(fcx, source_expr.span, source_ty);
70-
debug!("check_object_cast resolveto source_ty={}", source_ty.repr(tcx));
7169

7270
let object_trait = object_trait(&object_trait_ty);
7371

74-
let referent_ty = match source_ty.sty {
75-
ty::ty_uniq(ty) => ty,
76-
ty::ty_rptr(_, ty::mt { ty, mutbl: _ }) => ty,
77-
_ => fcx.tcx().sess.span_bug(source_expr.span,
78-
"expected appropriate reference type"),
79-
};
80-
8172
// Ensure that if Ptr<T> is cast to Ptr<Trait>, then T : Trait.
82-
push_cast_obligation(fcx, cast_expr, object_trait, referent_ty);
73+
push_cast_obligation(fcx, cast_expr, object_trait, fresh_ty);
8374
check_object_safety(tcx, object_trait, source_expr.span);
8475

8576
fn object_trait<'a, 'tcx>(t: &'a Ty<'tcx>) -> &'a ty::TyTrait<'tcx> {

0 commit comments

Comments
 (0)