From 5086657b42624f0c28b0df01f1c31563ac6b2f4a Mon Sep 17 00:00:00 2001 From: Josh Leeb-du Toit Date: Sun, 29 Oct 2017 10:37:59 +1100 Subject: [PATCH] Fix duplicate display of error E0502 --- src/librustc_borrowck/borrowck/check_loans.rs | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index 6fd9ff4012e..a2d6fd536bc 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -395,10 +395,32 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { assert!(self.bccx.region_scope_tree.scopes_intersect(old_loan.kill_scope, new_loan.kill_scope)); - self.report_error_if_loan_conflicts_with_restriction( - old_loan, new_loan, old_loan, new_loan) && - self.report_error_if_loan_conflicts_with_restriction( - new_loan, old_loan, old_loan, new_loan) + let err_old_new = match self.report_error_if_loan_conflicts_with_restriction( + old_loan, new_loan, old_loan, new_loan + ) { + Err(err) => Some(err), + Ok(_) => None + }; + + let err_new_old = match self.report_error_if_loan_conflicts_with_restriction( + new_loan, old_loan, old_loan, new_loan + ) { + Err(err) => Some(err), + Ok(_) => None + }; + + if let Some(mut err_old) = err_old_new { + err_old.emit(); + if let Some(mut err_new) = err_new_old { + err_new.cancel(); + } + } else if let Some(mut err_new) = err_new_old { + err_new.emit(); + } else { + return true; + } + + false } pub fn report_error_if_loan_conflicts_with_restriction(&self, @@ -406,7 +428,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { loan2: &Loan<'tcx>, old_loan: &Loan<'tcx>, new_loan: &Loan<'tcx>) - -> bool { + -> Result<(), DiagnosticBuilder<'a>> { //! Checks whether the restrictions introduced by `loan1` would //! prohibit `loan2`. Returns false if an error is reported. @@ -416,7 +438,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { loan2); if compatible_borrow_kinds(loan1.kind, loan2.kind) { - return true; + return Ok(()); } let loan2_base_path = owned_ptr_base_path_rc(&loan2.loan_path); @@ -520,11 +542,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { _ => { } } - err.emit(); - return false; + return Err(err); } - true + Ok(()) } fn consume_common(&self,