]> git.lizzy.rs Git - rust.git/commitdiff
Add flag indicating whether AST `borrowck` query signalled any error.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Fri, 20 Jul 2018 14:38:00 +0000 (16:38 +0200)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Thu, 26 Jul 2018 11:17:55 +0000 (13:17 +0200)
src/librustc/middle/borrowck.rs
src/librustc_borrowck/borrowck/check_loans.rs
src/librustc_borrowck/borrowck/gather_loans/move_error.rs
src/librustc_borrowck/borrowck/mod.rs

index 6f5791ed5d71bc063c11a69b1b3a10e4525b3eef..c8d513a59f00de4776015a98a67b7107aee3060a 100644 (file)
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
                                            StableHasherResult};
 
+#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
+pub enum SignalledError { SawSomeError, NoErrorsSeen }
+
+impl_stable_hash_for!(enum self::SignalledError { SawSomeError, NoErrorsSeen });
+
 #[derive(Debug, RustcEncodable, RustcDecodable)]
 pub struct BorrowCheckResult {
     pub used_mut_nodes: FxHashSet<HirId>,
+    pub signalled_any_error: SignalledError,
 }
 
 impl<'a> HashStable<StableHashingContext<'a>> for BorrowCheckResult {
@@ -26,7 +32,9 @@ fn hash_stable<W: StableHasherResult>(&self,
                                           hasher: &mut StableHasher<W>) {
         let BorrowCheckResult {
             ref used_mut_nodes,
+            ref signalled_any_error,
         } = *self;
         used_mut_nodes.hash_stable(hcx, hasher);
+        signalled_any_error.hash_stable(hcx, hasher);
     }
 }
index 002e8697588fcdb113b5ea66ad85ff9dd81c0071..49bd69f8262169ad18bb2a85daa9cb487bbdf9ca 100644 (file)
@@ -447,10 +447,12 @@ pub fn borrow_of_local_data<'tcx>(cmt: &mc::cmt_<'tcx>) -> bool {
                                       .region_scope_tree
                                       .yield_in_scope_for_expr(scope,
                                                                cmt.hir_id,
-                                                               self.bccx.body) {
+                                                               self.bccx.body)
+        {
             self.bccx.cannot_borrow_across_generator_yield(borrow_span,
                                                            yield_span,
                                                            Origin::Ast).emit();
+            self.bccx.signal_error();
         }
     }
 
@@ -507,9 +509,13 @@ pub fn report_error_if_loans_conflict(&self,
             new_loan, old_loan, old_loan, new_loan).err();
 
         match (err_old_new, err_new_old) {
-            (Some(mut err), None) | (None, Some(mut err)) => err.emit(),
+            (Some(mut err), None) | (None, Some(mut err)) => {
+                err.emit();
+                self.bccx.signal_error();
+            }
             (Some(mut err_old), Some(mut err_new)) => {
                 err_old.emit();
+                self.bccx.signal_error();
                 err_new.cancel();
             }
             (None, None) => return true,
@@ -695,6 +701,7 @@ fn check_for_copy_of_frozen_path(&self,
                         loan_span, &self.bccx.loan_path_to_string(&loan_path),
                         Origin::Ast)
                     .emit();
+                self.bccx.signal_error();
             }
         }
     }
@@ -745,6 +752,7 @@ fn check_for_move_of_borrowed_path(&self,
                 };
 
                 err.emit();
+                self.bccx.signal_error();
             }
         }
     }
@@ -914,5 +922,6 @@ pub fn report_illegal_mutation(&self,
         self.bccx.cannot_assign_to_borrowed(
             span, loan.span, &self.bccx.loan_path_to_string(loan_path), Origin::Ast)
             .emit();
+        self.bccx.signal_error();
     }
 }
index f221565c7f39124afc001be0819ed538f86c84f4..e51caf89ee651b39e7ddc46feb10adc51809ca8f 100644 (file)
@@ -99,6 +99,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &Vec<Move
                            "captured outer variable");
         }
         err.emit();
+        bccx.signal_error();
     }
 }
 
index 3ae1e5aac507611938bc57855c1d5f18200720db..86a7f30147024956ac1752e3068349a44b342327 100644 (file)
@@ -28,7 +28,7 @@
 use rustc::middle::dataflow::BitwiseOperator;
 use rustc::middle::dataflow::DataFlowOperator;
 use rustc::middle::dataflow::KillFrom;
-use rustc::middle::borrowck::BorrowCheckResult;
+use rustc::middle::borrowck::{BorrowCheckResult, SignalledError};
 use rustc::hir::def_id::{DefId, LocalDefId};
 use rustc::middle::expr_use_visitor as euv;
 use rustc::middle::mem_categorization as mc;
@@ -42,7 +42,7 @@
 use rustc_mir::util::suggest_ref_mut;
 use rustc::util::nodemap::FxHashSet;
 
-use std::cell::RefCell;
+use std::cell::{Cell, RefCell};
 use std::fmt;
 use std::rc::Rc;
 use rustc_data_structures::sync::Lrc;
@@ -105,6 +105,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
             // and do not need borrowchecking.
             return Lrc::new(BorrowCheckResult {
                 used_mut_nodes: FxHashSet(),
+                signalled_any_error: SignalledError::NoErrorsSeen,
             })
         }
         _ => { }
@@ -121,6 +122,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
         owner_def_id,
         body,
         used_mut_nodes: RefCell::new(FxHashSet()),
+        signalled_any_error: Cell::new(SignalledError::NoErrorsSeen),
     };
 
     // 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)
 
     Lrc::new(BorrowCheckResult {
         used_mut_nodes: bccx.used_mut_nodes.into_inner(),
+        signalled_any_error: bccx.signalled_any_error.into_inner(),
     })
 }
 
@@ -234,6 +237,7 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
         owner_def_id,
         body,
         used_mut_nodes: RefCell::new(FxHashSet()),
+        signalled_any_error: Cell::new(SignalledError::NoErrorsSeen),
     };
 
     let dataflow_data = build_borrowck_dataflow_data(&mut bccx, true, body_id, |_| cfg);
@@ -257,6 +261,15 @@ pub struct BorrowckCtxt<'a, 'tcx: 'a> {
     body: &'tcx hir::Body,
 
     used_mut_nodes: RefCell<FxHashSet<HirId>>,
+
+    signalled_any_error: Cell<SignalledError>,
+}
+
+
+impl<'a, 'tcx: 'a> BorrowckCtxt<'a, 'tcx> {
+    fn signal_error(&self) {
+        self.signalled_any_error.set(SignalledError::SawSomeError);
+    }
 }
 
 impl<'a, 'b, 'tcx: 'b> BorrowckErrors<'a> for &'a BorrowckCtxt<'b, 'tcx> {
@@ -645,6 +658,7 @@ pub fn report_use_of_moved_value(&self,
                     .span_label(use_span, format!("use of possibly uninitialized `{}`",
                                                   self.loan_path_to_string(lp)))
                     .emit();
+                self.signal_error();
                 return;
             }
             _ => {
@@ -760,6 +774,7 @@ pub fn report_use_of_moved_value(&self,
         // not considered particularly helpful.
 
         err.emit();
+        self.signal_error();
     }
 
     pub fn report_partial_reinitialization_of_uninitialized_structure(
@@ -770,6 +785,7 @@ pub fn report_partial_reinitialization_of_uninitialized_structure(
                                                       &self.loan_path_to_string(lp),
                                                       Origin::Ast)
             .emit();
+        self.signal_error();
     }
 
     pub fn report_reassigned_immutable_variable(&self,
@@ -787,6 +803,7 @@ pub fn report_reassigned_immutable_variable(&self,
                                                 self.loan_path_to_string(lp)));
         }
         err.emit();
+        self.signal_error();
     }
 
     pub fn struct_span_err_with_code<S: Into<MultiSpan>>(&self,
@@ -908,6 +925,7 @@ fn report_bckerr(&self, err: &BckError<'a, 'tcx>) {
                     self.tcx.hir.hir_to_node_id(err.cmt.hir_id)
                 );
                 db.emit();
+                self.signal_error();
             }
             err_out_of_scope(super_scope, sub_scope, cause) => {
                 let msg = match opt_loan_path(&err.cmt) {
@@ -1022,6 +1040,7 @@ fn report_bckerr(&self, err: &BckError<'a, 'tcx>) {
                 }
 
                 db.emit();
+                self.signal_error();
             }
             err_borrowed_pointer_too_short(loan_scope, ptr_scope) => {
                 let descr = self.cmt_to_path_or_string(err.cmt);
@@ -1047,6 +1066,7 @@ fn report_bckerr(&self, err: &BckError<'a, 'tcx>) {
                     "");
 
                 db.emit();
+                self.signal_error();
             }
         }
     }
@@ -1125,6 +1145,7 @@ pub fn report_aliasability_violation(&self,
             err.help("closures behind references must be called via `&mut`");
         }
         err.emit();
+        self.signal_error();
     }
 
     /// Given a type, if it is an immutable reference, return a suggestion to make it mutable
@@ -1307,6 +1328,7 @@ fn report_out_of_scope_escaping_closure_capture(&self,
                                        cmt_path_or_string),
                              suggestion)
             .emit();
+        self.signal_error();
     }
 
     fn region_end_span(&self, region: ty::Region<'tcx>) -> Option<Span> {