@@ -611,6 +611,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
611
611
return Ok ( None ) ;
612
612
}
613
613
614
+
614
615
// If there are *NO* candidates, that there are no impls --
615
616
// that we know of, anyway. Note that in the case where there
616
617
// are unbound type variables within the obligation, it might
@@ -626,6 +627,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
626
627
627
628
// Just one candidate left.
628
629
let candidate = candidates. pop ( ) . unwrap ( ) ;
630
+
631
+ match candidate {
632
+ ImplCandidate ( def_id) => {
633
+ match ty:: trait_impl_polarity ( self . tcx ( ) , def_id) {
634
+ Some ( ast:: ImplPolarity :: Negative ) => return Err ( Unimplemented ) ,
635
+ _ => { }
636
+ }
637
+ }
638
+ _ => { }
639
+ }
640
+
629
641
Ok ( Some ( candidate) )
630
642
}
631
643
@@ -714,15 +726,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
714
726
debug ! ( "obligation self ty is {}" ,
715
727
obligation. predicate. 0 . self_ty( ) . repr( self . tcx( ) ) ) ;
716
728
717
- try!( self . assemble_candidates_from_impls ( obligation, & mut candidates. vec ) ) ;
729
+ try!( self . assemble_candidates_from_impls ( obligation, & mut candidates) ) ;
718
730
719
731
try!( self . assemble_builtin_bound_candidates ( ty:: BoundCopy ,
720
732
stack,
721
733
& mut candidates) ) ;
722
734
}
723
735
Some ( bound @ ty:: BoundSend ) |
724
736
Some ( bound @ ty:: BoundSync ) => {
725
- try!( self . assemble_candidates_from_impls ( obligation, & mut candidates. vec ) ) ;
737
+ try!( self . assemble_candidates_from_impls ( obligation, & mut candidates) ) ;
726
738
727
739
// No explicit impls were declared for this type, consider the fallback rules.
728
740
if candidates. vec . is_empty ( ) && !candidates. ambiguous {
@@ -741,7 +753,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
741
753
// (And unboxed candidates only apply to the Fn/FnMut/etc traits.)
742
754
try!( self . assemble_unboxed_closure_candidates ( obligation, & mut candidates) ) ;
743
755
try!( self . assemble_fn_pointer_candidates ( obligation, & mut candidates) ) ;
744
- try!( self . assemble_candidates_from_impls ( obligation, & mut candidates. vec ) ) ;
756
+ try!( self . assemble_candidates_from_impls ( obligation, & mut candidates) ) ;
745
757
self . assemble_candidates_from_object_ty ( obligation, & mut candidates) ;
746
758
}
747
759
}
@@ -1013,9 +1025,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1013
1025
/// Search for impls that might apply to `obligation`.
1014
1026
fn assemble_candidates_from_impls ( & mut self ,
1015
1027
obligation : & TraitObligation < ' tcx > ,
1016
- candidate_vec : & mut Vec < SelectionCandidate < ' tcx > > )
1028
+ candidates : & mut SelectionCandidateSet < ' tcx > )
1017
1029
-> Result < ( ) , SelectionError < ' tcx > >
1018
1030
{
1031
+ let self_ty = self . infcx . shallow_resolve ( obligation. self_ty ( ) ) ;
1032
+ debug ! ( "assemble_candidates_from_impls(self_ty={})" , self_ty. repr( self . tcx( ) ) ) ;
1033
+
1019
1034
let all_impls = self . all_impls ( obligation. predicate . def_id ( ) ) ;
1020
1035
for & impl_def_id in all_impls. iter ( ) {
1021
1036
self . infcx . probe ( |snapshot| {
@@ -1024,7 +1039,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1024
1039
match self . match_impl ( impl_def_id, obligation, snapshot,
1025
1040
& skol_map, skol_obligation_trait_pred. trait_ref . clone ( ) ) {
1026
1041
Ok ( _) => {
1027
- candidate_vec . push ( ImplCandidate ( impl_def_id) ) ;
1042
+ candidates . vec . push ( ImplCandidate ( impl_def_id) ) ;
1028
1043
}
1029
1044
Err ( ( ) ) => { }
1030
1045
}
@@ -2214,12 +2229,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2214
2229
2215
2230
/// Returns set of all impls for a given trait.
2216
2231
fn all_impls ( & self , trait_def_id : ast:: DefId ) -> Vec < ast:: DefId > {
2217
- ty:: populate_implementations_for_trait_if_necessary ( self . tcx ( ) ,
2218
- trait_def_id ) ;
2219
- match self . tcx ( ) . trait_impls . borrow ( ) . get ( & trait_def_id) {
2232
+ ty:: populate_implementations_for_trait_if_necessary ( self . tcx ( ) , trait_def_id ) ;
2233
+
2234
+ let mut trait_impls = match self . tcx ( ) . trait_impls . borrow ( ) . get ( & trait_def_id) {
2220
2235
None => Vec :: new ( ) ,
2221
2236
Some ( impls) => impls. borrow ( ) . clone ( )
2222
- }
2237
+ } ;
2238
+
2239
+ match self . tcx ( ) . trait_negative_impls . borrow ( ) . get ( & trait_def_id) {
2240
+ None => { } ,
2241
+ Some ( impls) => trait_impls. push_all ( impls. borrow ( ) . as_slice ( ) ) ,
2242
+ } ;
2243
+
2244
+ trait_impls
2223
2245
}
2224
2246
2225
2247
fn impl_obligations ( & mut self ,
0 commit comments