@@ -33,7 +33,7 @@ use rustc_middle::ty::IsSuggestable;
33
33
use rustc_middle:: ty:: { self , GenericArgKind , Ty , TyCtxt , TypeVisitableExt } ;
34
34
use rustc_span:: def_id:: DefIdSet ;
35
35
use 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 } ;
37
37
use rustc_span:: { Symbol , DUMMY_SP } ;
38
38
use rustc_trait_selection:: infer:: InferCtxtExt ;
39
39
use rustc_trait_selection:: traits:: error_reporting:: on_unimplemented:: OnUnimplementedNote ;
@@ -192,7 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
192
192
error : MethodError < ' tcx > ,
193
193
expected : Expectation < ' tcx > ,
194
194
trait_missing_method : bool ,
195
- ) -> Option < Diag < ' _ > > {
195
+ ) -> ErrorGuaranteed {
196
196
let ( span, sugg_span, source, item_name, args) = match self . tcx . hir_node ( call_id) {
197
197
hir:: Node :: Expr ( & hir:: Expr {
198
198
kind : hir:: ExprKind :: MethodCall ( segment, rcvr, args, _) ,
@@ -226,8 +226,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
226
226
} ;
227
227
228
228
// 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 ;
231
231
}
232
232
233
233
match error {
@@ -265,7 +265,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
265
265
& mut sources,
266
266
Some ( sugg_span) ,
267
267
) ;
268
- err. emit ( ) ;
268
+ return err. emit ( ) ;
269
269
}
270
270
271
271
MethodError :: PrivateMatch ( kind, def_id, out_of_scope_traits) => {
@@ -286,7 +286,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
286
286
. unwrap_or_else ( || self . tcx . def_span ( def_id) ) ;
287
287
err. span_label ( sp, format ! ( "private {kind} defined here" ) ) ;
288
288
self . suggest_valid_traits ( & mut err, item_name, out_of_scope_traits, true ) ;
289
- err. emit ( ) ;
289
+ return err. emit ( ) ;
290
290
}
291
291
292
292
MethodError :: IllegalSizedBound { candidates, needs_mut, bound_span, self_expr } => {
@@ -343,12 +343,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
343
343
}
344
344
}
345
345
}
346
- err. emit ( ) ;
346
+ return err. emit ( ) ;
347
347
}
348
348
349
349
MethodError :: BadReturnType => bug ! ( "no return type expectations but got BadReturnType" ) ,
350
350
}
351
- None
352
351
}
353
352
354
353
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> {
564
563
}
565
564
}
566
565
567
- pub fn report_no_match_method_error (
566
+ fn report_no_match_method_error (
568
567
& self ,
569
568
mut span : Span ,
570
569
rcvr_ty : Ty < ' tcx > ,
@@ -576,7 +575,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
576
575
no_match_data : & mut NoMatchData < ' tcx > ,
577
576
expected : Expectation < ' tcx > ,
578
577
trait_missing_method : bool ,
579
- ) -> Option < Diag < ' _ > > {
578
+ ) -> ErrorGuaranteed {
580
579
let mode = no_match_data. mode ;
581
580
let tcx = self . tcx ;
582
581
let rcvr_ty = self . resolve_vars_if_possible ( rcvr_ty) ;
@@ -608,14 +607,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
608
607
609
608
// We could pass the file for long types into these two, but it isn't strictly necessary
610
609
// 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 (
612
611
tcx,
613
612
rcvr_ty,
614
613
source,
615
614
span,
616
615
item_name,
617
616
& 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 (
619
621
tcx,
620
622
rcvr_ty,
621
623
source,
@@ -624,7 +626,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
624
626
item_name,
625
627
& short_ty_str,
626
628
) {
627
- return None ;
629
+ return guar ;
628
630
}
629
631
span = item_name. span ;
630
632
@@ -881,7 +883,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
881
883
vec ! [ ( span. shrink_to_lo( ) , format!( "into_iter()." ) ) ] ,
882
884
Applicability :: MaybeIncorrect ,
883
885
) ;
884
- return Some ( err) ;
886
+ return err. emit ( ) ;
885
887
} else if !unsatisfied_predicates. is_empty ( ) && matches ! ( rcvr_ty. kind( ) , ty:: Param ( _) ) {
886
888
// We special case the situation where we are looking for `_` in
887
889
// `<TypeParam as _>::method` because otherwise the machinery will look for blanket
@@ -1606,7 +1608,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1606
1608
}
1607
1609
1608
1610
self . note_derefed_ty_has_method ( & mut err, source, rcvr_ty, item_name, expected) ;
1609
- Some ( err)
1611
+ err. emit ( )
1610
1612
}
1611
1613
1612
1614
/// If an appropriate error source is not found, check method chain for possible candidates
@@ -2251,15 +2253,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2251
2253
2252
2254
/// Suggest possible range with adding parentheses, for example:
2253
2255
/// 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 (
2255
2257
& self ,
2256
2258
tcx : TyCtxt < ' tcx > ,
2257
2259
actual : Ty < ' tcx > ,
2258
2260
source : SelfSource < ' tcx > ,
2259
2261
span : Span ,
2260
2262
item_name : Ident ,
2261
2263
ty_str : & str ,
2262
- ) -> bool {
2264
+ ) -> Result < ( ) , ErrorGuaranteed > {
2263
2265
if let SelfSource :: MethodCall ( expr) = source {
2264
2266
for ( _, parent) in tcx. hir ( ) . parent_iter ( expr. hir_id ) . take ( 5 ) {
2265
2267
if let Node :: Expr ( parent_expr) = parent {
@@ -2316,7 +2318,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2316
2318
) ;
2317
2319
if pick. is_ok ( ) {
2318
2320
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 {
2320
2322
span,
2321
2323
ty_str : ty_str. to_string ( ) ,
2322
2324
method_name : item_name. as_str ( ) . to_string ( ) ,
@@ -2325,16 +2327,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2325
2327
left : range_span. shrink_to_lo ( ) ,
2326
2328
right : range_span. shrink_to_hi ( ) ,
2327
2329
} ) ,
2328
- } ) ;
2329
- return true ;
2330
+ } ) ) ;
2330
2331
}
2331
2332
}
2332
2333
}
2333
2334
}
2334
- false
2335
+ Ok ( ( ) )
2335
2336
}
2336
2337
2337
- fn suggest_constraining_numerical_ty (
2338
+ fn report_failed_method_call_on_numerical_infer_var (
2338
2339
& self ,
2339
2340
tcx : TyCtxt < ' tcx > ,
2340
2341
actual : Ty < ' tcx > ,
@@ -2343,7 +2344,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2343
2344
item_kind : & str ,
2344
2345
item_name : Ident ,
2345
2346
ty_str : & str ,
2346
- ) -> bool {
2347
+ ) -> Result < ( ) , ErrorGuaranteed > {
2347
2348
let found_candidate = all_traits ( self . tcx )
2348
2349
. into_iter ( )
2349
2350
. any ( |info| self . associated_value ( info. def_id , item_name) . is_some ( ) ) ;
@@ -2447,10 +2448,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2447
2448
}
2448
2449
_ => { }
2449
2450
}
2450
- err. emit ( ) ;
2451
- return true ;
2451
+ return Err ( err. emit ( ) ) ;
2452
2452
}
2453
- false
2453
+ Ok ( ( ) )
2454
2454
}
2455
2455
2456
2456
/// For code `rect::area(...)`,
0 commit comments