Skip to content

Commit 1830c9e

Browse files
committed
use a UnlessNll flag to consolidate error reporting paths
1 parent 84563da commit 1830c9e

File tree

6 files changed

+32
-48
lines changed

6 files changed

+32
-48
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
//! ported to this system, and which relies on string concatenation at the
5656
//! time of error detection.
5757
58-
use infer;
58+
use infer::{self, UnlessNll};
5959
use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
6060
use super::region_constraints::GenericKind;
6161
use super::lexical_region_resolve::RegionResolutionError;
@@ -298,13 +298,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
298298
&self,
299299
region_scope_tree: &region::ScopeTree,
300300
errors: &Vec<RegionResolutionError<'tcx>>,
301-
will_later_be_reported_by_nll: bool,
301+
unless_nll: UnlessNll,
302302
) {
303303
debug!("report_region_errors(): {} errors to start", errors.len());
304304

305305
// If the errors will later be reported by NLL, choose wether to display them or not based
306306
// on the borrowck mode
307-
if will_later_be_reported_by_nll {
307+
if unless_nll.0 {
308308
match self.tcx.borrowck_mode() {
309309
// If we're on AST or Migrate mode, report AST region errors
310310
BorrowckMode::Ast | BorrowckMode::Migrate => {},

src/librustc/infer/mod.rs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ pub type Bound<T> = Option<T>;
8080
pub type UnitResult<'tcx> = RelateResult<'tcx, ()>; // "unify result"
8181
pub type FixupResult<T> = Result<T, FixupError>; // "fixup result"
8282

83+
/// A flag that is given when running region resolution: if true, it
84+
/// indicates that we should not report the region errors to the user
85+
/// if NLL is enabled, since NLL will also detect them (and do a
86+
/// better job of it).
87+
///
88+
/// Currently, NLL only runs on HIR bodies, so you should use `false`
89+
/// unless you are region-checking a `hir::Body` (basically, a fn or
90+
/// expression).
91+
pub struct UnlessNll(pub bool);
92+
8393
pub struct InferCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
8494
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
8595

@@ -1039,34 +1049,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10391049
region_context: DefId,
10401050
region_map: &region::ScopeTree,
10411051
outlives_env: &OutlivesEnvironment<'tcx>,
1042-
) {
1043-
self.resolve_regions_and_report_errors_inner(
1044-
region_context,
1045-
region_map,
1046-
outlives_env,
1047-
false,
1048-
)
1049-
}
1050-
1051-
/// Like `resolve_regions_and_report_errors`, but skips error
1052-
/// reporting if NLL is enabled. This is used for fn bodies where
1053-
/// the same error may later be reported by the NLL-based
1054-
/// inference.
1055-
pub fn resolve_regions_and_report_errors_unless_nll(
1056-
&self,
1057-
region_context: DefId,
1058-
region_map: &region::ScopeTree,
1059-
outlives_env: &OutlivesEnvironment<'tcx>,
1060-
) {
1061-
self.resolve_regions_and_report_errors_inner(region_context, region_map, outlives_env, true)
1062-
}
1063-
1064-
fn resolve_regions_and_report_errors_inner(
1065-
&self,
1066-
region_context: DefId,
1067-
region_map: &region::ScopeTree,
1068-
outlives_env: &OutlivesEnvironment<'tcx>,
1069-
will_later_be_reported_by_nll: bool,
1052+
unless_nll: UnlessNll,
10701053
) {
10711054
assert!(
10721055
self.is_tainted_by_errors() || self.region_obligations.borrow().is_empty(),
@@ -1098,7 +1081,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10981081
// this infcx was in use. This is totally hokey but
10991082
// otherwise we have a hard time separating legit region
11001083
// errors from silly ones.
1101-
self.report_region_errors(region_map, &errors, will_later_be_reported_by_nll);
1084+
self.report_region_errors(region_map, &errors, unless_nll);
11021085
}
11031086
}
11041087

src/librustc/traits/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub use self::ObligationCauseCode::*;
2020
use chalk_engine;
2121
use hir;
2222
use hir::def_id::DefId;
23+
use infer::UnlessNll;
2324
use infer::outlives::env::OutlivesEnvironment;
2425
use middle::region;
2526
use mir::interpret::ConstEvalErr;
@@ -715,7 +716,12 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
715716
// cares about declarations like `'a: 'b`.
716717
let outlives_env = OutlivesEnvironment::new(elaborated_env);
717718

718-
infcx.resolve_regions_and_report_errors(region_context, &region_scope_tree, &outlives_env);
719+
infcx.resolve_regions_and_report_errors(
720+
region_context,
721+
&region_scope_tree,
722+
&outlives_env,
723+
UnlessNll(false),
724+
);
719725

720726
let predicates = match infcx.fully_resolve(&predicates) {
721727
Ok(predicates) => predicates,

src/librustc_typeck/check/dropck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use check::regionck::RegionCtxt;
1212

1313
use hir::def_id::DefId;
14-
use rustc::infer::{self, InferOk};
14+
use rustc::infer::{self, InferOk, UnlessNll};
1515
use rustc::infer::outlives::env::OutlivesEnvironment;
1616
use rustc::middle::region;
1717
use rustc::ty::subst::{Subst, Substs, UnpackedKind};
@@ -128,7 +128,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>(
128128
// conservative. -nmatsakis
129129
let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty());
130130

131-
infcx.resolve_regions_and_report_errors(drop_impl_did, &region_scope_tree, &outlives_env);
131+
infcx.resolve_regions_and_report_errors(drop_impl_did, &region_scope_tree, &outlives_env, UnlessNll(false));
132132
Ok(())
133133
})
134134
}

src/librustc_typeck/check/regionck.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use middle::mem_categorization as mc;
8888
use middle::mem_categorization::Categorization;
8989
use middle::region;
9090
use rustc::hir::def_id::DefId;
91-
use rustc::infer;
91+
use rustc::infer::{self, UnlessNll};
9292
use rustc::infer::outlives::env::OutlivesEnvironment;
9393
use rustc::ty::adjustment;
9494
use rustc::ty::subst::Substs;
@@ -140,7 +140,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
140140
rcx.visit_body(body);
141141
rcx.visit_region_obligations(id);
142142
}
143-
rcx.resolve_regions_and_report_errors_unless_nll();
143+
rcx.resolve_regions_and_report_errors(UnlessNll(true));
144144

145145
assert!(self.tables.borrow().free_region_map.is_empty());
146146
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> {
162162
.add_implied_bounds(self, wf_tys, item_id, span);
163163
rcx.outlives_environment.save_implied_bounds(item_id);
164164
rcx.visit_region_obligations(item_id);
165-
rcx.resolve_regions_and_report_errors();
165+
rcx.resolve_regions_and_report_errors(UnlessNll(false));
166166
}
167167

168168
/// Region check a function body. Not invoked on closures, but
@@ -190,7 +190,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
190190
rcx.visit_fn_body(fn_id, body, self.tcx.hir.span(fn_id));
191191
}
192192

193-
rcx.resolve_regions_and_report_errors_unless_nll();
193+
rcx.resolve_regions_and_report_errors(UnlessNll(true));
194194

195195
// In this mode, we also copy the free-region-map into the
196196
// tables of the enclosing fcx. In the other regionck modes
@@ -399,19 +399,12 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
399399
);
400400
}
401401

402-
fn resolve_regions_and_report_errors(&self) {
402+
fn resolve_regions_and_report_errors(&self, unless_nll: UnlessNll) {
403403
self.fcx.resolve_regions_and_report_errors(
404404
self.subject_def_id,
405405
&self.region_scope_tree,
406406
&self.outlives_environment,
407-
);
408-
}
409-
410-
fn resolve_regions_and_report_errors_unless_nll(&self) {
411-
self.fcx.resolve_regions_and_report_errors_unless_nll(
412-
self.subject_def_id,
413-
&self.region_scope_tree,
414-
&self.outlives_environment,
407+
unless_nll,
415408
);
416409
}
417410

src/librustc_typeck/coherence/builtin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! Check properties that are required by built-in traits and set
1212
//! up data structures required by type-checking/codegen.
1313
14+
use rustc::infer::UnlessNll;
1415
use rustc::infer::outlives::env::OutlivesEnvironment;
1516
use rustc::middle::region;
1617
use rustc::middle::lang_items::UnsizeTraitLangItem;
@@ -396,6 +397,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>,
396397
impl_did,
397398
&region_scope_tree,
398399
&outlives_env,
400+
UnlessNll(false),
399401
);
400402

401403
CoerceUnsizedInfo {

0 commit comments

Comments
 (0)