]> git.lizzy.rs Git - rust.git/commitdiff
use a `UnlessNll` flag to consolidate error reporting paths
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 12 Sep 2018 19:43:26 +0000 (15:43 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 26 Sep 2018 13:30:54 +0000 (09:30 -0400)
src/librustc/infer/error_reporting/mod.rs
src/librustc/infer/mod.rs
src/librustc/traits/mod.rs
src/librustc_typeck/check/dropck.rs
src/librustc_typeck/check/regionck.rs
src/librustc_typeck/coherence/builtin.rs

index cf76c3b7e02dfbb94185bdd6ff561e07c0b400ee..fe9e00f8a60383a3cf19bad67812b5e35b47a1a0 100644 (file)
@@ -55,7 +55,7 @@
 //! ported to this system, and which relies on string concatenation at the
 //! time of error detection.
 
-use infer;
+use infer::{self, UnlessNll};
 use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
 use super::region_constraints::GenericKind;
 use super::lexical_region_resolve::RegionResolutionError;
@@ -298,13 +298,13 @@ pub fn report_region_errors(
         &self,
         region_scope_tree: &region::ScopeTree,
         errors: &Vec<RegionResolutionError<'tcx>>,
-        will_later_be_reported_by_nll: bool,
+        unless_nll: UnlessNll,
     ) {
         debug!("report_region_errors(): {} errors to start", errors.len());
 
         // If the errors will later be reported by NLL, choose wether to display them or not based
         // on the borrowck mode
-        if will_later_be_reported_by_nll {
+        if unless_nll.0 {
             match self.tcx.borrowck_mode() {
                 // If we're on AST or Migrate mode, report AST region errors
                 BorrowckMode::Ast | BorrowckMode::Migrate => {},
index e628a3458f9e628c0ed450caae519aea28dd4d12..6e20194dff9b75c635f5e7ca100b839c58a759da 100644 (file)
@@ -80,6 +80,16 @@ pub struct InferOk<'tcx, T> {
 pub type UnitResult<'tcx> = RelateResult<'tcx, ()>; // "unify result"
 pub type FixupResult<T> = Result<T, FixupError>; // "fixup result"
 
+/// A flag that is given when running region resolution: if true, it
+/// indicates that we should not report the region errors to the user
+/// if NLL is enabled, since NLL will also detect them (and do a
+/// better job of it).
+///
+/// Currently, NLL only runs on HIR bodies, so you should use `false`
+/// unless you are region-checking a `hir::Body` (basically, a fn or
+/// expression).
+pub struct UnlessNll(pub bool);
+
 pub struct InferCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
     pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
 
@@ -1039,34 +1049,7 @@ pub fn resolve_regions_and_report_errors(
         region_context: DefId,
         region_map: &region::ScopeTree,
         outlives_env: &OutlivesEnvironment<'tcx>,
-    ) {
-        self.resolve_regions_and_report_errors_inner(
-            region_context,
-            region_map,
-            outlives_env,
-            false,
-        )
-    }
-
-    /// Like `resolve_regions_and_report_errors`, but skips error
-    /// reporting if NLL is enabled.  This is used for fn bodies where
-    /// the same error may later be reported by the NLL-based
-    /// inference.
-    pub fn resolve_regions_and_report_errors_unless_nll(
-        &self,
-        region_context: DefId,
-        region_map: &region::ScopeTree,
-        outlives_env: &OutlivesEnvironment<'tcx>,
-    ) {
-        self.resolve_regions_and_report_errors_inner(region_context, region_map, outlives_env, true)
-    }
-
-    fn resolve_regions_and_report_errors_inner(
-        &self,
-        region_context: DefId,
-        region_map: &region::ScopeTree,
-        outlives_env: &OutlivesEnvironment<'tcx>,
-        will_later_be_reported_by_nll: bool,
+        unless_nll: UnlessNll,
     ) {
         assert!(
             self.is_tainted_by_errors() || self.region_obligations.borrow().is_empty(),
@@ -1098,7 +1081,7 @@ fn resolve_regions_and_report_errors_inner(
             // this infcx was in use.  This is totally hokey but
             // otherwise we have a hard time separating legit region
             // errors from silly ones.
-            self.report_region_errors(region_map, &errors, will_later_be_reported_by_nll);
+            self.report_region_errors(region_map, &errors, unless_nll);
         }
     }
 
index edf7772f2f78ef76f907275f62fd7700fce9da06..6c0fe157a2a6593820d970efff1cb2e7908dceab 100644 (file)
@@ -20,6 +20,7 @@
 use chalk_engine;
 use hir;
 use hir::def_id::DefId;
+use infer::UnlessNll;
 use infer::outlives::env::OutlivesEnvironment;
 use middle::region;
 use mir::interpret::ConstEvalErr;
@@ -715,7 +716,12 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         // cares about declarations like `'a: 'b`.
         let outlives_env = OutlivesEnvironment::new(elaborated_env);
 
-        infcx.resolve_regions_and_report_errors(region_context, &region_scope_tree, &outlives_env);
+        infcx.resolve_regions_and_report_errors(
+            region_context,
+            &region_scope_tree,
+            &outlives_env,
+            UnlessNll(false),
+        );
 
         let predicates = match infcx.fully_resolve(&predicates) {
             Ok(predicates) => predicates,
index 9d3cbf910e05958f3633f0d6c02fe9af944b1471..c6e0da309a40ffdf795288a2e1e91d05753742df 100644 (file)
@@ -11,7 +11,7 @@
 use check::regionck::RegionCtxt;
 
 use hir::def_id::DefId;
-use rustc::infer::{self, InferOk};
+use rustc::infer::{self, InferOk, UnlessNll};
 use rustc::infer::outlives::env::OutlivesEnvironment;
 use rustc::middle::region;
 use rustc::ty::subst::{Subst, Substs, UnpackedKind};
@@ -128,7 +128,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>(
         // conservative. -nmatsakis
         let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty());
 
-        infcx.resolve_regions_and_report_errors(drop_impl_did, &region_scope_tree, &outlives_env);
+        infcx.resolve_regions_and_report_errors(drop_impl_did, &region_scope_tree, &outlives_env, UnlessNll(false));
         Ok(())
     })
 }
index aad474d0a885991b2e510fc662310ec38b0c0203..3c462c1ae7a25a5d9c2385b92c492542dd706c22 100644 (file)
@@ -88,7 +88,7 @@
 use middle::mem_categorization::Categorization;
 use middle::region;
 use rustc::hir::def_id::DefId;
-use rustc::infer;
+use rustc::infer::{self, UnlessNll};
 use rustc::infer::outlives::env::OutlivesEnvironment;
 use rustc::ty::adjustment;
 use rustc::ty::subst::Substs;
@@ -140,7 +140,7 @@ pub fn regionck_expr(&self, body: &'gcx hir::Body) {
             rcx.visit_body(body);
             rcx.visit_region_obligations(id);
         }
-        rcx.resolve_regions_and_report_errors_unless_nll();
+        rcx.resolve_regions_and_report_errors(UnlessNll(true));
 
         assert!(self.tables.borrow().free_region_map.is_empty());
         self.tables.borrow_mut().free_region_map = rcx.outlives_environment.into_free_region_map();
@@ -162,7 +162,7 @@ pub fn regionck_item(&self, item_id: ast::NodeId, span: Span, wf_tys: &[Ty<'tcx>
             .add_implied_bounds(self, wf_tys, item_id, span);
         rcx.outlives_environment.save_implied_bounds(item_id);
         rcx.visit_region_obligations(item_id);
-        rcx.resolve_regions_and_report_errors();
+        rcx.resolve_regions_and_report_errors(UnlessNll(false));
     }
 
     /// Region check a function body. Not invoked on closures, but
@@ -190,7 +190,7 @@ pub fn regionck_fn(&self, fn_id: ast::NodeId, body: &'gcx hir::Body) {
             rcx.visit_fn_body(fn_id, body, self.tcx.hir.span(fn_id));
         }
 
-        rcx.resolve_regions_and_report_errors_unless_nll();
+        rcx.resolve_regions_and_report_errors(UnlessNll(true));
 
         // In this mode, we also copy the free-region-map into the
         // tables of the enclosing fcx. In the other regionck modes
@@ -399,19 +399,12 @@ fn visit_region_obligations(&mut self, node_id: ast::NodeId) {
         );
     }
 
-    fn resolve_regions_and_report_errors(&self) {
+    fn resolve_regions_and_report_errors(&self, unless_nll: UnlessNll) {
         self.fcx.resolve_regions_and_report_errors(
             self.subject_def_id,
             &self.region_scope_tree,
             &self.outlives_environment,
-        );
-    }
-
-    fn resolve_regions_and_report_errors_unless_nll(&self) {
-        self.fcx.resolve_regions_and_report_errors_unless_nll(
-            self.subject_def_id,
-            &self.region_scope_tree,
-            &self.outlives_environment,
+            unless_nll,
         );
     }
 
index efc35fad820c820c8c52924be8729e890ad1ba81..4def76e892289bf3c0410a0d68927558f7de84e2 100644 (file)
@@ -11,6 +11,7 @@
 //! Check properties that are required by built-in traits and set
 //! up data structures required by type-checking/codegen.
 
+use rustc::infer::UnlessNll;
 use rustc::infer::outlives::env::OutlivesEnvironment;
 use rustc::middle::region;
 use rustc::middle::lang_items::UnsizeTraitLangItem;
@@ -396,6 +397,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>,
             impl_did,
             &region_scope_tree,
             &outlives_env,
+            UnlessNll(false),
         );
 
         CoerceUnsizedInfo {