@@ -25,14 +25,14 @@ 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 > (
28
+ pub ( super ) fn check_trait < ' tcx > (
29
29
tcx : TyCtxt < ' tcx > ,
30
30
trait_def_id : DefId ,
31
31
impl_def_id : LocalDefId ,
32
32
impl_header : ty:: ImplTraitHeader < ' tcx > ,
33
33
) -> Result < ( ) , ErrorGuaranteed > {
34
34
let lang_items = tcx. lang_items ( ) ;
35
- let checker = Checker { tcx, trait_def_id, impl_def_id, impl_header } ;
35
+ let checker = Checker :: new ( tcx, trait_def_id, impl_def_id, impl_header) ;
36
36
let mut res = checker. check ( lang_items. drop_trait ( ) , visit_implementation_of_drop) ;
37
37
res = res. and ( checker. check ( lang_items. copy_trait ( ) , visit_implementation_of_copy) ) ;
38
38
res = res. and (
@@ -52,9 +52,19 @@ struct Checker<'tcx> {
52
52
trait_def_id : DefId ,
53
53
impl_def_id : LocalDefId ,
54
54
impl_header : ty:: ImplTraitHeader < ' tcx > ,
55
+ trait_ref : ty:: TraitRef < ' tcx > ,
55
56
}
56
57
57
58
impl < ' tcx > Checker < ' tcx > {
59
+ fn new (
60
+ tcx : TyCtxt < ' tcx > ,
61
+ trait_def_id : DefId ,
62
+ impl_def_id : LocalDefId ,
63
+ impl_header : ty:: ImplTraitHeader < ' tcx > ,
64
+ ) -> Self {
65
+ let trait_ref = impl_header. trait_ref . instantiate_identity ( ) ;
66
+ Self { tcx, trait_def_id, impl_def_id, impl_header, trait_ref }
67
+ }
58
68
fn check (
59
69
& self ,
60
70
trait_def_id : Option < DefId > ,
@@ -66,10 +76,9 @@ impl<'tcx> Checker<'tcx> {
66
76
67
77
fn visit_implementation_of_drop ( checker : & Checker < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
68
78
let tcx = checker. tcx ;
69
- let header = checker. impl_header ;
70
79
let impl_did = checker. impl_def_id ;
71
80
// Destructors only work on local ADT types.
72
- match header . trait_ref . self_ty ( ) . kind ( ) {
81
+ match checker . trait_ref . self_ty ( ) . kind ( ) {
73
82
ty:: Adt ( def, _) if def. did ( ) . is_local ( ) => return Ok ( ( ) ) ,
74
83
ty:: Error ( _) => return Ok ( ( ) ) ,
75
84
_ => { }
@@ -86,7 +95,7 @@ fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaran
86
95
let impl_did = checker. impl_def_id ;
87
96
debug ! ( "visit_implementation_of_copy: impl_did={:?}" , impl_did) ;
88
97
89
- let self_type = impl_header . trait_ref . self_ty ( ) ;
98
+ let self_type = checker . trait_ref . self_ty ( ) ;
90
99
debug ! ( "visit_implementation_of_copy: self_type={:?} (bound)" , self_type) ;
91
100
92
101
let param_env = tcx. param_env ( impl_did) ;
@@ -120,7 +129,7 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E
120
129
let tcx = checker. tcx ;
121
130
let header = checker. impl_header ;
122
131
let impl_did = checker. impl_def_id ;
123
- let self_type = header . trait_ref . self_ty ( ) ;
132
+ let self_type = checker . trait_ref . self_ty ( ) ;
124
133
assert ! ( !self_type. has_escaping_bound_vars( ) ) ;
125
134
126
135
let param_env = tcx. param_env ( impl_did) ;
@@ -157,9 +166,8 @@ fn visit_implementation_of_coerce_unsized(checker: &Checker<'_>) -> Result<(), E
157
166
158
167
fn visit_implementation_of_dispatch_from_dyn ( checker : & Checker < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
159
168
let tcx = checker. tcx ;
160
- let header = checker. impl_header ;
161
169
let impl_did = checker. impl_def_id ;
162
- let trait_ref = header . trait_ref ;
170
+ let trait_ref = checker . trait_ref ;
163
171
debug ! ( "visit_implementation_of_dispatch_from_dyn: impl_did={:?}" , impl_did) ;
164
172
165
173
let span = tcx. def_span ( impl_did) ;
0 commit comments