use crate::check::FnCtxt;
use crate::mem_categorization as mc;
use crate::middle::region;
-use rustc::hir::map::Map;
-use rustc::ty::adjustment;
-use rustc::ty::subst::{GenericArgKind, SubstsRef};
-use rustc::ty::{self, Ty};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::PatKind;
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
-use rustc_infer::infer::{self, RegionObligation, SuppressRegionErrors};
+use rustc_infer::infer::{self, RegionObligation, RegionckMode};
+use rustc_middle::ty::adjustment;
+use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
+use rustc_middle::ty::{self, Ty};
use rustc_span::Span;
+use rustc_trait_selection::infer::OutlivesEnvironmentExt;
+use rustc_trait_selection::opaque_types::InferCtxtExt;
use std::mem;
use std::ops::Deref;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn regionck_expr(&self, body: &'tcx hir::Body<'tcx>) {
- let subject = self.tcx.hir().body_owner_def_id(body.id());
+ let subject = self.tcx.hir().body_owner_def_id(body.id()).to_def_id();
let id = body.value.hir_id;
let mut rcx =
RegionCtxt::new(self, RepeatingScope(id), id, Subject(subject), self.param_env);
rcx.visit_body(body);
rcx.visit_region_obligations(id);
}
- rcx.resolve_regions_and_report_errors(SuppressRegionErrors::when_nll_is_enabled(self.tcx));
-
- assert!(self.tables.borrow().free_region_map.is_empty());
- self.tables.borrow_mut().free_region_map = rcx.outlives_environment.into_free_region_map();
+ rcx.resolve_regions_and_report_errors(RegionckMode::for_item_body(self.tcx));
}
/// Region checking during the WF phase for items. `wf_tys` are the
rcx.outlives_environment.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(SuppressRegionErrors::default());
+ rcx.resolve_regions_and_report_errors(RegionckMode::default());
}
/// Region check a function body. Not invoked on closures, but
/// constraints to add.
pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'tcx hir::Body<'tcx>) {
debug!("regionck_fn(id={})", fn_id);
- let subject = self.tcx.hir().body_owner_def_id(body.id());
+ let subject = self.tcx.hir().body_owner_def_id(body.id()).to_def_id();
let hir_id = body.value.hir_id;
let mut rcx =
RegionCtxt::new(self, RepeatingScope(hir_id), hir_id, Subject(subject), self.param_env);
rcx.visit_fn_body(fn_id, body, self.tcx.hir().span(fn_id));
}
- rcx.resolve_regions_and_report_errors(SuppressRegionErrors::when_nll_is_enabled(self.tcx));
-
- // In this mode, we also copy the free-region-map into the
- // tables of the enclosing fcx. In the other regionck modes
- // (e.g., `regionck_item`), we don't have an enclosing tables.
- assert!(self.tables.borrow().free_region_map.is_empty());
- self.tables.borrow_mut().free_region_map = rcx.outlives_environment.into_free_region_map();
+ rcx.resolve_regions_and_report_errors(RegionckMode::for_item_body(self.tcx));
}
}
let body_id = body.id();
self.body_id = body_id.hir_id;
- self.body_owner = self.tcx.hir().body_owner_def_id(body_id);
+ self.body_owner = self.tcx.hir().body_owner_def_id(body_id).to_def_id();
let call_site =
region::Scope { id: body.value.hir_id.local_id, data: region::ScopeData::CallSite };
self.select_all_obligations_or_error();
}
- fn resolve_regions_and_report_errors(&self, suppress: SuppressRegionErrors) {
+ fn resolve_regions_and_report_errors(&self, mode: RegionckMode) {
self.infcx.process_registered_region_obligations(
self.outlives_environment.region_bound_pairs_map(),
self.implicit_region_bound,
self.subject_def_id,
&self.region_scope_tree,
&self.outlives_environment,
- suppress,
+ mode,
);
}
// hierarchy, and in particular the relationships between free
// regions, until regionck, as described in #3238.
- type Map = Map<'tcx>;
+ type Map = intravisit::ErasedMap<'tcx>;
- fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
NestedVisitorMap::None
}
// A closure capture can't be borrowed for longer than the
// reference to the closure.
- if let ty::Closure(closure_def_id, substs) = ty.kind {
- match self.infcx.closure_kind(closure_def_id, substs) {
- Some(ty::ClosureKind::Fn) | Some(ty::ClosureKind::FnMut) => {
+ if let ty::Closure(_, substs) = ty.kind {
+ match self.infcx.closure_kind(substs) {
+ Some(ty::ClosureKind::Fn | ty::ClosureKind::FnMut) => {
// Region of environment pointer
let env_region = self.tcx.mk_region(ty::ReFree(ty::FreeRegion {
scope: upvar_id.closure_expr_id.to_def_id(),