@@ -12,6 +12,7 @@ use rustc_hir::def::DefKind;
12
12
use rustc_hir:: def_id:: { CRATE_DEF_ID , DefId } ;
13
13
use rustc_infer:: infer:: { DefineOpaqueTypes , InferCtxt , TyCtxtInferExt } ;
14
14
use rustc_infer:: traits:: PredicateObligations ;
15
+ use rustc_macros:: { TypeFoldable , TypeVisitable } ;
15
16
use rustc_middle:: bug;
16
17
use rustc_middle:: traits:: query:: NoSolution ;
17
18
use rustc_middle:: traits:: solve:: { CandidateSource , Certainty , Goal } ;
@@ -37,8 +38,20 @@ use crate::traits::{
37
38
SelectionContext , SkipLeakCheck , util,
38
39
} ;
39
40
41
+ /// The "header" of an impl is everything outside the body: a Self type, a trait
42
+ /// ref (in the case of a trait impl), and a set of predicates (from the
43
+ /// bounds / where-clauses).
44
+ #[ derive( Clone , Debug , TypeFoldable , TypeVisitable ) ]
45
+ pub struct ImplHeader < ' tcx > {
46
+ pub impl_def_id : DefId ,
47
+ pub impl_args : ty:: GenericArgsRef < ' tcx > ,
48
+ pub self_ty : Ty < ' tcx > ,
49
+ pub trait_ref : Option < ty:: TraitRef < ' tcx > > ,
50
+ pub predicates : Vec < ty:: Predicate < ' tcx > > ,
51
+ }
52
+
40
53
pub struct OverlapResult < ' tcx > {
41
- pub impl_header : ty :: ImplHeader < ' tcx > ,
54
+ pub impl_header : ImplHeader < ' tcx > ,
42
55
pub intercrate_ambiguity_causes : FxIndexSet < IntercrateAmbiguityCause < ' tcx > > ,
43
56
44
57
/// `true` if the overlap might've been permitted before the shift
@@ -151,11 +164,11 @@ pub fn overlapping_impls(
151
164
}
152
165
}
153
166
154
- fn fresh_impl_header < ' tcx > ( infcx : & InferCtxt < ' tcx > , impl_def_id : DefId ) -> ty :: ImplHeader < ' tcx > {
167
+ fn fresh_impl_header < ' tcx > ( infcx : & InferCtxt < ' tcx > , impl_def_id : DefId ) -> ImplHeader < ' tcx > {
155
168
let tcx = infcx. tcx ;
156
169
let impl_args = infcx. fresh_args_for_item ( DUMMY_SP , impl_def_id) ;
157
170
158
- ty :: ImplHeader {
171
+ ImplHeader {
159
172
impl_def_id,
160
173
impl_args,
161
174
self_ty : tcx. type_of ( impl_def_id) . instantiate ( tcx, impl_args) ,
@@ -173,7 +186,7 @@ fn fresh_impl_header_normalized<'tcx>(
173
186
infcx : & InferCtxt < ' tcx > ,
174
187
param_env : ty:: ParamEnv < ' tcx > ,
175
188
impl_def_id : DefId ,
176
- ) -> ty :: ImplHeader < ' tcx > {
189
+ ) -> ImplHeader < ' tcx > {
177
190
let header = fresh_impl_header ( infcx, impl_def_id) ;
178
191
179
192
let InferOk { value : mut header, obligations } =
@@ -287,8 +300,8 @@ fn overlap<'tcx>(
287
300
fn equate_impl_headers < ' tcx > (
288
301
infcx : & InferCtxt < ' tcx > ,
289
302
param_env : ty:: ParamEnv < ' tcx > ,
290
- impl1 : & ty :: ImplHeader < ' tcx > ,
291
- impl2 : & ty :: ImplHeader < ' tcx > ,
303
+ impl1 : & ImplHeader < ' tcx > ,
304
+ impl2 : & ImplHeader < ' tcx > ,
292
305
) -> Option < PredicateObligations < ' tcx > > {
293
306
let result =
294
307
match ( impl1. trait_ref , impl2. trait_ref ) {
0 commit comments