@@ -395,18 +395,40 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
395
395
assert ! ( self . bccx. region_scope_tree. scopes_intersect( old_loan. kill_scope,
396
396
new_loan. kill_scope) ) ;
397
397
398
- self . report_error_if_loan_conflicts_with_restriction (
399
- old_loan, new_loan, old_loan, new_loan) &&
400
- self . report_error_if_loan_conflicts_with_restriction (
401
- new_loan, old_loan, old_loan, new_loan)
398
+ let err_old_new = match self . report_error_if_loan_conflicts_with_restriction (
399
+ old_loan, new_loan, old_loan, new_loan
400
+ ) {
401
+ Err ( err) => Some ( err) ,
402
+ Ok ( _) => None
403
+ } ;
404
+
405
+ let err_new_old = match self . report_error_if_loan_conflicts_with_restriction (
406
+ new_loan, old_loan, old_loan, new_loan
407
+ ) {
408
+ Err ( err) => Some ( err) ,
409
+ Ok ( _) => None
410
+ } ;
411
+
412
+ if let Some ( mut err_old) = err_old_new {
413
+ err_old. emit ( ) ;
414
+ if let Some ( mut err_new) = err_new_old {
415
+ err_new. cancel ( ) ;
416
+ }
417
+ } else if let Some ( mut err_new) = err_new_old {
418
+ err_new. emit ( ) ;
419
+ } else {
420
+ return true ;
421
+ }
422
+
423
+ false
402
424
}
403
425
404
426
pub fn report_error_if_loan_conflicts_with_restriction ( & self ,
405
427
loan1 : & Loan < ' tcx > ,
406
428
loan2 : & Loan < ' tcx > ,
407
429
old_loan : & Loan < ' tcx > ,
408
430
new_loan : & Loan < ' tcx > )
409
- -> bool {
431
+ -> Result < ( ) , DiagnosticBuilder < ' a > > {
410
432
//! Checks whether the restrictions introduced by `loan1` would
411
433
//! prohibit `loan2`. Returns false if an error is reported.
412
434
@@ -416,7 +438,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
416
438
loan2) ;
417
439
418
440
if compatible_borrow_kinds ( loan1. kind , loan2. kind ) {
419
- return true ;
441
+ return Ok ( ( ) ) ;
420
442
}
421
443
422
444
let loan2_base_path = owned_ptr_base_path_rc ( & loan2. loan_path ) ;
@@ -520,11 +542,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
520
542
_ => { }
521
543
}
522
544
523
- err. emit ( ) ;
524
- return false ;
545
+ return Err ( err) ;
525
546
}
526
547
527
- true
548
+ Ok ( ( ) )
528
549
}
529
550
530
551
fn consume_common ( & self ,
0 commit comments