@@ -1709,10 +1709,47 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1709
1709
}
1710
1710
}
1711
1711
1712
+ /// Apply "fallbacks" to some types
1713
+ /// ! gets replaced with (), unconstrained ints with i32, and unconstrained floats with f64.
1714
+ pub fn default_type_parameters ( & self ) {
1715
+ use middle:: ty:: UnconstrainedNumeric :: { UnconstrainedInt , UnconstrainedFloat , Neither } ;
1716
+ for ty in & self . infcx ( ) . unsolved_variables ( ) {
1717
+ let resolved = self . infcx ( ) . resolve_type_vars_if_possible ( ty) ;
1718
+ if self . infcx ( ) . type_var_diverges ( resolved) {
1719
+ demand:: eqtype ( self , codemap:: DUMMY_SP , * ty, self . tcx ( ) . mk_nil ( ) ) ;
1720
+ } else {
1721
+ match self . infcx ( ) . type_is_unconstrained_numeric ( resolved) {
1722
+ UnconstrainedInt => {
1723
+ demand:: eqtype ( self , codemap:: DUMMY_SP , * ty, self . tcx ( ) . types . i32 )
1724
+ } ,
1725
+ UnconstrainedFloat => {
1726
+ demand:: eqtype ( self , codemap:: DUMMY_SP , * ty, self . tcx ( ) . types . f64 )
1727
+ }
1728
+ Neither => { }
1729
+ }
1730
+ }
1731
+ }
1732
+ }
1733
+
1712
1734
fn select_all_obligations_and_apply_defaults ( & self ) {
1735
+ if self . tcx ( ) . sess . features . borrow ( ) . default_type_parameter_fallback {
1736
+ self . new_select_all_obligations_and_apply_defaults ( ) ;
1737
+ } else {
1738
+ self . old_select_all_obligations_and_apply_defaults ( ) ;
1739
+ }
1740
+ }
1741
+
1742
+ // Implements old type inference fallback algorithm
1743
+ fn old_select_all_obligations_and_apply_defaults ( & self ) {
1744
+ self . select_obligations_where_possible ( ) ;
1745
+ self . default_type_parameters ( ) ;
1746
+ self . select_obligations_where_possible ( ) ;
1747
+ }
1748
+
1749
+ fn new_select_all_obligations_and_apply_defaults ( & self ) {
1713
1750
use middle:: ty:: UnconstrainedNumeric :: { UnconstrainedInt , UnconstrainedFloat , Neither } ;
1714
1751
1715
- // For the time being this errs on the side of being memory wasteful but provides better
1752
+ // For the time being this errs on the side of being memory wasteful but provides better
1716
1753
// error reporting.
1717
1754
// let type_variables = self.infcx().type_variables.clone();
1718
1755
@@ -1934,6 +1971,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1934
1971
assert ! ( self . inh. deferred_call_resolutions. borrow( ) . is_empty( ) ) ;
1935
1972
1936
1973
self . select_all_obligations_and_apply_defaults ( ) ;
1974
+
1937
1975
let mut fulfillment_cx = self . inh . infcx . fulfillment_cx . borrow_mut ( ) ;
1938
1976
match fulfillment_cx. select_all_or_error ( self . infcx ( ) ) {
1939
1977
Ok ( ( ) ) => { }
0 commit comments