@@ -49,7 +49,6 @@ use std::fmt;
49
49
use std:: rc:: Rc ;
50
50
use syntax:: abi:: Abi ;
51
51
use hir;
52
- use util:: common:: ErrorReported ;
53
52
use util:: nodemap:: FnvHashMap ;
54
53
55
54
pub struct SelectionContext < ' cx , ' tcx : ' cx > {
@@ -1402,7 +1401,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1402
1401
return ;
1403
1402
}
1404
1403
1405
- self . infcx . commit_if_ok ( |snapshot| {
1404
+ self . infcx . in_snapshot ( |snapshot| {
1406
1405
let ( self_ty, _) =
1407
1406
self . infcx ( ) . skolemize_late_bound_regions ( & obligation. self_ty ( ) , snapshot) ;
1408
1407
let poly_trait_ref = match self_ty. sty {
@@ -1413,7 +1412,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1413
1412
debug ! ( "assemble_candidates_from_object_ty: matched builtin bound, \
1414
1413
pushing candidate") ;
1415
1414
candidates. vec . push ( BuiltinObjectCandidate ) ;
1416
- return Ok ( ( ) ) ;
1415
+ return ;
1417
1416
}
1418
1417
}
1419
1418
_ => { }
@@ -1424,10 +1423,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1424
1423
ty:: TyInfer ( ty:: TyVar ( _) ) => {
1425
1424
debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
1426
1425
candidates. ambiguous = true ; // could wind up being an object type
1427
- return Ok ( ( ) ) ;
1426
+ return ;
1428
1427
}
1429
1428
_ => {
1430
- return Ok ( ( ) ) ;
1429
+ return ;
1431
1430
}
1432
1431
} ;
1433
1432
@@ -1455,9 +1454,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1455
1454
} else if upcast_trait_refs == 1 {
1456
1455
candidates. vec . push ( ObjectCandidate ) ;
1457
1456
}
1458
-
1459
- Ok :: < ( ) , ( ) > ( ( ) )
1460
- } ) . unwrap ( ) ;
1457
+ } )
1461
1458
}
1462
1459
1463
1460
/// Search for unsizing that might apply to `obligation`.
@@ -1854,21 +1851,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1854
1851
// 2. Produce something like `&'0 int : Copy`
1855
1852
// 3. Re-bind the regions back to `for<'a> &'a int : Copy`
1856
1853
1857
- // Move the binder into the individual types
1858
- let bound_types: Vec < ty:: Binder < Ty < ' tcx > > > =
1859
- types. skip_binder ( )
1860
- . iter ( )
1861
- . map ( |& nested_ty| ty:: Binder ( nested_ty) )
1862
- . collect ( ) ;
1854
+ types. skip_binder ( ) . into_iter ( ) . flat_map ( |ty| { // binder moved -\
1855
+ let ty: ty:: Binder < Ty < ' tcx > > = ty:: Binder ( ty) ; // <----------/
1863
1856
1864
- // For each type, produce a vector of resulting obligations
1865
- let obligations: Result < Vec < Vec < _ > > , _ > = bound_types. iter ( ) . map ( |nested_ty| {
1866
- self . infcx . commit_if_ok ( |snapshot| {
1857
+ self . infcx . in_snapshot ( |snapshot| {
1867
1858
let ( skol_ty, skol_map) =
1868
- self . infcx ( ) . skolemize_late_bound_regions ( nested_ty , snapshot) ;
1859
+ self . infcx ( ) . skolemize_late_bound_regions ( & ty , snapshot) ;
1869
1860
let Normalized { value : normalized_ty, mut obligations } =
1870
1861
project:: normalize_with_depth ( self ,
1871
- obligation . cause . clone ( ) ,
1862
+ derived_cause . clone ( ) ,
1872
1863
obligation. recursion_depth + 1 ,
1873
1864
& skol_ty) ;
1874
1865
let skol_obligation =
@@ -1879,15 +1870,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1879
1870
normalized_ty,
1880
1871
vec ! [ ] ) ;
1881
1872
obligations. push ( skol_obligation) ;
1882
- Ok ( self . infcx ( ) . plug_leaks ( skol_map, snapshot, & obligations) )
1873
+ self . infcx ( ) . plug_leaks ( skol_map, snapshot, & obligations)
1883
1874
} )
1884
- } ) . collect ( ) ;
1885
-
1886
- // Flatten those vectors (couldn't do it above due `collect`)
1887
- match obligations {
1888
- Ok ( obligations) => obligations. into_iter ( ) . flat_map ( |o| o) . collect ( ) ,
1889
- Err ( ErrorReported ) => Vec :: new ( ) ,
1890
- }
1875
+ } ) . collect ( )
1891
1876
}
1892
1877
1893
1878
///////////////////////////////////////////////////////////////////////////
@@ -1928,9 +1913,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1928
1913
}
1929
1914
1930
1915
ImplCandidate ( impl_def_id) => {
1931
- let vtable_impl =
1932
- self . confirm_impl_candidate ( obligation, impl_def_id) ?;
1933
- Ok ( VtableImpl ( vtable_impl) )
1916
+ Ok ( VtableImpl ( self . confirm_impl_candidate ( obligation, impl_def_id) ) )
1934
1917
}
1935
1918
1936
1919
ClosureCandidate ( closure_def_id, substs, kind) => {
@@ -1974,14 +1957,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1974
1957
fn confirm_projection_candidate ( & mut self ,
1975
1958
obligation : & TraitObligation < ' tcx > )
1976
1959
{
1977
- let _: Result < ( ) , ( ) > =
1978
- self . infcx . commit_if_ok ( |snapshot| {
1979
- let result =
1980
- self . match_projection_obligation_against_bounds_from_trait ( obligation,
1981
- snapshot) ;
1982
- assert ! ( result) ;
1983
- Ok ( ( ) )
1984
- } ) ;
1960
+ self . infcx . in_snapshot ( |snapshot| {
1961
+ let result =
1962
+ self . match_projection_obligation_against_bounds_from_trait ( obligation,
1963
+ snapshot) ;
1964
+ assert ! ( result) ;
1965
+ } )
1985
1966
}
1986
1967
1987
1968
fn confirm_param_candidate ( & mut self ,
@@ -2112,20 +2093,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2112
2093
trait_def_id,
2113
2094
nested) ;
2114
2095
2115
- let trait_obligations: Result < Vec < _ > , ( ) > = self . infcx . commit_if_ok ( |snapshot| {
2096
+ let trait_obligations = self . infcx . in_snapshot ( |snapshot| {
2116
2097
let poly_trait_ref = obligation. predicate . to_poly_trait_ref ( ) ;
2117
2098
let ( trait_ref, skol_map) =
2118
2099
self . infcx ( ) . skolemize_late_bound_regions ( & poly_trait_ref, snapshot) ;
2119
- Ok ( self . impl_or_trait_obligations ( obligation. cause . clone ( ) ,
2120
- obligation. recursion_depth + 1 ,
2121
- trait_def_id,
2122
- & trait_ref. substs ,
2123
- skol_map,
2124
- snapshot) )
2100
+ self . impl_or_trait_obligations ( obligation. cause . clone ( ) ,
2101
+ obligation. recursion_depth + 1 ,
2102
+ trait_def_id,
2103
+ & trait_ref. substs ,
2104
+ skol_map,
2105
+ snapshot)
2125
2106
} ) ;
2126
2107
2127
- // no Errors in that code above
2128
- obligations. append ( & mut trait_obligations. unwrap ( ) ) ;
2108
+ obligations. extend ( trait_obligations) ;
2129
2109
2130
2110
debug ! ( "vtable_default_impl_data: obligations={:?}" , obligations) ;
2131
2111
@@ -2138,22 +2118,21 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2138
2118
fn confirm_impl_candidate ( & mut self ,
2139
2119
obligation : & TraitObligation < ' tcx > ,
2140
2120
impl_def_id : DefId )
2141
- -> Result < VtableImplData < ' tcx , PredicateObligation < ' tcx > > ,
2142
- SelectionError < ' tcx > >
2121
+ -> VtableImplData < ' tcx , PredicateObligation < ' tcx > >
2143
2122
{
2144
2123
debug ! ( "confirm_impl_candidate({:?},{:?})" ,
2145
2124
obligation,
2146
2125
impl_def_id) ;
2147
2126
2148
2127
// First, create the substitutions by matching the impl again,
2149
2128
// this time not in a probe.
2150
- self . infcx . commit_if_ok ( |snapshot| {
2129
+ self . infcx . in_snapshot ( |snapshot| {
2151
2130
let ( substs, skol_map) =
2152
2131
self . rematch_impl ( impl_def_id, obligation,
2153
2132
snapshot) ;
2154
2133
debug ! ( "confirm_impl_candidate substs={:?}" , substs) ;
2155
- Ok ( self . vtable_impl ( impl_def_id, substs, obligation. cause . clone ( ) ,
2156
- obligation. recursion_depth + 1 , skol_map, snapshot) )
2134
+ self . vtable_impl ( impl_def_id, substs, obligation. cause . clone ( ) ,
2135
+ obligation. recursion_depth + 1 , skol_map, snapshot)
2157
2136
} )
2158
2137
}
2159
2138
0 commit comments