@@ -428,6 +428,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
428
428
generic_param_scope: LocalDefId,
429
429
errors: &[RegionResolutionError<'tcx>],
430
430
) -> ErrorGuaranteed {
431
+ assert!(!errors.is_empty());
432
+
431
433
if let Some(guaranteed) = self.infcx.tainted_by_errors() {
432
434
return guaranteed;
433
435
}
@@ -440,10 +442,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
440
442
441
443
debug!("report_region_errors: {} errors after preprocessing", errors.len());
442
444
445
+ let mut guar = None;
443
446
for error in errors {
444
447
debug!("report_region_errors: error = {:?}", error);
445
448
446
- if !self.try_report_nice_region_error(&error) {
449
+ guar = Some(if let Some(guar) = self.try_report_nice_region_error(&error) {
450
+ guar
451
+ } else {
447
452
match error.clone() {
448
453
// These errors could indicate all manner of different
449
454
// problems with many different solutions. Rather
@@ -454,21 +459,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
454
459
// general bit of code that displays the error information
455
460
RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
456
461
if sub.is_placeholder() || sup.is_placeholder() {
457
- self.report_placeholder_failure(origin, sub, sup).emit();
462
+ self.report_placeholder_failure(origin, sub, sup).emit()
458
463
} else {
459
- self.report_concrete_failure(origin, sub, sup).emit();
464
+ self.report_concrete_failure(origin, sub, sup).emit()
460
465
}
461
466
}
462
467
463
- RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => {
464
- self .report_generic_bound_failure(
468
+ RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => self
469
+ .report_generic_bound_failure(
465
470
generic_param_scope,
466
471
origin.span(),
467
472
Some(origin),
468
473
param_ty,
469
474
sub,
470
- );
471
- }
475
+ ),
472
476
473
477
RegionResolutionError::SubSupConflict(
474
478
_,
@@ -480,13 +484,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
480
484
_,
481
485
) => {
482
486
if sub_r.is_placeholder() {
483
- self.report_placeholder_failure(sub_origin, sub_r, sup_r).emit();
487
+ self.report_placeholder_failure(sub_origin, sub_r, sup_r).emit()
484
488
} else if sup_r.is_placeholder() {
485
- self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
489
+ self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit()
486
490
} else {
487
491
self.report_sub_sup_conflict(
488
492
var_origin, sub_origin, sub_r, sup_origin, sup_r,
489
- );
493
+ )
490
494
}
491
495
}
492
496
@@ -506,7 +510,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
506
510
// value.
507
511
let sub_r = self.tcx.lifetimes.re_erased;
508
512
509
- self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
513
+ self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit()
510
514
}
511
515
512
516
RegionResolutionError::CannotNormalize(clause, origin) => {
@@ -515,15 +519,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
515
519
self.tcx
516
520
.dcx()
517
521
.struct_span_err(origin.span(), format!("cannot normalize `{clause}`"))
518
- .emit();
522
+ .emit()
519
523
}
520
524
}
521
- }
525
+ })
522
526
}
523
527
524
- self.tcx
525
- .dcx()
526
- .span_delayed_bug(self.tcx.def_span(generic_param_scope), "expected region errors")
528
+ guar.unwrap()
527
529
}
528
530
529
531
// This method goes through all the errors and try to group certain types
@@ -2314,9 +2316,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2314
2316
origin: Option<SubregionOrigin<'tcx>>,
2315
2317
bound_kind: GenericKind<'tcx>,
2316
2318
sub: Region<'tcx>,
2317
- ) {
2319
+ ) -> ErrorGuaranteed {
2318
2320
self.construct_generic_bound_failure(generic_param_scope, span, origin, bound_kind, sub)
2319
- .emit();
2321
+ .emit()
2320
2322
}
2321
2323
2322
2324
pub fn construct_generic_bound_failure(
@@ -2575,7 +2577,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2575
2577
sub_region: Region<'tcx>,
2576
2578
sup_origin: SubregionOrigin<'tcx>,
2577
2579
sup_region: Region<'tcx>,
2578
- ) {
2580
+ ) -> ErrorGuaranteed {
2579
2581
let mut err = self.report_inference_failure(var_origin);
2580
2582
2581
2583
note_and_explain_region(
@@ -2614,12 +2616,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2614
2616
);
2615
2617
2616
2618
err.note_expected_found(&"", sup_expected, &"", sup_found);
2617
- if sub_region.is_error() | sup_region.is_error() {
2618
- err.delay_as_bug();
2619
+ return if sub_region.is_error() | sup_region.is_error() {
2620
+ err.delay_as_bug()
2619
2621
} else {
2620
- err.emit();
2621
- }
2622
- return;
2622
+ err.emit()
2623
+ };
2623
2624
}
2624
2625
2625
2626
self.note_region_origin(&mut err, &sup_origin);
@@ -2634,11 +2635,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2634
2635
);
2635
2636
2636
2637
self.note_region_origin(&mut err, &sub_origin);
2637
- if sub_region.is_error() | sup_region.is_error() {
2638
- err.delay_as_bug();
2639
- } else {
2640
- err.emit();
2641
- }
2638
+ if sub_region.is_error() | sup_region.is_error() { err.delay_as_bug() } else { err.emit() }
2642
2639
}
2643
2640
2644
2641
/// Determine whether an error associated with the given span and definition
0 commit comments