use a UnlessNll
flag to consolidate error reporting paths
This commit is contained in:
parent
84563dac88
commit
1830c9e8f9
6 changed files with 32 additions and 48 deletions
|
@ -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 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
&self,
|
||||
region_scope_tree: ®ion::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 => {},
|
||||
|
|
|
@ -80,6 +80,16 @@ pub type Bound<T> = Option<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 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
region_context: DefId,
|
||||
region_map: ®ion::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: ®ion::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: ®ion::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 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ pub use self::ObligationCauseCode::*;
|
|||
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, ®ion_scope_tree, &outlives_env);
|
||||
infcx.resolve_regions_and_report_errors(
|
||||
region_context,
|
||||
®ion_scope_tree,
|
||||
&outlives_env,
|
||||
UnlessNll(false),
|
||||
);
|
||||
|
||||
let predicates = match infcx.fully_resolve(&predicates) {
|
||||
Ok(predicates) => predicates,
|
||||
|
|
|
@ -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, ®ion_scope_tree, &outlives_env);
|
||||
infcx.resolve_regions_and_report_errors(drop_impl_did, ®ion_scope_tree, &outlives_env, UnlessNll(false));
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ use middle::mem_categorization as mc;
|
|||
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 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
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 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, '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 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
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 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
®ion_scope_tree,
|
||||
&outlives_env,
|
||||
UnlessNll(false),
|
||||
);
|
||||
|
||||
CoerceUnsizedInfo {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue