@@ -162,15 +162,28 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
162162 let tcx = ecx. tcx ( ) ;
163163
164164 let goal_trait_ref = goal. predicate . alias . trait_ref ( tcx) ;
165- let impl_trait_ref = tcx. impl_trait_ref ( impl_def_id) . unwrap ( ) ;
165+ let impl_trait_header = tcx. impl_trait_header ( impl_def_id) . unwrap ( ) ;
166166 let drcx = DeepRejectCtxt { treat_obligation_params : TreatParams :: ForLookup } ;
167- if !drcx. args_may_unify ( goal_trait_ref. args , impl_trait_ref. skip_binder ( ) . args ) {
167+ if !drcx. args_may_unify (
168+ goal. predicate . trait_ref ( tcx) . args ,
169+ impl_trait_header. skip_binder ( ) . trait_ref . args ,
170+ ) {
168171 return Err ( NoSolution ) ;
169172 }
170173
174+ // We have to ignore negative impls when projecting.
175+ let impl_polarity = impl_trait_header. skip_binder ( ) . polarity ;
176+ match impl_polarity {
177+ ty:: ImplPolarity :: Negative => return Err ( NoSolution ) ,
178+ ty:: ImplPolarity :: Reservation => {
179+ unimplemented ! ( "reservation impl for trait with assoc item: {:?}" , goal)
180+ }
181+ ty:: ImplPolarity :: Positive => { }
182+ } ;
183+
171184 ecx. probe_trait_candidate ( CandidateSource :: Impl ( impl_def_id) ) . enter ( |ecx| {
172185 let impl_args = ecx. fresh_args_for_item ( impl_def_id) ;
173- let impl_trait_ref = impl_trait_ref . instantiate ( tcx, impl_args) ;
186+ let impl_trait_ref = impl_trait_header . instantiate ( tcx, impl_args) . trait_ref ;
174187
175188 ecx. eq ( goal. param_env , goal_trait_ref, impl_trait_ref) ?;
176189
0 commit comments