From d2bacb18d2bf9eadca86fe7c1483e38ce774750e Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 28 Apr 2020 13:04:48 -0700 Subject: [PATCH] Ensure that `new_self_ty` has no escaping bound vars Otherwise inserting it to the `Binder` used by `trait_ref` would cause problems. This is just to be extra carefult: we aren't going to start recommending that the user start using HKTs anytime soon. --- src/librustc_trait_selection/traits/error_reporting/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index 20de0b786ed70..c59abd3602116 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -1385,6 +1385,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { trait_ref: &ty::PolyTraitRef<'tcx>, new_self_ty: Ty<'tcx>, ) -> PredicateObligation<'tcx> { + assert!(!new_self_ty.has_escaping_bound_vars()); + let trait_ref = trait_ref.map_bound_ref(|tr| ty::TraitRef { substs: self.tcx.mk_substs_trait(new_self_ty, &tr.substs[1..]), ..*tr