@@ -1709,10 +1709,47 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17091709 }
17101710 }
17111711
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+
17121734 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 ) {
17131750 use middle:: ty:: UnconstrainedNumeric :: { UnconstrainedInt , UnconstrainedFloat , Neither } ;
17141751
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
17161753 // error reporting.
17171754 // let type_variables = self.infcx().type_variables.clone();
17181755
@@ -1934,6 +1971,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19341971 assert ! ( self . inh. deferred_call_resolutions. borrow( ) . is_empty( ) ) ;
19351972
19361973 self . select_all_obligations_and_apply_defaults ( ) ;
1974+
19371975 let mut fulfillment_cx = self . inh . infcx . fulfillment_cx . borrow_mut ( ) ;
19381976 match fulfillment_cx. select_all_or_error ( self . infcx ( ) ) {
19391977 Ok ( ( ) ) => { }
0 commit comments