@@ -25,9 +25,13 @@ use rustc_trait_selection::traits::ObligationCtxt;
2525use rustc_trait_selection:: traits:: { self , ObligationCause } ;
2626use std:: collections:: BTreeMap ;
2727
28- pub fn check_trait ( tcx : TyCtxt < ' _ > , trait_def_id : DefId ) -> Result < ( ) , ErrorGuaranteed > {
28+ pub fn check_trait (
29+ tcx : TyCtxt < ' _ > ,
30+ trait_def_id : DefId ,
31+ impl_def_id : LocalDefId ,
32+ ) -> Result < ( ) , ErrorGuaranteed > {
2933 let lang_items = tcx. lang_items ( ) ;
30- let checker = Checker { tcx, trait_def_id } ;
34+ let checker = Checker { tcx, trait_def_id, impl_def_id } ;
3135 let mut res = checker. check ( lang_items. drop_trait ( ) , visit_implementation_of_drop) ;
3236 res = res. and ( checker. check ( lang_items. copy_trait ( ) , visit_implementation_of_copy) ) ;
3337 res = res. and (
@@ -45,6 +49,7 @@ pub fn check_trait(tcx: TyCtxt<'_>, trait_def_id: DefId) -> Result<(), ErrorGuar
4549struct Checker < ' tcx > {
4650 tcx : TyCtxt < ' tcx > ,
4751 trait_def_id : DefId ,
52+ impl_def_id : LocalDefId ,
4853}
4954
5055impl < ' tcx > Checker < ' tcx > {
@@ -54,9 +59,7 @@ impl<'tcx> Checker<'tcx> {
5459 {
5560 let mut res = Ok ( ( ) ) ;
5661 if Some ( self . trait_def_id ) == trait_def_id {
57- for & impl_def_id in self . tcx . hir ( ) . trait_impls ( self . trait_def_id ) {
58- res = res. and ( f ( self . tcx , impl_def_id) ) ;
59- }
62+ res = res. and ( f ( self . tcx , self . impl_def_id ) ) ;
6063 }
6164 res
6265 }
@@ -92,10 +95,10 @@ fn visit_implementation_of_copy(
9295
9396 debug ! ( "visit_implementation_of_copy: self_type={:?} (free)" , self_type) ;
9497
95- let span = match tcx. hir ( ) . expect_item ( impl_did) . expect_impl ( ) {
96- hir :: Impl { polarity : hir :: ImplPolarity :: Negative ( _ ) , .. } => return Ok ( ( ) ) ,
97- hir :: Impl { self_ty , .. } => self_ty . span ,
98- } ;
98+ if let ty :: ImplPolarity :: Negative = tcx. impl_polarity ( impl_did) {
99+ return Ok ( ( ) ) ;
100+ }
101+ let span = tcx . hir ( ) . expect_item ( impl_did ) . expect_impl ( ) . self_ty . span ;
99102
100103 let cause = traits:: ObligationCause :: misc ( span, impl_did) ;
101104 match type_allowed_to_implement_copy ( tcx, param_env, self_type, cause) {
@@ -121,10 +124,10 @@ fn visit_implementation_of_const_param_ty(
121124
122125 let param_env = tcx. param_env ( impl_did) ;
123126
124- let span = match tcx. hir ( ) . expect_item ( impl_did) . expect_impl ( ) {
125- hir :: Impl { polarity : hir :: ImplPolarity :: Negative ( _ ) , .. } => return Ok ( ( ) ) ,
126- impl_ => impl_ . self_ty . span ,
127- } ;
127+ if let ty :: ImplPolarity :: Negative = tcx. impl_polarity ( impl_did) {
128+ return Ok ( ( ) ) ;
129+ }
130+ let span = tcx . hir ( ) . expect_item ( impl_did ) . expect_impl ( ) . self_ty . span ;
128131
129132 let cause = traits:: ObligationCause :: misc ( span, impl_did) ;
130133 match type_allowed_to_implement_const_param_ty ( tcx, param_env, self_type, cause) {
0 commit comments