@@ -32,7 +32,7 @@ impl<'a, 'tcx> Deref for ConfirmContext<'a, 'tcx> {
32
32
33
33
pub struct ConfirmResult < ' tcx > {
34
34
pub callee : MethodCallee < ' tcx > ,
35
- pub illegal_sized_bound : bool ,
35
+ pub illegal_sized_bound : Option < Span > ,
36
36
}
37
37
38
38
impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
@@ -112,7 +112,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
112
112
// Add any trait/regions obligations specified on the method's type parameters.
113
113
// We won't add these if we encountered an illegal sized bound, so that we can use
114
114
// a custom error in that case.
115
- if ! illegal_sized_bound {
115
+ if illegal_sized_bound. is_none ( ) {
116
116
let method_ty = self . tcx . mk_fn_ptr ( ty:: Binder :: bind ( method_sig) ) ;
117
117
self . add_obligations ( method_ty, all_substs, & method_predicates) ;
118
118
}
@@ -561,23 +561,31 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
561
561
fn predicates_require_illegal_sized_bound (
562
562
& self ,
563
563
predicates : & ty:: InstantiatedPredicates < ' tcx > ,
564
- ) -> bool {
564
+ ) -> Option < Span > {
565
565
let sized_def_id = match self . tcx . lang_items ( ) . sized_trait ( ) {
566
566
Some ( def_id) => def_id,
567
- None => return false ,
567
+ None => return None ,
568
568
} ;
569
569
570
570
traits:: elaborate_predicates ( self . tcx , predicates. predicates . clone ( ) )
571
571
. filter_map ( |predicate| match predicate {
572
572
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) )
574
581
}
575
582
_ => None ,
576
583
} )
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 ,
580
587
} )
588
+ . next ( )
581
589
}
582
590
583
591
fn enforce_illegal_method_limitations ( & self , pick : & probe:: Pick < ' _ > ) {
0 commit comments