diff options
| author | scalexm <alexandre@scalexm.fr> | 2018-11-01 15:30:37 +0100 |
|---|---|---|
| committer | scalexm <alexandre@scalexm.fr> | 2018-11-13 12:28:43 +0100 |
| commit | afa884c03a90f4d773e28faaad4bc7845d677332 (patch) | |
| tree | e91cfa82db867a2540ed00b66bd2db799c442c2a /src/librustc | |
| parent | 79b6c41bc2d4e9cb9a0c92c0c446882a0cf1a804 (diff) | |
| download | rust-afa884c03a90f4d773e28faaad4bc7845d677332.tar.gz rust-afa884c03a90f4d773e28faaad4bc7845d677332.zip | |
Instantiate all bound vars existentially
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/infer/canonical/substitute.rs | 2 | ||||
| -rw-r--r-- | src/librustc/infer/higher_ranked/mod.rs | 10 | ||||
| -rw-r--r-- | src/librustc/infer/mod.rs | 12 | ||||
| -rw-r--r-- | src/librustc/traits/error_reporting.rs | 5 | ||||
| -rw-r--r-- | src/librustc/ty/fold.rs | 30 |
5 files changed, 29 insertions, 30 deletions
diff --git a/src/librustc/infer/canonical/substitute.rs b/src/librustc/infer/canonical/substitute.rs index b8c1ed236c0..70ce5d0d8dc 100644 --- a/src/librustc/infer/canonical/substitute.rs +++ b/src/librustc/infer/canonical/substitute.rs @@ -80,6 +80,6 @@ where } }; - tcx.replace_escaping_bound_vars(value, fld_r, fld_t) + tcx.replace_escaping_bound_vars(value, fld_r, fld_t).0 } } diff --git a/src/librustc/infer/higher_ranked/mod.rs b/src/librustc/infer/higher_ranked/mod.rs index 3e08a4e021a..642382bcf0f 100644 --- a/src/librustc/infer/higher_ranked/mod.rs +++ b/src/librustc/infer/higher_ranked/mod.rs @@ -59,11 +59,11 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> { // with a fresh region variable. These region variables -- // but no other pre-existing region variables -- can name // the placeholders. - let (a_prime, _) = - self.infcx.replace_late_bound_regions_with_fresh_var( - span, - HigherRankedType, - a); + let (a_prime, _) = self.infcx.replace_bound_vars_with_fresh_vars( + span, + HigherRankedType, + a + ); debug!("a_prime={:?}", a_prime); debug!("b_prime={:?}", b_prime); diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index f5513acecf9..4ddf47c88dd 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -1328,18 +1328,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { self.report_and_explain_type_error(trace, &err) } - pub fn replace_late_bound_regions_with_fresh_var<T>( + pub fn replace_bound_vars_with_fresh_vars<T>( &self, span: Span, lbrct: LateBoundRegionConversionTime, - value: &ty::Binder<T>, + value: &ty::Binder<T> ) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>) where - T: TypeFoldable<'tcx>, + T: TypeFoldable<'tcx> { - self.tcx.replace_late_bound_regions(value, |br| { - self.next_region_var(LateBoundRegion(span, br, lbrct)) - }) + let fld_r = |br| self.next_region_var(LateBoundRegion(span, br, lbrct)); + let fld_t = |_| self.next_ty_var(TypeVariableOrigin::MiscVariable(span)); + self.tcx.replace_bound_vars(value, fld_r, fld_t) } /// Given a higher-ranked projection predicate like: diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index fbada789956..2761a954cea 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -212,10 +212,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // cause I have no idea for a good error message. if let ty::Predicate::Projection(ref data) = predicate { let mut selcx = SelectionContext::new(self); - let (data, _) = self.replace_late_bound_regions_with_fresh_var( + let (data, _) = self.replace_bound_vars_with_fresh_vars( obligation.cause.span, infer::LateBoundRegionConversionTime::HigherRankedType, - data); + data + ); let mut obligations = vec![]; let normalized_ty = super::normalize_projection_type( &mut selcx, diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index ffa4380a5d6..a897afa0ca6 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -520,22 +520,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn replace_late_bound_regions<T, F>( self, value: &Binder<T>, - mut fld_r: F + fld_r: F ) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>) where F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>, T: TypeFoldable<'tcx> { - let mut map = BTreeMap::new(); - let mut real_fldr = |br| { - *map.entry(br).or_insert_with(|| fld_r(br)) - }; - // identity for bound types - let mut fld_t = |bound_ty| self.mk_ty(ty::Bound(bound_ty)); - - let mut replacer = BoundVarReplacer::new(self, &mut real_fldr, &mut fld_t); - let result = value.skip_binder().fold_with(&mut replacer); - (result, map) + let fld_t = |bound_ty| self.mk_ty(ty::Bound(bound_ty)); + self.replace_escaping_bound_vars(value.skip_binder(), fld_r, fld_t) } /// Replace all escaping bound vars. The `fld_r` closure replaces escaping @@ -545,17 +537,23 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { value: &T, mut fld_r: F, mut fld_t: G - ) -> T + ) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>) where F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>, G: FnMut(ty::BoundTy) -> ty::Ty<'tcx>, T: TypeFoldable<'tcx> { + let mut map = BTreeMap::new(); + if !value.has_escaping_bound_vars() { - value.clone() + (value.clone(), map) } else { - let mut replacer = BoundVarReplacer::new(self, &mut fld_r, &mut fld_t); + let mut real_fld_r = |br| { + *map.entry(br).or_insert_with(|| fld_r(br)) + }; + + let mut replacer = BoundVarReplacer::new(self, &mut real_fld_r, &mut fld_t); let result = value.fold_with(&mut replacer); - result + (result, map) } } @@ -567,7 +565,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { value: &Binder<T>, fld_r: F, fld_t: G - ) -> T + ) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>) where F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>, G: FnMut(ty::BoundTy) -> ty::Ty<'tcx>, T: TypeFoldable<'tcx> |
