@@ -32,7 +32,7 @@ impl<'a, 'tcx> Deref for ConfirmContext<'a, 'tcx> {
3232
3333pub struct ConfirmResult < ' tcx > {
3434 pub callee : MethodCallee < ' tcx > ,
35- pub illegal_sized_bound : bool ,
35+ pub illegal_sized_bound : Option < Span > ,
3636}
3737
3838impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
@@ -112,7 +112,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
112112 // Add any trait/regions obligations specified on the method's type parameters.
113113 // We won't add these if we encountered an illegal sized bound, so that we can use
114114 // a custom error in that case.
115- if ! illegal_sized_bound {
115+ if illegal_sized_bound. is_none ( ) {
116116 let method_ty = self . tcx . mk_fn_ptr ( ty:: Binder :: bind ( method_sig) ) ;
117117 self . add_obligations ( method_ty, all_substs, & method_predicates) ;
118118 }
@@ -561,23 +561,31 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
561561 fn predicates_require_illegal_sized_bound (
562562 & self ,
563563 predicates : & ty:: InstantiatedPredicates < ' tcx > ,
564- ) -> bool {
564+ ) -> Option < Span > {
565565 let sized_def_id = match self . tcx . lang_items ( ) . sized_trait ( ) {
566566 Some ( def_id) => def_id,
567- None => return false ,
567+ None => return None ,
568568 } ;
569569
570570 traits:: elaborate_predicates ( self . tcx , predicates. predicates . clone ( ) )
571571 . filter_map ( |predicate| match predicate {
572572 ty:: Predicate :: Trait ( trait_pred, _) if trait_pred. def_id ( ) == sized_def_id => {
573- Some ( trait_pred)
573+ let span = predicates
574+ . predicates
575+ . iter ( )
576+ . zip ( predicates. spans . iter ( ) )
577+ . filter_map ( |( p, span) | if * p == predicate { Some ( * span) } else { None } )
578+ . next ( )
579+ . unwrap_or ( rustc_span:: DUMMY_SP ) ;
580+ Some ( ( trait_pred, span) )
574581 }
575582 _ => None ,
576583 } )
577- . any ( | trait_pred| match trait_pred. skip_binder ( ) . self_ty ( ) . kind {
578- ty:: Dynamic ( ..) => true ,
579- _ => false ,
584+ . filter_map ( | ( trait_pred, span ) | match trait_pred. skip_binder ( ) . self_ty ( ) . kind {
585+ ty:: Dynamic ( ..) => Some ( span ) ,
586+ _ => None ,
580587 } )
588+ . next ( )
581589 }
582590
583591 fn enforce_illegal_method_limitations ( & self , pick : & probe:: Pick < ' _ > ) {
0 commit comments