Skip to content

Commit 5086657

Browse files
author
Josh Leeb-du Toit
committed
Fix duplicate display of error E0502
1 parent 269cf50 commit 5086657

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/librustc_borrowck/borrowck/check_loans.rs

+30-9
Original file line numberDiff line numberDiff line change
@@ -395,18 +395,40 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
395395
assert!(self.bccx.region_scope_tree.scopes_intersect(old_loan.kill_scope,
396396
new_loan.kill_scope));
397397

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
402424
}
403425

404426
pub fn report_error_if_loan_conflicts_with_restriction(&self,
405427
loan1: &Loan<'tcx>,
406428
loan2: &Loan<'tcx>,
407429
old_loan: &Loan<'tcx>,
408430
new_loan: &Loan<'tcx>)
409-
-> bool {
431+
-> Result<(), DiagnosticBuilder<'a>> {
410432
//! Checks whether the restrictions introduced by `loan1` would
411433
//! prohibit `loan2`. Returns false if an error is reported.
412434
@@ -416,7 +438,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
416438
loan2);
417439

418440
if compatible_borrow_kinds(loan1.kind, loan2.kind) {
419-
return true;
441+
return Ok(());
420442
}
421443

422444
let loan2_base_path = owned_ptr_base_path_rc(&loan2.loan_path);
@@ -520,11 +542,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
520542
_ => { }
521543
}
522544

523-
err.emit();
524-
return false;
545+
return Err(err);
525546
}
526547

527-
true
548+
Ok(())
528549
}
529550

530551
fn consume_common(&self,

0 commit comments

Comments
 (0)