@@ -79,19 +79,19 @@ use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
79
79
use rustc_span:: Span ;
80
80
use rustc_trait_selection:: traits:: { self , translate_substs, wf} ;
81
81
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 ) {
83
83
if let Some ( node) = parent_specialization_node ( tcx, impl_def_id) {
84
84
tcx. infer_ctxt ( ) . enter ( |infcx| {
85
- check_always_applicable ( & infcx, impl_def_id, node, span ) ;
85
+ check_always_applicable ( & infcx, impl_def_id, node) ;
86
86
} ) ;
87
87
}
88
88
}
89
89
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 > {
91
91
let trait_ref = tcx. impl_trait_ref ( impl1_def_id) ?;
92
92
let trait_def = tcx. trait_def ( trait_ref. def_id ) ;
93
93
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 ) ?;
95
95
96
96
let always_applicable_trait =
97
97
matches ! ( trait_def. specialization_kind, TraitSpecializationKind :: AlwaysApplicable ) ;
@@ -103,15 +103,8 @@ fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: DefId) -> Option<No
103
103
}
104
104
105
105
/// 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) {
115
108
let impl2_def_id = impl2_node. def_id ( ) ;
116
109
debug ! (
117
110
"check_always_applicable(\n impl1_def_id={:?},\n impl2_def_id={:?},\n impl2_substs={:?}\n )" ,
@@ -126,17 +119,10 @@ fn check_always_applicable(
126
119
unconstrained_parent_impl_substs ( tcx, impl2_def_id, impl2_substs)
127
120
} ;
128
121
122
+ let span = tcx. def_span ( impl1_def_id) ;
129
123
check_static_lifetimes ( tcx, & parent_substs, span) ;
130
124
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) ;
140
126
}
141
127
}
142
128
@@ -152,20 +138,21 @@ fn check_always_applicable(
152
138
/// Would return `S1 = [C]` and `S2 = [Vec<C>, C]`.
153
139
fn get_impl_substs < ' tcx > (
154
140
infcx : & InferCtxt < ' _ , ' tcx > ,
155
- impl1_def_id : DefId ,
141
+ impl1_def_id : LocalDefId ,
156
142
impl2_node : Node ,
157
- span : Span ,
158
143
) -> Option < ( SubstsRef < ' tcx > , SubstsRef < ' tcx > ) > {
159
144
let tcx = infcx. tcx ;
160
145
let param_env = tcx. param_env ( impl1_def_id) ;
161
146
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) ;
164
150
165
151
// Conservatively use an empty `ParamEnv`.
166
152
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) ;
168
154
let Ok ( impl2_substs) = infcx. fully_resolve ( impl2_substs) else {
155
+ let span = tcx. def_span ( impl1_def_id) ;
169
156
tcx. sess . emit_err ( SubstsOnOverriddenImpl { span } ) ;
170
157
return None ;
171
158
} ;
0 commit comments