@@ -17,9 +17,9 @@ use self::SelectionCandidate::*;
17
17
use self :: BuiltinBoundConditions :: * ;
18
18
use self :: EvaluationResult :: * ;
19
19
20
- use super :: { DerivedObligationCause } ;
21
- use super :: { project} ;
22
- use super :: project:: Normalized ;
20
+ use super :: DerivedObligationCause ;
21
+ use super :: project;
22
+ use super :: project:: { normalize_with_depth , Normalized } ;
23
23
use super :: { PredicateObligation , TraitObligation , ObligationCause } ;
24
24
use super :: { ObligationCauseCode , BuiltinDerivedObligation , ImplDerivedObligation } ;
25
25
use super :: { SelectionError , Unimplemented , Overflow , OutputTypeParameterMismatch } ;
@@ -1620,7 +1620,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1620
1620
}
1621
1621
}
1622
1622
1623
- fn constituent_types ( & self , t : Ty < ' tcx > ) -> Vec < Ty < ' tcx > > {
1623
+ fn constituent_ty_obligations ( & self , t : Ty < ' tcx > ) -> Vec < Ty < ' tcx > > {
1624
1624
match t. sty {
1625
1625
ty:: ty_uint( _) |
1626
1626
ty:: ty_int( _) |
@@ -1870,6 +1870,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1870
1870
VtableBuiltinData { nested : obligations }
1871
1871
}
1872
1872
1873
+ /// This handles the case where a `impl Foo for ..` impl is being used.
1874
+ /// The idea is that the impl applies to `X : Foo` if the following conditions are met:
1875
+ ///
1876
+ /// 1. For each constituent type `Y` in `X`, `Y : Foo` holds
1877
+ /// 2. For each where-clause `C` declared on `Foo`, `[Self => X] C` holds.
1873
1878
fn confirm_default_impl_candidate ( & mut self ,
1874
1879
obligation : & TraitObligation < ' tcx > ,
1875
1880
impl_def_id : ast:: DefId )
@@ -1881,10 +1886,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1881
1886
impl_def_id. repr( self . tcx( ) ) ) ;
1882
1887
1883
1888
let self_ty = self . infcx . shallow_resolve ( obligation. predicate . 0 . self_ty ( ) ) ;
1884
- let types = self . constituent_types ( self_ty) ;
1889
+ let types = self . constituent_ty_obligations ( self_ty) ;
1885
1890
Ok ( self . vtable_default_impl ( obligation, impl_def_id, types) )
1886
1891
}
1887
1892
1893
+ /// See `confirm_default_impl_candidate`
1888
1894
fn vtable_default_impl ( & mut self ,
1889
1895
obligation : & TraitObligation < ' tcx > ,
1890
1896
trait_def_id : ast:: DefId ,
@@ -1930,12 +1936,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1930
1936
self . infcx ( ) . skolemize_late_bound_regions ( & obligation. predicate , snapshot) ;
1931
1937
1932
1938
let substs = obligation. predicate . to_poly_trait_ref ( ) . substs ( ) ;
1933
- let trait_obligations = self . impl_obligations ( obligation. cause . clone ( ) ,
1934
- obligation. recursion_depth + 1 ,
1935
- trait_def_id,
1936
- substs,
1937
- skol_map,
1938
- snapshot) ;
1939
+ let trait_obligations = self . impl_or_trait_obligations ( obligation. cause . clone ( ) ,
1940
+ obligation. recursion_depth + 1 ,
1941
+ trait_def_id,
1942
+ substs,
1943
+ skol_map,
1944
+ snapshot) ;
1939
1945
obligations. push_all ( trait_obligations. as_slice ( ) ) ;
1940
1946
Ok ( ( ) )
1941
1947
} ) ;
@@ -1988,12 +1994,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1988
1994
skol_map. repr( self . tcx( ) ) ) ;
1989
1995
1990
1996
let mut impl_obligations =
1991
- self . impl_obligations ( cause,
1992
- recursion_depth,
1993
- impl_def_id,
1994
- & substs. value ,
1995
- skol_map,
1996
- snapshot) ;
1997
+ self . impl_or_trait_obligations ( cause,
1998
+ recursion_depth,
1999
+ impl_def_id,
2000
+ & substs. value ,
2001
+ skol_map,
2002
+ snapshot) ;
1997
2003
1998
2004
debug ! ( "vtable_impl: impl_def_id={} impl_obligations={}" ,
1999
2005
impl_def_id. repr( self . tcx( ) ) ,
@@ -2413,28 +2419,30 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2413
2419
ty:: Binder ( trait_ref)
2414
2420
}
2415
2421
2416
- fn impl_obligations ( & mut self ,
2417
- cause : ObligationCause < ' tcx > ,
2418
- recursion_depth : uint ,
2419
- impl_def_id : ast:: DefId ,
2420
- impl_substs : & Substs < ' tcx > ,
2421
- skol_map : infer:: SkolemizationMap ,
2422
- snapshot : & infer:: CombinedSnapshot )
2423
- -> VecPerParamSpace < PredicateObligation < ' tcx > >
2422
+ /// Returns the obligations that are implied by instantiating an
2423
+ /// impl or trait. The obligations are substituted and fully
2424
+ /// normalized. This is used when confirming an impl or default
2425
+ /// impl.
2426
+ fn impl_or_trait_obligations ( & mut self ,
2427
+ cause : ObligationCause < ' tcx > ,
2428
+ recursion_depth : uint ,
2429
+ def_id : ast:: DefId , // of impl or trait
2430
+ substs : & Substs < ' tcx > , // for impl or trait
2431
+ skol_map : infer:: SkolemizationMap ,
2432
+ snapshot : & infer:: CombinedSnapshot )
2433
+ -> VecPerParamSpace < PredicateObligation < ' tcx > >
2424
2434
{
2425
- let impl_bounds = ty:: lookup_predicates ( self . tcx ( ) , impl_def_id) ;
2426
- let bounds = impl_bounds. instantiate ( self . tcx ( ) , impl_substs) ;
2427
- let normalized_bounds =
2428
- project:: normalize_with_depth ( self , cause. clone ( ) , recursion_depth, & bounds) ;
2429
- let normalized_bounds =
2430
- self . infcx ( ) . plug_leaks ( skol_map, snapshot, & normalized_bounds) ;
2431
- let mut impl_obligations =
2435
+ let predicates = ty:: lookup_predicates ( self . tcx ( ) , def_id) ;
2436
+ let predicates = predicates. instantiate ( self . tcx ( ) , substs) ;
2437
+ let predicates = normalize_with_depth ( self , cause. clone ( ) , recursion_depth, & predicates) ;
2438
+ let predicates = self . infcx ( ) . plug_leaks ( skol_map, snapshot, & predicates) ;
2439
+ let mut obligations =
2432
2440
util:: predicates_for_generics ( self . tcx ( ) ,
2433
2441
cause,
2434
2442
recursion_depth,
2435
- & normalized_bounds . value ) ;
2436
- impl_obligations . extend ( TypeSpace , normalized_bounds . obligations . into_iter ( ) ) ;
2437
- impl_obligations
2443
+ & predicates . value ) ;
2444
+ obligations . extend ( TypeSpace , predicates . obligations . into_iter ( ) ) ;
2445
+ obligations
2438
2446
}
2439
2447
2440
2448
#[ allow( unused_comparisons) ]
0 commit comments