@@ -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
+ ) -> Result < Diag < ' _ > , 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,9 +226,7 @@ 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 ;
231
- }
229
+ rcvr_ty. error_reported ( ) ?;
232
230
233
231
match error {
234
232
MethodError :: NoMatch ( mut no_match_data) => {
@@ -265,7 +263,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
265
263
& mut sources,
266
264
Some ( sugg_span) ,
267
265
) ;
268
- err. emit ( ) ;
266
+ return Err ( err. emit ( ) ) ;
269
267
}
270
268
271
269
MethodError :: PrivateMatch ( kind, def_id, out_of_scope_traits) => {
@@ -286,7 +284,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
286
284
. unwrap_or_else ( || self . tcx . def_span ( def_id) ) ;
287
285
err. span_label ( sp, format ! ( "private {kind} defined here" ) ) ;
288
286
self . suggest_valid_traits ( & mut err, item_name, out_of_scope_traits, true ) ;
289
- err. emit ( ) ;
287
+ return Err ( err. emit ( ) ) ;
290
288
}
291
289
292
290
MethodError :: IllegalSizedBound { candidates, needs_mut, bound_span, self_expr } => {
@@ -343,12 +341,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
343
341
}
344
342
}
345
343
}
346
- err. emit ( ) ;
344
+ return Err ( err. emit ( ) ) ;
347
345
}
348
346
349
347
MethodError :: BadReturnType => bug ! ( "no return type expectations but got BadReturnType" ) ,
350
348
}
351
- None
352
349
}
353
350
354
351
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> {
576
573
no_match_data : & mut NoMatchData < ' tcx > ,
577
574
expected : Expectation < ' tcx > ,
578
575
trait_missing_method : bool ,
579
- ) -> Option < Diag < ' _ > > {
576
+ ) -> Result < Diag < ' _ > , ErrorGuaranteed > {
580
577
let mode = no_match_data. mode ;
581
578
let tcx = self . tcx ;
582
579
let rcvr_ty = self . resolve_vars_if_possible ( rcvr_ty) ;
@@ -608,24 +605,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
608
605
609
606
// We could pass the file for long types into these two, but it isn't strictly necessary
610
607
// given how targeted they are.
611
- if self . suggest_wrapping_range_with_parens (
608
+ self . suggest_wrapping_range_with_parens (
612
609
tcx,
613
610
rcvr_ty,
614
611
source,
615
612
span,
616
613
item_name,
617
614
& short_ty_str,
618
- ) || self . suggest_constraining_numerical_ty (
615
+ ) ?;
616
+ self . suggest_constraining_numerical_ty (
619
617
tcx,
620
618
rcvr_ty,
621
619
source,
622
620
span,
623
621
item_kind,
624
622
item_name,
625
623
& short_ty_str,
626
- ) {
627
- return None ;
628
- }
624
+ ) ?;
629
625
span = item_name. span ;
630
626
631
627
// 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> {
881
877
vec ! [ ( span. shrink_to_lo( ) , format!( "into_iter()." ) ) ] ,
882
878
Applicability :: MaybeIncorrect ,
883
879
) ;
884
- return Some ( err) ;
880
+ return Ok ( err) ;
885
881
} else if !unsatisfied_predicates. is_empty ( ) && matches ! ( rcvr_ty. kind( ) , ty:: Param ( _) ) {
886
882
// We special case the situation where we are looking for `_` in
887
883
// `<TypeParam as _>::method` because otherwise the machinery will look for blanket
@@ -1606,7 +1602,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1606
1602
}
1607
1603
1608
1604
self . note_derefed_ty_has_method ( & mut err, source, rcvr_ty, item_name, expected) ;
1609
- Some ( err)
1605
+ Ok ( err)
1610
1606
}
1611
1607
1612
1608
/// If an appropriate error source is not found, check method chain for possible candidates
@@ -2259,7 +2255,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2259
2255
span : Span ,
2260
2256
item_name : Ident ,
2261
2257
ty_str : & str ,
2262
- ) -> bool {
2258
+ ) -> Result < ( ) , ErrorGuaranteed > {
2263
2259
if let SelfSource :: MethodCall ( expr) = source {
2264
2260
for ( _, parent) in tcx. hir ( ) . parent_iter ( expr. hir_id ) . take ( 5 ) {
2265
2261
if let Node :: Expr ( parent_expr) = parent {
@@ -2316,7 +2312,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2316
2312
) ;
2317
2313
if pick. is_ok ( ) {
2318
2314
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 {
2320
2316
span,
2321
2317
ty_str : ty_str. to_string ( ) ,
2322
2318
method_name : item_name. as_str ( ) . to_string ( ) ,
@@ -2325,13 +2321,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2325
2321
left : range_span. shrink_to_lo ( ) ,
2326
2322
right : range_span. shrink_to_hi ( ) ,
2327
2323
} ) ,
2328
- } ) ;
2329
- return true ;
2324
+ } ) ) ;
2330
2325
}
2331
2326
}
2332
2327
}
2333
2328
}
2334
- false
2329
+ Ok ( ( ) )
2335
2330
}
2336
2331
2337
2332
fn suggest_constraining_numerical_ty (
@@ -2343,7 +2338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2343
2338
item_kind : & str ,
2344
2339
item_name : Ident ,
2345
2340
ty_str : & str ,
2346
- ) -> bool {
2341
+ ) -> Result < ( ) , ErrorGuaranteed > {
2347
2342
let found_candidate = all_traits ( self . tcx )
2348
2343
. into_iter ( )
2349
2344
. any ( |info| self . associated_value ( info. def_id , item_name) . is_some ( ) ) ;
@@ -2447,10 +2442,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2447
2442
}
2448
2443
_ => { }
2449
2444
}
2450
- err. emit ( ) ;
2451
- return true ;
2445
+ return Err ( err. emit ( ) ) ;
2452
2446
}
2453
- false
2447
+ Ok ( ( ) )
2454
2448
}
2455
2449
2456
2450
/// For code `rect::area(...)`,
0 commit comments