@@ -49,7 +49,6 @@ use std::fmt;
4949use std:: rc:: Rc ;
5050use syntax:: abi:: Abi ;
5151use hir;
52- use util:: common:: ErrorReported ;
5352use util:: nodemap:: FnvHashMap ;
5453
5554pub struct SelectionContext < ' cx , ' tcx : ' cx > {
@@ -1402,7 +1401,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14021401 return ;
14031402 }
14041403
1405- self . infcx . commit_if_ok ( |snapshot| {
1404+ self . infcx . in_snapshot ( |snapshot| {
14061405 let ( self_ty, _) =
14071406 self . infcx ( ) . skolemize_late_bound_regions ( & obligation. self_ty ( ) , snapshot) ;
14081407 let poly_trait_ref = match self_ty. sty {
@@ -1413,7 +1412,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14131412 debug ! ( "assemble_candidates_from_object_ty: matched builtin bound, \
14141413 pushing candidate") ;
14151414 candidates. vec . push ( BuiltinObjectCandidate ) ;
1416- return Ok ( ( ) ) ;
1415+ return ;
14171416 }
14181417 }
14191418 _ => { }
@@ -1424,10 +1423,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14241423 ty:: TyInfer ( ty:: TyVar ( _) ) => {
14251424 debug ! ( "assemble_candidates_from_object_ty: ambiguous" ) ;
14261425 candidates. ambiguous = true ; // could wind up being an object type
1427- return Ok ( ( ) ) ;
1426+ return ;
14281427 }
14291428 _ => {
1430- return Ok ( ( ) ) ;
1429+ return ;
14311430 }
14321431 } ;
14331432
@@ -1455,9 +1454,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14551454 } else if upcast_trait_refs == 1 {
14561455 candidates. vec . push ( ObjectCandidate ) ;
14571456 }
1458-
1459- Ok :: < ( ) , ( ) > ( ( ) )
1460- } ) . unwrap ( ) ;
1457+ } )
14611458 }
14621459
14631460 /// Search for unsizing that might apply to `obligation`.
@@ -1854,21 +1851,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18541851 // 2. Produce something like `&'0 int : Copy`
18551852 // 3. Re-bind the regions back to `for<'a> &'a int : Copy`
18561853
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) ; // <----------/
18631856
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| {
18671858 let ( skol_ty, skol_map) =
1868- self . infcx ( ) . skolemize_late_bound_regions ( nested_ty , snapshot) ;
1859+ self . infcx ( ) . skolemize_late_bound_regions ( & ty , snapshot) ;
18691860 let Normalized { value : normalized_ty, mut obligations } =
18701861 project:: normalize_with_depth ( self ,
1871- obligation . cause . clone ( ) ,
1862+ derived_cause . clone ( ) ,
18721863 obligation. recursion_depth + 1 ,
18731864 & skol_ty) ;
18741865 let skol_obligation =
@@ -1879,15 +1870,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18791870 normalized_ty,
18801871 vec ! [ ] ) ;
18811872 obligations. push ( skol_obligation) ;
1882- Ok ( self . infcx ( ) . plug_leaks ( skol_map, snapshot, & obligations) )
1873+ self . infcx ( ) . plug_leaks ( skol_map, snapshot, & obligations)
18831874 } )
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 ( )
18911876 }
18921877
18931878 ///////////////////////////////////////////////////////////////////////////
@@ -1928,9 +1913,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19281913 }
19291914
19301915 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) ) )
19341917 }
19351918
19361919 ClosureCandidate ( closure_def_id, substs, kind) => {
@@ -1974,14 +1957,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19741957 fn confirm_projection_candidate ( & mut self ,
19751958 obligation : & TraitObligation < ' tcx > )
19761959 {
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+ } )
19851966 }
19861967
19871968 fn confirm_param_candidate ( & mut self ,
@@ -2112,20 +2093,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21122093 trait_def_id,
21132094 nested) ;
21142095
2115- let trait_obligations: Result < Vec < _ > , ( ) > = self . infcx . commit_if_ok ( |snapshot| {
2096+ let trait_obligations = self . infcx . in_snapshot ( |snapshot| {
21162097 let poly_trait_ref = obligation. predicate . to_poly_trait_ref ( ) ;
21172098 let ( trait_ref, skol_map) =
21182099 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)
21252106 } ) ;
21262107
2127- // no Errors in that code above
2128- obligations. append ( & mut trait_obligations. unwrap ( ) ) ;
2108+ obligations. extend ( trait_obligations) ;
21292109
21302110 debug ! ( "vtable_default_impl_data: obligations={:?}" , obligations) ;
21312111
@@ -2138,22 +2118,21 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21382118 fn confirm_impl_candidate ( & mut self ,
21392119 obligation : & TraitObligation < ' tcx > ,
21402120 impl_def_id : DefId )
2141- -> Result < VtableImplData < ' tcx , PredicateObligation < ' tcx > > ,
2142- SelectionError < ' tcx > >
2121+ -> VtableImplData < ' tcx , PredicateObligation < ' tcx > >
21432122 {
21442123 debug ! ( "confirm_impl_candidate({:?},{:?})" ,
21452124 obligation,
21462125 impl_def_id) ;
21472126
21482127 // First, create the substitutions by matching the impl again,
21492128 // this time not in a probe.
2150- self . infcx . commit_if_ok ( |snapshot| {
2129+ self . infcx . in_snapshot ( |snapshot| {
21512130 let ( substs, skol_map) =
21522131 self . rematch_impl ( impl_def_id, obligation,
21532132 snapshot) ;
21542133 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)
21572136 } )
21582137 }
21592138
0 commit comments