@@ -102,6 +102,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
102102 "...so that the definition in impl matches the definition from the trait" ,
103103 ) ;
104104 }
105+ infer:: CheckAssociatedTypeBounds { ref parent, .. } => {
106+ self . note_region_origin ( err, & parent) ;
107+ }
105108 }
106109 }
107110
@@ -345,6 +348,55 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
345348 trait_item_def_id,
346349 & format ! ( "`{}: {}`" , sup, sub) ,
347350 ) ,
351+ infer:: CheckAssociatedTypeBounds { impl_item_def_id, trait_item_def_id, parent } => {
352+ let mut err = self . report_concrete_failure ( * parent, sub, sup) ;
353+
354+ let trait_item_span = self . tcx . def_span ( trait_item_def_id) ;
355+ let item_name = self . tcx . item_name ( impl_item_def_id) ;
356+ err. span_label (
357+ trait_item_span,
358+ format ! ( "definition of `{}` from trait" , item_name) ,
359+ ) ;
360+
361+ let trait_predicates = self . tcx . explicit_predicates_of ( trait_item_def_id) ;
362+ let impl_predicates = self . tcx . explicit_predicates_of ( impl_item_def_id) ;
363+
364+ let impl_predicates: rustc_data_structures:: stable_set:: FxHashSet < _ > =
365+ impl_predicates. predicates . into_iter ( ) . map ( |( pred, _) | pred) . collect ( ) ;
366+ let clauses: Vec < _ > = trait_predicates
367+ . predicates
368+ . into_iter ( )
369+ . filter ( |& ( pred, _) | !impl_predicates. contains ( pred) )
370+ . map ( |( pred, _) | format ! ( "{}" , pred) )
371+ . collect ( ) ;
372+
373+ if !clauses. is_empty ( ) {
374+ let where_clause_span = self
375+ . tcx
376+ . hir ( )
377+ . get_generics ( impl_item_def_id. expect_local ( ) )
378+ . unwrap ( )
379+ . where_clause
380+ . tail_span_for_suggestion ( ) ;
381+
382+ let suggestion = format ! (
383+ "{} {}" ,
384+ if !impl_predicates. is_empty( ) { "," } else { " where" } ,
385+ clauses. join( ", " ) ,
386+ ) ;
387+ err. span_suggestion (
388+ where_clause_span,
389+ & format ! (
390+ "try copying {} from the trait" ,
391+ if clauses. len( ) > 1 { "these clauses" } else { "this clause" }
392+ ) ,
393+ suggestion,
394+ rustc_errors:: Applicability :: MaybeIncorrect ,
395+ ) ;
396+ }
397+
398+ err
399+ }
348400 }
349401 }
350402
0 commit comments