@@ -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+ ) -> 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,8 +226,8 @@ 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 ;
229+ if let Err ( guar ) = rcvr_ty. error_reported ( ) {
230+ return guar ;
231231 }
232232
233233 match error {
@@ -265,7 +265,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
265265 & mut sources,
266266 Some ( sugg_span) ,
267267 ) ;
268- err. emit ( ) ;
268+ return err. emit ( ) ;
269269 }
270270
271271 MethodError :: PrivateMatch ( kind, def_id, out_of_scope_traits) => {
@@ -286,7 +286,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
286286 . unwrap_or_else ( || self . tcx . def_span ( def_id) ) ;
287287 err. span_label ( sp, format ! ( "private {kind} defined here" ) ) ;
288288 self . suggest_valid_traits ( & mut err, item_name, out_of_scope_traits, true ) ;
289- err. emit ( ) ;
289+ return err. emit ( ) ;
290290 }
291291
292292 MethodError :: IllegalSizedBound { candidates, needs_mut, bound_span, self_expr } => {
@@ -343,12 +343,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
343343 }
344344 }
345345 }
346- err. emit ( ) ;
346+ return err. emit ( ) ;
347347 }
348348
349349 MethodError :: BadReturnType => bug ! ( "no return type expectations but got BadReturnType" ) ,
350350 }
351- None
352351 }
353352
354353 fn suggest_missing_writer ( & self , rcvr_ty : Ty < ' tcx > , rcvr_expr : & hir:: Expr < ' tcx > ) -> Diag < ' _ > {
@@ -564,7 +563,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
564563 }
565564 }
566565
567- pub fn report_no_match_method_error (
566+ fn report_no_match_method_error (
568567 & self ,
569568 mut span : Span ,
570569 rcvr_ty : Ty < ' tcx > ,
@@ -576,7 +575,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
576575 no_match_data : & mut NoMatchData < ' tcx > ,
577576 expected : Expectation < ' tcx > ,
578577 trait_missing_method : bool ,
579- ) -> Option < Diag < ' _ > > {
578+ ) -> ErrorGuaranteed {
580579 let mode = no_match_data. mode ;
581580 let tcx = self . tcx ;
582581 let rcvr_ty = self . resolve_vars_if_possible ( rcvr_ty) ;
@@ -608,14 +607,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
608607
609608 // We could pass the file for long types into these two, but it isn't strictly necessary
610609 // given how targeted they are.
611- if self . suggest_wrapping_range_with_parens (
610+ if let Err ( guar ) = self . report_failed_method_call_on_range_end (
612611 tcx,
613612 rcvr_ty,
614613 source,
615614 span,
616615 item_name,
617616 & short_ty_str,
618- ) || self . suggest_constraining_numerical_ty (
617+ ) {
618+ return guar;
619+ }
620+ if let Err ( guar) = self . report_failed_method_call_on_numerical_infer_var (
619621 tcx,
620622 rcvr_ty,
621623 source,
@@ -624,7 +626,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
624626 item_name,
625627 & short_ty_str,
626628 ) {
627- return None ;
629+ return guar ;
628630 }
629631 span = item_name. span ;
630632
@@ -881,7 +883,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
881883 vec ! [ ( span. shrink_to_lo( ) , format!( "into_iter()." ) ) ] ,
882884 Applicability :: MaybeIncorrect ,
883885 ) ;
884- return Some ( err) ;
886+ return err. emit ( ) ;
885887 } else if !unsatisfied_predicates. is_empty ( ) && matches ! ( rcvr_ty. kind( ) , ty:: Param ( _) ) {
886888 // We special case the situation where we are looking for `_` in
887889 // `<TypeParam as _>::method` because otherwise the machinery will look for blanket
@@ -1606,7 +1608,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16061608 }
16071609
16081610 self . note_derefed_ty_has_method ( & mut err, source, rcvr_ty, item_name, expected) ;
1609- Some ( err)
1611+ err. emit ( )
16101612 }
16111613
16121614 /// If an appropriate error source is not found, check method chain for possible candidates
@@ -2251,15 +2253,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22512253
22522254 /// Suggest possible range with adding parentheses, for example:
22532255 /// when encountering `0..1.map(|i| i + 1)` suggest `(0..1).map(|i| i + 1)`.
2254- fn suggest_wrapping_range_with_parens (
2256+ fn report_failed_method_call_on_range_end (
22552257 & self ,
22562258 tcx : TyCtxt < ' tcx > ,
22572259 actual : Ty < ' tcx > ,
22582260 source : SelfSource < ' tcx > ,
22592261 span : Span ,
22602262 item_name : Ident ,
22612263 ty_str : & str ,
2262- ) -> bool {
2264+ ) -> Result < ( ) , ErrorGuaranteed > {
22632265 if let SelfSource :: MethodCall ( expr) = source {
22642266 for ( _, parent) in tcx. hir ( ) . parent_iter ( expr. hir_id ) . take ( 5 ) {
22652267 if let Node :: Expr ( parent_expr) = parent {
@@ -2316,7 +2318,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23162318 ) ;
23172319 if pick. is_ok ( ) {
23182320 let range_span = parent_expr. span . with_hi ( expr. span . hi ( ) ) ;
2319- tcx. dcx ( ) . emit_err ( errors:: MissingParenthesesInRange {
2321+ return Err ( tcx. dcx ( ) . emit_err ( errors:: MissingParenthesesInRange {
23202322 span,
23212323 ty_str : ty_str. to_string ( ) ,
23222324 method_name : item_name. as_str ( ) . to_string ( ) ,
@@ -2325,16 +2327,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23252327 left : range_span. shrink_to_lo ( ) ,
23262328 right : range_span. shrink_to_hi ( ) ,
23272329 } ) ,
2328- } ) ;
2329- return true ;
2330+ } ) ) ;
23302331 }
23312332 }
23322333 }
23332334 }
2334- false
2335+ Ok ( ( ) )
23352336 }
23362337
2337- fn suggest_constraining_numerical_ty (
2338+ fn report_failed_method_call_on_numerical_infer_var (
23382339 & self ,
23392340 tcx : TyCtxt < ' tcx > ,
23402341 actual : Ty < ' tcx > ,
@@ -2343,7 +2344,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23432344 item_kind : & str ,
23442345 item_name : Ident ,
23452346 ty_str : & str ,
2346- ) -> bool {
2347+ ) -> Result < ( ) , ErrorGuaranteed > {
23472348 let found_candidate = all_traits ( self . tcx )
23482349 . into_iter ( )
23492350 . any ( |info| self . associated_value ( info. def_id , item_name) . is_some ( ) ) ;
@@ -2447,10 +2448,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24472448 }
24482449 _ => { }
24492450 }
2450- err. emit ( ) ;
2451- return true ;
2451+ return Err ( err. emit ( ) ) ;
24522452 }
2453- false
2453+ Ok ( ( ) )
24542454 }
24552455
24562456 /// For code `rect::area(...)`,
0 commit comments