@@ -110,7 +110,7 @@ pub trait TypeErrCtxtExt<'tcx> {
110
110
obligation : & PredicateObligation < ' tcx > ,
111
111
trait_ref : ty:: TraitRef < ' tcx > ,
112
112
err : & mut Diagnostic ,
113
- ) ;
113
+ ) -> bool ;
114
114
115
115
fn report_const_param_not_wf (
116
116
& self ,
@@ -506,8 +506,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
506
506
507
507
let mut err = struct_span_err ! ( self . tcx. sess, span, E0277 , "{}" , err_msg) ;
508
508
509
+ let mut suggested = false ;
509
510
if is_try_conversion {
510
- self . try_conversion_context ( & obligation, trait_ref. skip_binder ( ) , & mut err) ;
511
+ suggested = self . try_conversion_context ( & obligation, trait_ref. skip_binder ( ) , & mut err) ;
511
512
}
512
513
513
514
if is_try_conversion && let Some ( ret_span) = self . return_type_span ( & obligation) {
@@ -608,8 +609,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
608
609
609
610
self . suggest_floating_point_literal ( & obligation, & mut err, & trait_ref) ;
610
611
self . suggest_dereferencing_index ( & obligation, & mut err, trait_predicate) ;
611
- let mut suggested =
612
- self . suggest_dereferences ( & obligation, & mut err, trait_predicate) ;
612
+ suggested |= self . suggest_dereferences ( & obligation, & mut err, trait_predicate) ;
613
613
suggested |= self . suggest_fn_call ( & obligation, & mut err, trait_predicate) ;
614
614
let impl_candidates = self . find_similar_impl_candidates ( trait_predicate) ;
615
615
suggested = if let & [ cand] = & impl_candidates[ ..] {
@@ -944,7 +944,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
944
944
obligation : & PredicateObligation < ' tcx > ,
945
945
trait_ref : ty:: TraitRef < ' tcx > ,
946
946
err : & mut Diagnostic ,
947
- ) {
947
+ ) -> bool {
948
948
let span = obligation. cause . span ;
949
949
struct V < ' v > {
950
950
search_span : Span ,
@@ -969,22 +969,22 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
969
969
Some ( hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Fn ( _, _, body_id) , .. } ) ) => {
970
970
body_id
971
971
}
972
- _ => return ,
972
+ _ => return false ,
973
973
} ;
974
974
let mut v = V { search_span : span, found : None } ;
975
975
v. visit_body ( self . tcx . hir ( ) . body ( * body_id) ) ;
976
976
let Some ( expr) = v. found else {
977
- return ;
977
+ return false ;
978
978
} ;
979
979
let Some ( typeck) = & self . typeck_results else {
980
- return ;
980
+ return false ;
981
981
} ;
982
982
let Some ( ( ObligationCauseCode :: QuestionMark , Some ( y) ) ) = obligation. cause . code ( ) . parent ( )
983
983
else {
984
- return ;
984
+ return false ;
985
985
} ;
986
986
if !self . tcx . is_diagnostic_item ( sym:: FromResidual , y. def_id ( ) ) {
987
- return ;
987
+ return false ;
988
988
}
989
989
let self_ty = trait_ref. self_ty ( ) ;
990
990
let found_ty = trait_ref. args . get ( 1 ) . and_then ( |a| a. as_type ( ) ) ;
@@ -1009,6 +1009,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1009
1009
Some ( arg. as_type ( ) ?)
1010
1010
} ;
1011
1011
1012
+ let mut suggested = false ;
1012
1013
let mut chain = vec ! [ ] ;
1013
1014
1014
1015
// The following logic is simlar to `point_at_chain`, but that's focused on associated types
@@ -1073,6 +1074,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1073
1074
)
1074
1075
. must_apply_modulo_regions ( )
1075
1076
{
1077
+ suggested = true ;
1076
1078
err. span_suggestion_short (
1077
1079
stmt. span . with_lo ( expr. span . hi ( ) ) ,
1078
1080
"remove this semicolon" ,
@@ -1132,14 +1134,15 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1132
1134
err. span_label ( span, format ! ( "this has type `Result<_, {err_ty}>`" ) ) ;
1133
1135
} else {
1134
1136
err. span_label (
1135
- span,
1136
- format ! (
1137
- "this can't be annotated with `?` because it has type `Result<_, {err_ty}>`" ,
1138
- ) ,
1139
- ) ;
1137
+ span,
1138
+ format ! (
1139
+ "this can't be annotated with `?` because it has type `Result<_, {err_ty}>`" ,
1140
+ ) ,
1141
+ ) ;
1140
1142
}
1141
1143
prev = Some ( err_ty) ;
1142
1144
}
1145
+ suggested
1143
1146
}
1144
1147
1145
1148
fn report_const_param_not_wf (
0 commit comments