diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-06-06 09:29:14 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-06-26 10:31:49 -0400 |
| commit | 2b52793f74484c9cb69901d34627210ad3a5ba70 (patch) | |
| tree | 382c4c4078ba56b904383635795ed3c974f205fd | |
| parent | 909b10c33ba51ac704fa909395c58de3e4aca71f (diff) | |
| download | rust-2b52793f74484c9cb69901d34627210ad3a5ba70.tar.gz rust-2b52793f74484c9cb69901d34627210ad3a5ba70.zip | |
introduce `Subtype` type_op
| -rw-r--r-- | src/librustc_mir/borrow_check/nll/type_check/mod.rs | 6 | ||||
| -rw-r--r-- | src/librustc_mir/borrow_check/nll/type_check/type_op.rs | 34 |
2 files changed, 31 insertions, 9 deletions
diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 5d06513e2a8..dd2af3f6f27 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -826,11 +826,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { self.fully_perform_op( locations, || format!("sub_types({:?} <: {:?})", sub, sup), - CustomTypeOp::new(|this| { - this.infcx - .at(&ObligationCause::dummy(), this.param_env) - .sup(sup, sub) - }), + type_op::Subtype::new(sub, sup), ) } diff --git a/src/librustc_mir/borrow_check/nll/type_check/type_op.rs b/src/librustc_mir/borrow_check/nll/type_check/type_op.rs index b4c71344cfc..e31af735d55 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/type_op.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/type_op.rs @@ -10,19 +10,23 @@ use borrow_check::nll::type_check::TypeChecker; use rustc::infer::InferResult; +use rustc::traits::ObligationCause; +use rustc::ty::Ty; pub(super) trait TypeOp<'gcx, 'tcx> { type Output; - fn perform(self, type_checker: &mut TypeChecker<'_, 'gcx, 'tcx>) -> InferResult<'tcx, Self::Output>; + fn perform( + self, + type_checker: &mut TypeChecker<'_, 'gcx, 'tcx>, + ) -> InferResult<'tcx, Self::Output>; } pub(super) struct CustomTypeOp<F> { - closure: F + closure: F, } -impl<F> CustomTypeOp<F> -{ +impl<F> CustomTypeOp<F> { pub(super) fn new<'gcx, 'tcx, R>(closure: F) -> Self where F: FnOnce(&mut TypeChecker<'_, 'gcx, 'tcx>) -> InferResult<'tcx, R>, @@ -41,3 +45,25 @@ where (self.closure)(type_checker) } } + +pub(super) struct Subtype<'tcx> { + sub: Ty<'tcx>, + sup: Ty<'tcx>, +} + +impl<'tcx> Subtype<'tcx> { + pub(super) fn new(sub: Ty<'tcx>, sup: Ty<'tcx>) -> Self { + Self { sub, sup } + } +} + +impl<'gcx, 'tcx> TypeOp<'gcx, 'tcx> for Subtype<'tcx> { + type Output = (); + + fn perform(self, type_checker: &mut TypeChecker<'_, 'gcx, 'tcx>) -> InferResult<'tcx, Self::Output> { + type_checker.infcx + .at(&ObligationCause::dummy(), type_checker.param_env) + .sup(self.sup, self.sub) + } +} + |
