@@ -25,9 +25,13 @@ use rustc_trait_selection::traits::ObligationCtxt;
25
25
use rustc_trait_selection:: traits:: { self , ObligationCause } ;
26
26
use std:: collections:: BTreeMap ;
27
27
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 > {
29
33
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 } ;
31
35
let mut res = checker. check ( lang_items. drop_trait ( ) , visit_implementation_of_drop) ;
32
36
res = res. and ( checker. check ( lang_items. copy_trait ( ) , visit_implementation_of_copy) ) ;
33
37
res = res. and (
@@ -45,6 +49,7 @@ pub fn check_trait(tcx: TyCtxt<'_>, trait_def_id: DefId) -> Result<(), ErrorGuar
45
49
struct Checker < ' tcx > {
46
50
tcx : TyCtxt < ' tcx > ,
47
51
trait_def_id : DefId ,
52
+ impl_def_id : LocalDefId ,
48
53
}
49
54
50
55
impl < ' tcx > Checker < ' tcx > {
@@ -54,9 +59,7 @@ impl<'tcx> Checker<'tcx> {
54
59
{
55
60
let mut res = Ok ( ( ) ) ;
56
61
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 ) ) ;
60
63
}
61
64
res
62
65
}
@@ -92,10 +95,10 @@ fn visit_implementation_of_copy(
92
95
93
96
debug ! ( "visit_implementation_of_copy: self_type={:?} (free)" , self_type) ;
94
97
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 ;
99
102
100
103
let cause = traits:: ObligationCause :: misc ( span, impl_did) ;
101
104
match type_allowed_to_implement_copy ( tcx, param_env, self_type, cause) {
@@ -121,10 +124,10 @@ fn visit_implementation_of_const_param_ty(
121
124
122
125
let param_env = tcx. param_env ( impl_did) ;
123
126
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 ;
128
131
129
132
let cause = traits:: ObligationCause :: misc ( span, impl_did) ;
130
133
match type_allowed_to_implement_const_param_ty ( tcx, param_env, self_type, cause) {
0 commit comments