Skip to content

PR #22012 followup: clean up vtable::check_object_cast by reusing fresh_ty #22193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/librustc_typeck/check/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

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

let object_trait = object_trait(&object_trait_ty);

let referent_ty = match source_ty.sty {
ty::ty_uniq(ty) => ty,
ty::ty_rptr(_, ty::mt { ty, mutbl: _ }) => ty,
_ => fcx.tcx().sess.span_bug(source_expr.span,
"expected appropriate reference type"),
};

// Ensure that if Ptr<T> is cast to Ptr<Trait>, then T : Trait.
push_cast_obligation(fcx, cast_expr, object_trait, referent_ty);
push_cast_obligation(fcx, cast_expr, object_trait, fresh_ty);
check_object_safety(tcx, object_trait, source_expr.span);

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