Skip to content

Commit 655894b

Browse files
committed
Add flag indicating whether AST borrowck query signalled any error.
1 parent fefe816 commit 655894b

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/librustc/middle/borrowck.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ use util::nodemap::FxHashSet;
1515
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
1616
StableHasherResult};
1717

18+
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
19+
pub enum SignalledError { SawSomeError, NoErrorsSeen }
20+
21+
impl_stable_hash_for!(enum self::SignalledError { SawSomeError, NoErrorsSeen });
22+
1823
#[derive(Debug, RustcEncodable, RustcDecodable)]
1924
pub struct BorrowCheckResult {
2025
pub used_mut_nodes: FxHashSet<HirId>,
26+
pub signalled_any_error: SignalledError,
2127
}
2228

2329
impl<'a> HashStable<StableHashingContext<'a>> for BorrowCheckResult {
@@ -26,7 +32,9 @@ impl<'a> HashStable<StableHashingContext<'a>> for BorrowCheckResult {
2632
hasher: &mut StableHasher<W>) {
2733
let BorrowCheckResult {
2834
ref used_mut_nodes,
35+
ref signalled_any_error,
2936
} = *self;
3037
used_mut_nodes.hash_stable(hcx, hasher);
38+
signalled_any_error.hash_stable(hcx, hasher);
3139
}
3240
}

src/librustc_borrowck/borrowck/check_loans.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
447447
.region_scope_tree
448448
.yield_in_scope_for_expr(scope,
449449
cmt.hir_id,
450-
self.bccx.body) {
450+
self.bccx.body)
451+
{
451452
self.bccx.cannot_borrow_across_generator_yield(borrow_span,
452453
yield_span,
453454
Origin::Ast).emit();
455+
self.bccx.signal_error();
454456
}
455457
}
456458

@@ -507,9 +509,13 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
507509
new_loan, old_loan, old_loan, new_loan).err();
508510

509511
match (err_old_new, err_new_old) {
510-
(Some(mut err), None) | (None, Some(mut err)) => err.emit(),
512+
(Some(mut err), None) | (None, Some(mut err)) => {
513+
err.emit();
514+
self.bccx.signal_error();
515+
}
511516
(Some(mut err_old), Some(mut err_new)) => {
512517
err_old.emit();
518+
self.bccx.signal_error();
513519
err_new.cancel();
514520
}
515521
(None, None) => return true,
@@ -695,6 +701,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
695701
loan_span, &self.bccx.loan_path_to_string(&loan_path),
696702
Origin::Ast)
697703
.emit();
704+
self.bccx.signal_error();
698705
}
699706
}
700707
}
@@ -745,6 +752,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
745752
};
746753

747754
err.emit();
755+
self.bccx.signal_error();
748756
}
749757
}
750758
}
@@ -914,5 +922,6 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
914922
self.bccx.cannot_assign_to_borrowed(
915923
span, loan.span, &self.bccx.loan_path_to_string(loan_path), Origin::Ast)
916924
.emit();
925+
self.bccx.signal_error();
917926
}
918927
}

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &Vec<Move
9999
"captured outer variable");
100100
}
101101
err.emit();
102+
bccx.signal_error();
102103
}
103104
}
104105

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc::middle::dataflow::DataFlowContext;
2828
use rustc::middle::dataflow::BitwiseOperator;
2929
use rustc::middle::dataflow::DataFlowOperator;
3030
use rustc::middle::dataflow::KillFrom;
31-
use rustc::middle::borrowck::BorrowCheckResult;
31+
use rustc::middle::borrowck::{BorrowCheckResult, SignalledError};
3232
use rustc::hir::def_id::{DefId, LocalDefId};
3333
use rustc::middle::expr_use_visitor as euv;
3434
use rustc::middle::mem_categorization as mc;
@@ -42,7 +42,7 @@ use rustc_mir::util::borrowck_errors::{BorrowckErrors, Origin};
4242
use rustc_mir::util::suggest_ref_mut;
4343
use rustc::util::nodemap::FxHashSet;
4444

45-
use std::cell::RefCell;
45+
use std::cell::{Cell, RefCell};
4646
use std::fmt;
4747
use std::rc::Rc;
4848
use rustc_data_structures::sync::Lrc;
@@ -105,6 +105,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
105105
// and do not need borrowchecking.
106106
return Lrc::new(BorrowCheckResult {
107107
used_mut_nodes: FxHashSet(),
108+
signalled_any_error: SignalledError::NoErrorsSeen,
108109
})
109110
}
110111
_ => { }
@@ -121,6 +122,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
121122
owner_def_id,
122123
body,
123124
used_mut_nodes: RefCell::new(FxHashSet()),
125+
signalled_any_error: Cell::new(SignalledError::NoErrorsSeen),
124126
};
125127

126128
// Eventually, borrowck will always read the MIR, but at the
@@ -154,6 +156,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
154156

155157
Lrc::new(BorrowCheckResult {
156158
used_mut_nodes: bccx.used_mut_nodes.into_inner(),
159+
signalled_any_error: bccx.signalled_any_error.into_inner(),
157160
})
158161
}
159162

@@ -234,6 +237,7 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
234237
owner_def_id,
235238
body,
236239
used_mut_nodes: RefCell::new(FxHashSet()),
240+
signalled_any_error: Cell::new(SignalledError::NoErrorsSeen),
237241
};
238242

239243
let dataflow_data = build_borrowck_dataflow_data(&mut bccx, true, body_id, |_| cfg);
@@ -257,6 +261,15 @@ pub struct BorrowckCtxt<'a, 'tcx: 'a> {
257261
body: &'tcx hir::Body,
258262

259263
used_mut_nodes: RefCell<FxHashSet<HirId>>,
264+
265+
signalled_any_error: Cell<SignalledError>,
266+
}
267+
268+
269+
impl<'a, 'tcx: 'a> BorrowckCtxt<'a, 'tcx> {
270+
fn signal_error(&self) {
271+
self.signalled_any_error.set(SignalledError::SawSomeError);
272+
}
260273
}
261274

262275
impl<'a, 'b, 'tcx: 'b> BorrowckErrors<'a> for &'a BorrowckCtxt<'b, 'tcx> {
@@ -645,6 +658,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
645658
.span_label(use_span, format!("use of possibly uninitialized `{}`",
646659
self.loan_path_to_string(lp)))
647660
.emit();
661+
self.signal_error();
648662
return;
649663
}
650664
_ => {
@@ -760,6 +774,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
760774
// not considered particularly helpful.
761775

762776
err.emit();
777+
self.signal_error();
763778
}
764779

765780
pub fn report_partial_reinitialization_of_uninitialized_structure(
@@ -770,6 +785,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
770785
&self.loan_path_to_string(lp),
771786
Origin::Ast)
772787
.emit();
788+
self.signal_error();
773789
}
774790

775791
pub fn report_reassigned_immutable_variable(&self,
@@ -787,6 +803,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
787803
self.loan_path_to_string(lp)));
788804
}
789805
err.emit();
806+
self.signal_error();
790807
}
791808

792809
pub fn struct_span_err_with_code<S: Into<MultiSpan>>(&self,
@@ -908,6 +925,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
908925
self.tcx.hir.hir_to_node_id(err.cmt.hir_id)
909926
);
910927
db.emit();
928+
self.signal_error();
911929
}
912930
err_out_of_scope(super_scope, sub_scope, cause) => {
913931
let msg = match opt_loan_path(&err.cmt) {
@@ -1022,6 +1040,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10221040
}
10231041

10241042
db.emit();
1043+
self.signal_error();
10251044
}
10261045
err_borrowed_pointer_too_short(loan_scope, ptr_scope) => {
10271046
let descr = self.cmt_to_path_or_string(err.cmt);
@@ -1047,6 +1066,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10471066
"");
10481067

10491068
db.emit();
1069+
self.signal_error();
10501070
}
10511071
}
10521072
}
@@ -1125,6 +1145,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
11251145
err.help("closures behind references must be called via `&mut`");
11261146
}
11271147
err.emit();
1148+
self.signal_error();
11281149
}
11291150

11301151
/// Given a type, if it is an immutable reference, return a suggestion to make it mutable
@@ -1307,6 +1328,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
13071328
cmt_path_or_string),
13081329
suggestion)
13091330
.emit();
1331+
self.signal_error();
13101332
}
13111333

13121334
fn region_end_span(&self, region: ty::Region<'tcx>) -> Option<Span> {

0 commit comments

Comments
 (0)