@@ -33,7 +33,7 @@ use rustc_middle::ty::IsSuggestable;
3333use rustc_middle:: ty:: { self , GenericArgKind , Ty , TyCtxt , TypeVisitableExt } ;
3434use rustc_span:: def_id:: DefIdSet ;
3535use rustc_span:: symbol:: { kw, sym, Ident } ;
36- use rustc_span:: { edit_distance, ExpnKind , FileName , MacroKind , Span } ;
36+ use rustc_span:: { edit_distance, ErrorGuaranteed , ExpnKind , FileName , MacroKind , Span } ;
3737use rustc_span:: { Symbol , DUMMY_SP } ;
3838use rustc_trait_selection:: infer:: InferCtxtExt ;
3939use rustc_trait_selection:: traits:: error_reporting:: on_unimplemented:: OnUnimplementedNote ;
@@ -192,7 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
192192 error : MethodError < ' tcx > ,
193193 expected : Expectation < ' tcx > ,
194194 trait_missing_method : bool ,
195- ) -> Option < Diag < ' _ > > {
195+ ) -> Result < Diag < ' _ > , ErrorGuaranteed > {
196196 let ( span, sugg_span, source, item_name, args) = match self . tcx . hir_node ( call_id) {
197197 hir:: Node :: Expr ( & hir:: Expr {
198198 kind : hir:: ExprKind :: MethodCall ( segment, rcvr, args, _) ,
@@ -226,9 +226,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
226226 } ;
227227
228228 // Avoid suggestions when we don't know what's going on.
229- if rcvr_ty. references_error ( ) {
230- return None ;
231- }
229+ rcvr_ty. error_reported ( ) ?;
232230
233231 match error {
234232 MethodError :: NoMatch ( mut no_match_data) => {
@@ -265,7 +263,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
265263 & mut sources,
266264 Some ( sugg_span) ,
267265 ) ;
268- err. emit ( ) ;
266+ return Err ( err. emit ( ) ) ;
269267 }
270268
271269 MethodError :: PrivateMatch ( kind, def_id, out_of_scope_traits) => {
@@ -286,7 +284,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
286284 . unwrap_or_else ( || self . tcx . def_span ( def_id) ) ;
287285 err. span_label ( sp, format ! ( "private {kind} defined here" ) ) ;
288286 self . suggest_valid_traits ( & mut err, item_name, out_of_scope_traits, true ) ;
289- err. emit ( ) ;
287+ return Err ( err. emit ( ) ) ;
290288 }
291289
292290 MethodError :: IllegalSizedBound { candidates, needs_mut, bound_span, self_expr } => {
@@ -343,12 +341,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
343341 }
344342 }
345343 }
346- err. emit ( ) ;
344+ return Err ( err. emit ( ) ) ;
347345 }
348346
349347 MethodError :: BadReturnType => bug ! ( "no return type expectations but got BadReturnType" ) ,
350348 }
351- None
352349 }
353350
354351 fn suggest_missing_writer ( & self , rcvr_ty : Ty < ' tcx > , rcvr_expr : & hir:: Expr < ' tcx > ) -> Diag < ' _ > {
@@ -576,7 +573,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
576573 no_match_data : & mut NoMatchData < ' tcx > ,
577574 expected : Expectation < ' tcx > ,
578575 trait_missing_method : bool ,
579- ) -> Option < Diag < ' _ > > {
576+ ) -> Result < Diag < ' _ > , ErrorGuaranteed > {
580577 let mode = no_match_data. mode ;
581578 let tcx = self . tcx ;
582579 let rcvr_ty = self . resolve_vars_if_possible ( rcvr_ty) ;
@@ -608,24 +605,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
608605
609606 // We could pass the file for long types into these two, but it isn't strictly necessary
610607 // given how targeted they are.
611- if self . suggest_wrapping_range_with_parens (
608+ self . suggest_wrapping_range_with_parens (
612609 tcx,
613610 rcvr_ty,
614611 source,
615612 span,
616613 item_name,
617614 & short_ty_str,
618- ) || self . suggest_constraining_numerical_ty (
615+ ) ?;
616+ self . suggest_constraining_numerical_ty (
619617 tcx,
620618 rcvr_ty,
621619 source,
622620 span,
623621 item_kind,
624622 item_name,
625623 & short_ty_str,
626- ) {
627- return None ;
628- }
624+ ) ?;
629625 span = item_name. span ;
630626
631627 // Don't show generic arguments when the method can't be found in any implementation (#81576).
@@ -881,7 +877,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
881877 vec ! [ ( span. shrink_to_lo( ) , format!( "into_iter()." ) ) ] ,
882878 Applicability :: MaybeIncorrect ,
883879 ) ;
884- return Some ( err) ;
880+ return Ok ( err) ;
885881 } else if !unsatisfied_predicates. is_empty ( ) && matches ! ( rcvr_ty. kind( ) , ty:: Param ( _) ) {
886882 // We special case the situation where we are looking for `_` in
887883 // `<TypeParam as _>::method` because otherwise the machinery will look for blanket
@@ -1606,7 +1602,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16061602 }
16071603
16081604 self . note_derefed_ty_has_method ( & mut err, source, rcvr_ty, item_name, expected) ;
1609- Some ( err)
1605+ Ok ( err)
16101606 }
16111607
16121608 /// If an appropriate error source is not found, check method chain for possible candidates
@@ -2259,7 +2255,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22592255 span : Span ,
22602256 item_name : Ident ,
22612257 ty_str : & str ,
2262- ) -> bool {
2258+ ) -> Result < ( ) , ErrorGuaranteed > {
22632259 if let SelfSource :: MethodCall ( expr) = source {
22642260 for ( _, parent) in tcx. hir ( ) . parent_iter ( expr. hir_id ) . take ( 5 ) {
22652261 if let Node :: Expr ( parent_expr) = parent {
@@ -2316,7 +2312,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23162312 ) ;
23172313 if pick. is_ok ( ) {
23182314 let range_span = parent_expr. span . with_hi ( expr. span . hi ( ) ) ;
2319- tcx. dcx ( ) . emit_err ( errors:: MissingParenthesesInRange {
2315+ return Err ( tcx. dcx ( ) . emit_err ( errors:: MissingParenthesesInRange {
23202316 span,
23212317 ty_str : ty_str. to_string ( ) ,
23222318 method_name : item_name. as_str ( ) . to_string ( ) ,
@@ -2325,13 +2321,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23252321 left : range_span. shrink_to_lo ( ) ,
23262322 right : range_span. shrink_to_hi ( ) ,
23272323 } ) ,
2328- } ) ;
2329- return true ;
2324+ } ) ) ;
23302325 }
23312326 }
23322327 }
23332328 }
2334- false
2329+ Ok ( ( ) )
23352330 }
23362331
23372332 fn suggest_constraining_numerical_ty (
@@ -2343,7 +2338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23432338 item_kind : & str ,
23442339 item_name : Ident ,
23452340 ty_str : & str ,
2346- ) -> bool {
2341+ ) -> Result < ( ) , ErrorGuaranteed > {
23472342 let found_candidate = all_traits ( self . tcx )
23482343 . into_iter ( )
23492344 . any ( |info| self . associated_value ( info. def_id , item_name) . is_some ( ) ) ;
@@ -2447,10 +2442,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24472442 }
24482443 _ => { }
24492444 }
2450- err. emit ( ) ;
2451- return true ;
2445+ return Err ( err. emit ( ) ) ;
24522446 }
2453- false
2447+ Ok ( ( ) )
24542448 }
24552449
24562450 /// For code `rect::area(...)`,
0 commit comments