1- use crate :: traits:: specialization_graph;
1+ use crate :: traits:: { check_args_compatible , specialization_graph} ;
22
33use super :: assembly:: { self , structural_traits} ;
44use super :: EvalCtxt ;
@@ -190,11 +190,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
190190 return ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS ) ;
191191 } ;
192192
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) ;
198195 let error_term = match assoc_def. item . kind {
199196 ty:: AssocKind :: Const => ty:: Const :: new_error (
200197 tcx,
@@ -208,7 +205,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
208205 } ;
209206 ecx. eq ( goal. param_env , goal. predicate . term , error_term)
210207 . 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" ) ;
212213 }
213214
214215 // Getting the right args here is complex, e.g. given:
@@ -233,6 +234,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
233234 assoc_def. defining_node ,
234235 ) ;
235236
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+
236244 // Finally we construct the actual value of the associated type.
237245 let term = match assoc_def. item . kind {
238246 ty:: AssocKind :: Type => tcx. type_of ( assoc_def. item . def_id ) . map_bound ( |ty| ty. into ( ) ) ,
0 commit comments