File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
compiler/rustc_trait_selection/src/traits/error_reporting Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ pub fn recompute_applicable_impls<'tcx>(
1919 let tcx = infcx. tcx ;
2020 let param_env = obligation. param_env ;
2121
22+ let predicate_polarity = obligation. predicate . skip_binder ( ) . polarity ;
23+
2224 let impl_may_apply = |impl_def_id| {
2325 let ocx = ObligationCtxt :: new ( infcx) ;
2426 infcx. enter_forall ( obligation. predicate , |placeholder_obligation| {
@@ -40,6 +42,21 @@ pub fn recompute_applicable_impls<'tcx>(
4042 return false ;
4143 }
4244
45+ let impl_trait_header = tcx. impl_trait_header ( impl_def_id) . unwrap ( ) ;
46+
47+ let impl_polarity = impl_trait_header. polarity ;
48+ match impl_polarity {
49+ ty:: ImplPolarity :: Positive | ty:: ImplPolarity :: Negative => {
50+ match impl_polarity == predicate_polarity {
51+ true => { }
52+ false => return false ,
53+ }
54+ }
55+ ty:: ImplPolarity :: Reservation => {
56+ return false ;
57+ }
58+ }
59+
4360 let impl_predicates = tcx. predicates_of ( impl_def_id) . instantiate ( tcx, impl_args) ;
4461 ocx. register_obligations ( impl_predicates. predicates . iter ( ) . map ( |& predicate| {
4562 Obligation :: new ( tcx, ObligationCause :: dummy ( ) , param_env, predicate)
You can’t perform that action at this time.
0 commit comments