@@ -79,19 +79,19 @@ use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
7979use rustc_span:: Span ;
8080use rustc_trait_selection:: traits:: { self , translate_substs, wf} ;
8181
82- pub ( super ) fn check_min_specialization ( tcx : TyCtxt < ' _ > , impl_def_id : DefId , span : Span ) {
82+ pub ( super ) fn check_min_specialization ( tcx : TyCtxt < ' _ > , impl_def_id : LocalDefId ) {
8383 if let Some ( node) = parent_specialization_node ( tcx, impl_def_id) {
8484 tcx. infer_ctxt ( ) . enter ( |infcx| {
85- check_always_applicable ( & infcx, impl_def_id, node, span ) ;
85+ check_always_applicable ( & infcx, impl_def_id, node) ;
8686 } ) ;
8787 }
8888}
8989
90- fn parent_specialization_node ( tcx : TyCtxt < ' _ > , impl1_def_id : DefId ) -> Option < Node > {
90+ fn parent_specialization_node ( tcx : TyCtxt < ' _ > , impl1_def_id : LocalDefId ) -> Option < Node > {
9191 let trait_ref = tcx. impl_trait_ref ( impl1_def_id) ?;
9292 let trait_def = tcx. trait_def ( trait_ref. def_id ) ;
9393
94- let impl2_node = trait_def. ancestors ( tcx, impl1_def_id) . ok ( ) ?. nth ( 1 ) ?;
94+ let impl2_node = trait_def. ancestors ( tcx, impl1_def_id. to_def_id ( ) ) . ok ( ) ?. nth ( 1 ) ?;
9595
9696 let always_applicable_trait =
9797 matches ! ( trait_def. specialization_kind, TraitSpecializationKind :: AlwaysApplicable ) ;
@@ -103,15 +103,8 @@ fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: DefId) -> Option<No
103103}
104104
105105/// Check that `impl1` is a sound specialization
106- fn check_always_applicable (
107- infcx : & InferCtxt < ' _ , ' _ > ,
108- impl1_def_id : DefId ,
109- impl2_node : Node ,
110- span : Span ,
111- ) {
112- if let Some ( ( impl1_substs, impl2_substs) ) =
113- get_impl_substs ( infcx, impl1_def_id, impl2_node, span)
114- {
106+ fn check_always_applicable ( infcx : & InferCtxt < ' _ , ' _ > , impl1_def_id : LocalDefId , impl2_node : Node ) {
107+ if let Some ( ( impl1_substs, impl2_substs) ) = get_impl_substs ( infcx, impl1_def_id, impl2_node) {
115108 let impl2_def_id = impl2_node. def_id ( ) ;
116109 debug ! (
117110 "check_always_applicable(\n impl1_def_id={:?},\n impl2_def_id={:?},\n impl2_substs={:?}\n )" ,
@@ -126,17 +119,10 @@ fn check_always_applicable(
126119 unconstrained_parent_impl_substs ( tcx, impl2_def_id, impl2_substs)
127120 } ;
128121
122+ let span = tcx. def_span ( impl1_def_id) ;
129123 check_static_lifetimes ( tcx, & parent_substs, span) ;
130124 check_duplicate_params ( tcx, impl1_substs, & parent_substs, span) ;
131-
132- check_predicates (
133- infcx,
134- impl1_def_id. expect_local ( ) ,
135- impl1_substs,
136- impl2_node,
137- impl2_substs,
138- span,
139- ) ;
125+ check_predicates ( infcx, impl1_def_id, impl1_substs, impl2_node, impl2_substs, span) ;
140126 }
141127}
142128
@@ -152,20 +138,21 @@ fn check_always_applicable(
152138/// Would return `S1 = [C]` and `S2 = [Vec<C>, C]`.
153139fn get_impl_substs < ' tcx > (
154140 infcx : & InferCtxt < ' _ , ' tcx > ,
155- impl1_def_id : DefId ,
141+ impl1_def_id : LocalDefId ,
156142 impl2_node : Node ,
157- span : Span ,
158143) -> Option < ( SubstsRef < ' tcx > , SubstsRef < ' tcx > ) > {
159144 let tcx = infcx. tcx ;
160145 let param_env = tcx. param_env ( impl1_def_id) ;
161146
162- let impl1_substs = InternalSubsts :: identity_for_item ( tcx, impl1_def_id) ;
163- let impl2_substs = translate_substs ( infcx, param_env, impl1_def_id, impl1_substs, impl2_node) ;
147+ let impl1_substs = InternalSubsts :: identity_for_item ( tcx, impl1_def_id. to_def_id ( ) ) ;
148+ let impl2_substs =
149+ translate_substs ( infcx, param_env, impl1_def_id. to_def_id ( ) , impl1_substs, impl2_node) ;
164150
165151 // Conservatively use an empty `ParamEnv`.
166152 let outlives_env = OutlivesEnvironment :: new ( ty:: ParamEnv :: empty ( ) ) ;
167- infcx. resolve_regions_and_report_errors ( impl1_def_id, & outlives_env) ;
153+ infcx. resolve_regions_and_report_errors ( impl1_def_id. to_def_id ( ) , & outlives_env) ;
168154 let Ok ( impl2_substs) = infcx. fully_resolve ( impl2_substs) else {
155+ let span = tcx. def_span ( impl1_def_id) ;
169156 tcx. sess . emit_err ( SubstsOnOverriddenImpl { span } ) ;
170157 return None ;
171158 } ;
0 commit comments