Fix duplicate display of error E0502

This commit is contained in:
Josh Leeb-du Toit 2017-10-29 10:37:59 +11:00
parent 269cf5026c
commit 5086657b42

View File

@ -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,