@@ -12,6 +12,7 @@ use rustc_hir::def::DefKind;
1212use rustc_hir:: def_id:: { CRATE_DEF_ID , DefId } ;
1313use rustc_infer:: infer:: { DefineOpaqueTypes , InferCtxt , TyCtxtInferExt } ;
1414use rustc_infer:: traits:: PredicateObligations ;
15+ use rustc_macros:: { TypeFoldable , TypeVisitable } ;
1516use rustc_middle:: bug;
1617use rustc_middle:: traits:: query:: NoSolution ;
1718use rustc_middle:: traits:: solve:: { CandidateSource , Certainty , Goal } ;
@@ -37,8 +38,20 @@ use crate::traits::{
3738 SelectionContext , SkipLeakCheck , util,
3839} ;
3940
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+
4053pub struct OverlapResult < ' tcx > {
41- pub impl_header : ty :: ImplHeader < ' tcx > ,
54+ pub impl_header : ImplHeader < ' tcx > ,
4255 pub intercrate_ambiguity_causes : FxIndexSet < IntercrateAmbiguityCause < ' tcx > > ,
4356
4457 /// `true` if the overlap might've been permitted before the shift
@@ -151,11 +164,11 @@ pub fn overlapping_impls(
151164 }
152165}
153166
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 > {
155168 let tcx = infcx. tcx ;
156169 let impl_args = infcx. fresh_args_for_item ( DUMMY_SP , impl_def_id) ;
157170
158- ty :: ImplHeader {
171+ ImplHeader {
159172 impl_def_id,
160173 impl_args,
161174 self_ty : tcx. type_of ( impl_def_id) . instantiate ( tcx, impl_args) ,
@@ -173,7 +186,7 @@ fn fresh_impl_header_normalized<'tcx>(
173186 infcx : & InferCtxt < ' tcx > ,
174187 param_env : ty:: ParamEnv < ' tcx > ,
175188 impl_def_id : DefId ,
176- ) -> ty :: ImplHeader < ' tcx > {
189+ ) -> ImplHeader < ' tcx > {
177190 let header = fresh_impl_header ( infcx, impl_def_id) ;
178191
179192 let InferOk { value : mut header, obligations } =
@@ -287,8 +300,8 @@ fn overlap<'tcx>(
287300fn equate_impl_headers < ' tcx > (
288301 infcx : & InferCtxt < ' tcx > ,
289302 param_env : ty:: ParamEnv < ' tcx > ,
290- impl1 : & ty :: ImplHeader < ' tcx > ,
291- impl2 : & ty :: ImplHeader < ' tcx > ,
303+ impl1 : & ImplHeader < ' tcx > ,
304+ impl2 : & ImplHeader < ' tcx > ,
292305) -> Option < PredicateObligations < ' tcx > > {
293306 let result =
294307 match ( impl1. trait_ref , impl2. trait_ref ) {
0 commit comments