1
- use crate :: traits:: specialization_graph;
1
+ use crate :: traits:: { check_args_compatible , specialization_graph} ;
2
2
3
3
use super :: assembly:: { self , structural_traits} ;
4
4
use super :: EvalCtxt ;
@@ -190,11 +190,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
190
190
return ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS ) ;
191
191
} ;
192
192
193
- if !assoc_def. item . defaultness ( tcx) . has_value ( ) {
194
- let guar = tcx. sess . delay_span_bug (
195
- tcx. def_span ( assoc_def. item . def_id ) ,
196
- "missing value for assoc item in impl" ,
197
- ) ;
193
+ let error_response = |ecx : & mut EvalCtxt < ' _ , ' tcx > , reason| {
194
+ let guar = tcx. sess . delay_span_bug ( tcx. def_span ( assoc_def. item . def_id ) , reason) ;
198
195
let error_term = match assoc_def. item . kind {
199
196
ty:: AssocKind :: Const => ty:: Const :: new_error (
200
197
tcx,
@@ -208,7 +205,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
208
205
} ;
209
206
ecx. eq ( goal. param_env , goal. predicate . term , error_term)
210
207
. expect ( "expected goal term to be fully unconstrained" ) ;
211
- return ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes ) ;
208
+ ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
209
+ } ;
210
+
211
+ if !assoc_def. item . defaultness ( tcx) . has_value ( ) {
212
+ return error_response ( ecx, "missing value for assoc item in impl" ) ;
212
213
}
213
214
214
215
// Getting the right args here is complex, e.g. given:
@@ -233,6 +234,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
233
234
assoc_def. defining_node ,
234
235
) ;
235
236
237
+ if !check_args_compatible ( tcx, assoc_def. item , args) {
238
+ return error_response (
239
+ ecx,
240
+ "associated item has mismatched generic item arguments" ,
241
+ ) ;
242
+ }
243
+
236
244
// Finally we construct the actual value of the associated type.
237
245
let term = match assoc_def. item . kind {
238
246
ty:: AssocKind :: Type => tcx. type_of ( assoc_def. item . def_id ) . map_bound ( |ty| ty. into ( ) ) ,
0 commit comments