@@ -1659,49 +1659,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1659
1659
self.tcx.const_eval_resolve(param_env_erased, unevaluated, span)
1660
1660
}
1661
1661
1662
- /// If `typ` is a type variable of some kind, resolve it one level
1663
- /// (but do not resolve types found in the result). If `typ` is
1664
- /// not a type variable, just return it unmodified.
1665
- // FIXME(eddyb) inline into `ShallowResolver::visit_ty`.
1666
- fn shallow_resolve_ty(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
1667
- match *typ.kind() {
1668
- ty::Infer(ty::TyVar(v)) => {
1669
- // Not entirely obvious: if `typ` is a type variable,
1670
- // it can be resolved to an int/float variable, which
1671
- // can then be recursively resolved, hence the
1672
- // recursion. Note though that we prevent type
1673
- // variables from unifying to other type variables
1674
- // directly (though they may be embedded
1675
- // structurally), and we prevent cycles in any case,
1676
- // so this recursion should always be of very limited
1677
- // depth.
1678
- //
1679
- // Note: if these two lines are combined into one we get
1680
- // dynamic borrow errors on `self.inner`.
1681
- let known = self.inner.borrow_mut().type_variables().probe(v).known();
1682
- known.map_or(typ, |t| self.shallow_resolve_ty(t))
1683
- }
1684
-
1685
- ty::Infer(ty::IntVar(v)) => self
1686
- .inner
1687
- .borrow_mut()
1688
- .int_unification_table()
1689
- .probe_value(v)
1690
- .map(|v| v.to_type(self.tcx))
1691
- .unwrap_or(typ),
1692
-
1693
- ty::Infer(ty::FloatVar(v)) => self
1694
- .inner
1695
- .borrow_mut()
1696
- .float_unification_table()
1697
- .probe_value(v)
1698
- .map(|v| v.to_type(self.tcx))
1699
- .unwrap_or(typ),
1700
-
1701
- _ => typ,
1702
- }
1703
- }
1704
-
1705
1662
/// `ty_or_const_infer_var_changed` is equivalent to one of these two:
1706
1663
/// * `shallow_resolve(ty) != ty` (where `ty.kind = ty::Infer(_)`)
1707
1664
/// * `shallow_resolve(ct) != ct` (where `ct.kind = ty::ConstKind::Infer(_)`)
@@ -1831,8 +1788,46 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
1831
1788
self.infcx.tcx
1832
1789
}
1833
1790
1791
+ /// If `ty` is a type variable of some kind, resolve it one level
1792
+ /// (but do not resolve types found in the result). If `typ` is
1793
+ /// not a type variable, just return it unmodified.
1834
1794
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
1835
- self.infcx.shallow_resolve_ty(ty)
1795
+ match *ty.kind() {
1796
+ ty::Infer(ty::TyVar(v)) => {
1797
+ // Not entirely obvious: if `typ` is a type variable,
1798
+ // it can be resolved to an int/float variable, which
1799
+ // can then be recursively resolved, hence the
1800
+ // recursion. Note though that we prevent type
1801
+ // variables from unifying to other type variables
1802
+ // directly (though they may be embedded
1803
+ // structurally), and we prevent cycles in any case,
1804
+ // so this recursion should always be of very limited
1805
+ // depth.
1806
+ //
1807
+ // Note: if these two lines are combined into one we get
1808
+ // dynamic borrow errors on `self.inner`.
1809
+ let known = self.infcx.inner.borrow_mut().type_variables().probe(v).known();
1810
+ known.map_or(ty, |t| self.fold_ty(t))
1811
+ }
1812
+
1813
+ ty::Infer(ty::IntVar(v)) => self
1814
+ .infcx
1815
+ .inner
1816
+ .borrow_mut()
1817
+ .int_unification_table()
1818
+ .probe_value(v)
1819
+ .map_or(ty, |v| v.to_type(self.infcx.tcx)),
1820
+
1821
+ ty::Infer(ty::FloatVar(v)) => self
1822
+ .infcx
1823
+ .inner
1824
+ .borrow_mut()
1825
+ .float_unification_table()
1826
+ .probe_value(v)
1827
+ .map_or(ty, |v| v.to_type(self.infcx.tcx)),
1828
+
1829
+ _ => ty,
1830
+ }
1836
1831
}
1837
1832
1838
1833
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
0 commit comments