introduce LateParamRegionKind
This commit is contained in:
parent
3378a5e084
commit
085d931810
19 changed files with 157 additions and 59 deletions
|
@ -188,7 +188,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
|
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
|
||||||
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
|
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
|
||||||
if let Some(ty::ReLateParam(late_param)) = self.to_error_region(fr).as_deref()
|
if let Some(ty::ReLateParam(late_param)) = self.to_error_region(fr).as_deref()
|
||||||
&& let ty::BoundRegionKind::ClosureEnv = late_param.bound_region
|
&& let ty::LateParamRegionKind::ClosureEnv = late_param.kind
|
||||||
&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
|
&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
|
||||||
{
|
{
|
||||||
return args.as_closure().kind() == ty::ClosureKind::FnMut;
|
return args.as_closure().kind() == ty::ClosureKind::FnMut;
|
||||||
|
|
|
@ -299,17 +299,17 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||||
Some(RegionName { name: kw::StaticLifetime, source: RegionNameSource::Static })
|
Some(RegionName { name: kw::StaticLifetime, source: RegionNameSource::Static })
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::ReLateParam(late_param) => match late_param.bound_region {
|
ty::ReLateParam(late_param) => match late_param.kind {
|
||||||
ty::BoundRegionKind::Named(region_def_id, name) => {
|
ty::LateParamRegionKind::Named(region_def_id, name) => {
|
||||||
// Get the span to point to, even if we don't use the name.
|
// Get the span to point to, even if we don't use the name.
|
||||||
let span = tcx.hir().span_if_local(region_def_id).unwrap_or(DUMMY_SP);
|
let span = tcx.hir().span_if_local(region_def_id).unwrap_or(DUMMY_SP);
|
||||||
debug!(
|
debug!(
|
||||||
"bound region named: {:?}, is_named: {:?}",
|
"bound region named: {:?}, is_named: {:?}",
|
||||||
name,
|
name,
|
||||||
late_param.bound_region.is_named()
|
late_param.kind.is_named()
|
||||||
);
|
);
|
||||||
|
|
||||||
if late_param.bound_region.is_named() {
|
if late_param.kind.is_named() {
|
||||||
// A named region that is actually named.
|
// A named region that is actually named.
|
||||||
Some(RegionName {
|
Some(RegionName {
|
||||||
name,
|
name,
|
||||||
|
@ -331,7 +331,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::BoundRegionKind::ClosureEnv => {
|
ty::LateParamRegionKind::ClosureEnv => {
|
||||||
let def_ty = self.regioncx.universal_regions().defining_ty;
|
let def_ty = self.regioncx.universal_regions().defining_ty;
|
||||||
|
|
||||||
let closure_kind = match def_ty {
|
let closure_kind = match def_ty {
|
||||||
|
@ -368,7 +368,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::BoundRegionKind::Anon => None,
|
ty::LateParamRegionKind::Anon(_) => None,
|
||||||
},
|
},
|
||||||
|
|
||||||
ty::ReBound(..)
|
ty::ReBound(..)
|
||||||
|
|
|
@ -842,8 +842,9 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
|
||||||
{
|
{
|
||||||
let (value, _map) = self.tcx.instantiate_bound_regions(value, |br| {
|
let (value, _map) = self.tcx.instantiate_bound_regions(value, |br| {
|
||||||
debug!(?br);
|
debug!(?br);
|
||||||
|
let kind = ty::LateParamRegionKind::from_bound(br.var, br.kind);
|
||||||
let liberated_region =
|
let liberated_region =
|
||||||
ty::Region::new_late_param(self.tcx, all_outlive_scope.to_def_id(), br.kind);
|
ty::Region::new_late_param(self.tcx, all_outlive_scope.to_def_id(), kind);
|
||||||
let region_vid = {
|
let region_vid = {
|
||||||
let name = match br.kind.get_name() {
|
let name = match br.kind.get_name() {
|
||||||
Some(name) => name,
|
Some(name) => name,
|
||||||
|
@ -941,12 +942,13 @@ fn for_each_late_bound_region_in_item<'tcx>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for bound_var in tcx.late_bound_vars(tcx.local_def_id_to_hir_id(mir_def_id)) {
|
for (idx, bound_var) in
|
||||||
let ty::BoundVariableKind::Region(bound_region) = bound_var else {
|
tcx.late_bound_vars(tcx.local_def_id_to_hir_id(mir_def_id)).iter().enumerate()
|
||||||
continue;
|
{
|
||||||
};
|
if let ty::BoundVariableKind::Region(kind) = bound_var {
|
||||||
let liberated_region =
|
let kind = ty::LateParamRegionKind::from_bound(ty::BoundVar::from_usize(idx), kind);
|
||||||
ty::Region::new_late_param(tcx, mir_def_id.to_def_id(), bound_region);
|
let liberated_region = ty::Region::new_late_param(tcx, mir_def_id.to_def_id(), kind);
|
||||||
f(liberated_region);
|
f(liberated_region);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -430,12 +430,12 @@ fn compare_method_predicate_entailment<'tcx>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RemapLateBound<'a, 'tcx> {
|
struct RemapLateParam<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
mapping: &'a FxIndexMap<ty::BoundRegionKind, ty::BoundRegionKind>,
|
mapping: &'a FxIndexMap<ty::LateParamRegionKind, ty::LateParamRegionKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
|
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'_, 'tcx> {
|
||||||
fn cx(&self) -> TyCtxt<'tcx> {
|
fn cx(&self) -> TyCtxt<'tcx> {
|
||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
|
@ -445,7 +445,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
|
||||||
ty::Region::new_late_param(
|
ty::Region::new_late_param(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
fr.scope,
|
fr.scope,
|
||||||
self.mapping.get(&fr.bound_region).copied().unwrap_or(fr.bound_region),
|
self.mapping.get(&fr.kind).copied().unwrap_or(fr.kind),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
r
|
r
|
||||||
|
|
|
@ -289,11 +289,16 @@ fn report_mismatched_rpitit_signature<'tcx>(
|
||||||
tcx.fn_sig(trait_m_def_id).skip_binder().bound_vars(),
|
tcx.fn_sig(trait_m_def_id).skip_binder().bound_vars(),
|
||||||
tcx.fn_sig(impl_m_def_id).skip_binder().bound_vars(),
|
tcx.fn_sig(impl_m_def_id).skip_binder().bound_vars(),
|
||||||
)
|
)
|
||||||
.filter_map(|(impl_bv, trait_bv)| {
|
.enumerate()
|
||||||
|
.filter_map(|(idx, (impl_bv, trait_bv))| {
|
||||||
if let ty::BoundVariableKind::Region(impl_bv) = impl_bv
|
if let ty::BoundVariableKind::Region(impl_bv) = impl_bv
|
||||||
&& let ty::BoundVariableKind::Region(trait_bv) = trait_bv
|
&& let ty::BoundVariableKind::Region(trait_bv) = trait_bv
|
||||||
{
|
{
|
||||||
Some((impl_bv, trait_bv))
|
let var = ty::BoundVar::from_usize(idx);
|
||||||
|
Some((
|
||||||
|
ty::LateParamRegionKind::from_bound(var, impl_bv),
|
||||||
|
ty::LateParamRegionKind::from_bound(var, trait_bv),
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -301,7 +306,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut return_ty =
|
let mut return_ty =
|
||||||
trait_m_sig.output().fold_with(&mut super::RemapLateBound { tcx, mapping: &mapping });
|
trait_m_sig.output().fold_with(&mut super::RemapLateParam { tcx, mapping: &mapping });
|
||||||
|
|
||||||
if tcx.asyncness(impl_m_def_id).is_async() && tcx.asyncness(trait_m_def_id).is_async() {
|
if tcx.asyncness(impl_m_def_id).is_async() && tcx.asyncness(trait_m_def_id).is_async() {
|
||||||
let ty::Alias(ty::Projection, future_ty) = return_ty.kind() else {
|
let ty::Alias(ty::Projection, future_ty) = return_ty.kind() else {
|
||||||
|
|
|
@ -2339,8 +2339,11 @@ fn lint_redundant_lifetimes<'tcx>(
|
||||||
);
|
);
|
||||||
// If we are in a function, add its late-bound lifetimes too.
|
// If we are in a function, add its late-bound lifetimes too.
|
||||||
if matches!(def_kind, DefKind::Fn | DefKind::AssocFn) {
|
if matches!(def_kind, DefKind::Fn | DefKind::AssocFn) {
|
||||||
for var in tcx.fn_sig(owner_id).instantiate_identity().bound_vars() {
|
for (idx, var) in
|
||||||
|
tcx.fn_sig(owner_id).instantiate_identity().bound_vars().iter().enumerate()
|
||||||
|
{
|
||||||
let ty::BoundVariableKind::Region(kind) = var else { continue };
|
let ty::BoundVariableKind::Region(kind) = var else { continue };
|
||||||
|
let kind = ty::LateParamRegionKind::from_bound(ty::BoundVar::from_usize(idx), kind);
|
||||||
lifetimes.push(ty::Region::new_late_param(tcx, owner_id.to_def_id(), kind));
|
lifetimes.push(ty::Region::new_late_param(tcx, owner_id.to_def_id(), kind));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -355,7 +355,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
ty::Region::new_late_param(
|
ty::Region::new_late_param(
|
||||||
tcx,
|
tcx,
|
||||||
scope.to_def_id(),
|
scope.to_def_id(),
|
||||||
ty::BoundRegionKind::Named(id.to_def_id(), name),
|
ty::LateParamRegionKind::Named(id.to_def_id(), name),
|
||||||
)
|
)
|
||||||
|
|
||||||
// (*) -- not late-bound, won't change
|
// (*) -- not late-bound, won't change
|
||||||
|
|
|
@ -325,7 +325,7 @@ where
|
||||||
ParamKind::Free(def_id, name) => ty::Region::new_late_param(
|
ParamKind::Free(def_id, name) => ty::Region::new_late_param(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
self.parent_def_id.to_def_id(),
|
self.parent_def_id.to_def_id(),
|
||||||
ty::BoundRegionKind::Named(def_id, name),
|
ty::LateParamRegionKind::Named(def_id, name),
|
||||||
),
|
),
|
||||||
// Totally ignore late bound args from binders.
|
// Totally ignore late bound args from binders.
|
||||||
ParamKind::Late => return true,
|
ParamKind::Late => return true,
|
||||||
|
@ -475,7 +475,7 @@ fn extract_def_id_from_arg<'tcx>(
|
||||||
)
|
)
|
||||||
| ty::ReLateParam(ty::LateParamRegion {
|
| ty::ReLateParam(ty::LateParamRegion {
|
||||||
scope: _,
|
scope: _,
|
||||||
bound_region: ty::BoundRegionKind::Named(def_id, ..),
|
kind: ty::LateParamRegionKind::Named(def_id, ..),
|
||||||
}) => def_id,
|
}) => def_id,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
|
@ -544,7 +544,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for FunctionalVariances<'tcx> {
|
||||||
)
|
)
|
||||||
| ty::ReLateParam(ty::LateParamRegion {
|
| ty::ReLateParam(ty::LateParamRegion {
|
||||||
scope: _,
|
scope: _,
|
||||||
bound_region: ty::BoundRegionKind::Named(def_id, ..),
|
kind: ty::LateParamRegionKind::Named(def_id, ..),
|
||||||
}) => def_id,
|
}) => def_id,
|
||||||
_ => {
|
_ => {
|
||||||
return Ok(a);
|
return Ok(a);
|
||||||
|
|
|
@ -3091,7 +3091,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
return ty::Region::new_late_param(
|
return ty::Region::new_late_param(
|
||||||
self,
|
self,
|
||||||
new_parent.to_def_id(),
|
new_parent.to_def_id(),
|
||||||
ty::BoundRegionKind::Named(
|
ty::LateParamRegionKind::Named(
|
||||||
lbv.to_def_id(),
|
lbv.to_def_id(),
|
||||||
self.item_name(lbv.to_def_id()),
|
self.item_name(lbv.to_def_id()),
|
||||||
),
|
),
|
||||||
|
|
|
@ -270,7 +270,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||||
{
|
{
|
||||||
self.instantiate_bound_regions_uncached(value, |br| {
|
self.instantiate_bound_regions_uncached(value, |br| {
|
||||||
ty::Region::new_late_param(self, all_outlive_scope, br.kind)
|
let kind = ty::LateParamRegionKind::from_bound(br.var, br.kind);
|
||||||
|
ty::Region::new_late_param(self, all_outlive_scope, kind)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,8 @@ pub use self::predicate::{
|
||||||
TypeOutlivesPredicate,
|
TypeOutlivesPredicate,
|
||||||
};
|
};
|
||||||
pub use self::region::{
|
pub use self::region::{
|
||||||
BoundRegion, BoundRegionKind, EarlyParamRegion, LateParamRegion, Region, RegionKind, RegionVid,
|
BoundRegion, BoundRegionKind, EarlyParamRegion, LateParamRegion, LateParamRegionKind, Region,
|
||||||
|
RegionKind, RegionVid,
|
||||||
};
|
};
|
||||||
pub use self::rvalue_scopes::RvalueScopes;
|
pub use self::rvalue_scopes::RvalueScopes;
|
||||||
pub use self::sty::{
|
pub use self::sty::{
|
||||||
|
|
|
@ -2374,8 +2374,8 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||||
match *region {
|
match *region {
|
||||||
ty::ReEarlyParam(ref data) => data.has_name(),
|
ty::ReEarlyParam(ref data) => data.has_name(),
|
||||||
|
|
||||||
|
ty::ReLateParam(ty::LateParamRegion { kind, .. }) => kind.is_named(),
|
||||||
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
|
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
|
||||||
| ty::ReLateParam(ty::LateParamRegion { bound_region: br, .. })
|
|
||||||
| ty::RePlaceholder(ty::Placeholder {
|
| ty::RePlaceholder(ty::Placeholder {
|
||||||
bound: ty::BoundRegion { kind: br, .. }, ..
|
bound: ty::BoundRegion { kind: br, .. }, ..
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -2448,8 +2448,13 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ty::ReLateParam(ty::LateParamRegion { kind, .. }) => {
|
||||||
|
if let Some(name) = kind.get_name() {
|
||||||
|
p!(write("{}", name));
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
|
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
|
||||||
| ty::ReLateParam(ty::LateParamRegion { bound_region: br, .. })
|
|
||||||
| ty::RePlaceholder(ty::Placeholder {
|
| ty::RePlaceholder(ty::Placeholder {
|
||||||
bound: ty::BoundRegion { kind: br, .. }, ..
|
bound: ty::BoundRegion { kind: br, .. }, ..
|
||||||
}) => {
|
}) => {
|
||||||
|
|
|
@ -69,9 +69,10 @@ impl<'tcx> Region<'tcx> {
|
||||||
pub fn new_late_param(
|
pub fn new_late_param(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
scope: DefId,
|
scope: DefId,
|
||||||
bound_region: ty::BoundRegionKind,
|
kind: LateParamRegionKind,
|
||||||
) -> Region<'tcx> {
|
) -> Region<'tcx> {
|
||||||
tcx.intern_region(ty::ReLateParam(ty::LateParamRegion { scope, bound_region }))
|
let data = LateParamRegion { scope, kind };
|
||||||
|
tcx.intern_region(ty::ReLateParam(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -124,8 +125,8 @@ impl<'tcx> Region<'tcx> {
|
||||||
match kind {
|
match kind {
|
||||||
ty::ReEarlyParam(region) => Region::new_early_param(tcx, region),
|
ty::ReEarlyParam(region) => Region::new_early_param(tcx, region),
|
||||||
ty::ReBound(debruijn, region) => Region::new_bound(tcx, debruijn, region),
|
ty::ReBound(debruijn, region) => Region::new_bound(tcx, debruijn, region),
|
||||||
ty::ReLateParam(ty::LateParamRegion { scope, bound_region }) => {
|
ty::ReLateParam(ty::LateParamRegion { scope, kind }) => {
|
||||||
Region::new_late_param(tcx, scope, bound_region)
|
Region::new_late_param(tcx, scope, kind)
|
||||||
}
|
}
|
||||||
ty::ReStatic => tcx.lifetimes.re_static,
|
ty::ReStatic => tcx.lifetimes.re_static,
|
||||||
ty::ReVar(vid) => Region::new_var(tcx, vid),
|
ty::ReVar(vid) => Region::new_var(tcx, vid),
|
||||||
|
@ -165,7 +166,7 @@ impl<'tcx> Region<'tcx> {
|
||||||
match *self {
|
match *self {
|
||||||
ty::ReEarlyParam(ebr) => Some(ebr.name),
|
ty::ReEarlyParam(ebr) => Some(ebr.name),
|
||||||
ty::ReBound(_, br) => br.kind.get_name(),
|
ty::ReBound(_, br) => br.kind.get_name(),
|
||||||
ty::ReLateParam(fr) => fr.bound_region.get_name(),
|
ty::ReLateParam(fr) => fr.kind.get_name(),
|
||||||
ty::ReStatic => Some(kw::StaticLifetime),
|
ty::ReStatic => Some(kw::StaticLifetime),
|
||||||
ty::RePlaceholder(placeholder) => placeholder.bound.kind.get_name(),
|
ty::RePlaceholder(placeholder) => placeholder.bound.kind.get_name(),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -187,7 +188,7 @@ impl<'tcx> Region<'tcx> {
|
||||||
match *self {
|
match *self {
|
||||||
ty::ReEarlyParam(ebr) => ebr.has_name(),
|
ty::ReEarlyParam(ebr) => ebr.has_name(),
|
||||||
ty::ReBound(_, br) => br.kind.is_named(),
|
ty::ReBound(_, br) => br.kind.is_named(),
|
||||||
ty::ReLateParam(fr) => fr.bound_region.is_named(),
|
ty::ReLateParam(fr) => fr.kind.is_named(),
|
||||||
ty::ReStatic => true,
|
ty::ReStatic => true,
|
||||||
ty::ReVar(..) => false,
|
ty::ReVar(..) => false,
|
||||||
ty::RePlaceholder(placeholder) => placeholder.bound.kind.is_named(),
|
ty::RePlaceholder(placeholder) => placeholder.bound.kind.is_named(),
|
||||||
|
@ -310,7 +311,7 @@ impl<'tcx> Region<'tcx> {
|
||||||
Some(tcx.generics_of(binding_item).region_param(ebr, tcx).def_id)
|
Some(tcx.generics_of(binding_item).region_param(ebr, tcx).def_id)
|
||||||
}
|
}
|
||||||
ty::ReLateParam(ty::LateParamRegion {
|
ty::ReLateParam(ty::LateParamRegion {
|
||||||
bound_region: ty::BoundRegionKind::Named(def_id, _),
|
kind: ty::LateParamRegionKind::Named(def_id, _),
|
||||||
..
|
..
|
||||||
}) => Some(def_id),
|
}) => Some(def_id),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -358,7 +359,71 @@ impl std::fmt::Debug for EarlyParamRegion {
|
||||||
/// different parameters apart.
|
/// different parameters apart.
|
||||||
pub struct LateParamRegion {
|
pub struct LateParamRegion {
|
||||||
pub scope: DefId,
|
pub scope: DefId,
|
||||||
pub bound_region: BoundRegionKind,
|
pub kind: LateParamRegionKind,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// When liberating bound regions, we map their [`BoundRegionKind`]
|
||||||
|
/// to this as we need to track the index of anonymous regions. We
|
||||||
|
/// otherwise end up liberating multiple bound regions to the same
|
||||||
|
/// late-bound region.
|
||||||
|
#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)]
|
||||||
|
#[derive(HashStable)]
|
||||||
|
pub enum LateParamRegionKind {
|
||||||
|
/// An anonymous region parameter for a given fn (&T)
|
||||||
|
///
|
||||||
|
/// Unlike [`BoundRegionKind::Anon`], this tracks the index of the
|
||||||
|
/// liberated bound region.
|
||||||
|
///
|
||||||
|
/// We should ideally never liberate anonymous regions, but do so for the
|
||||||
|
/// sake of diagnostics in `FnCtxt::sig_of_closure_with_expectation`.
|
||||||
|
Anon(u32),
|
||||||
|
|
||||||
|
/// Named region parameters for functions (a in &'a T)
|
||||||
|
///
|
||||||
|
/// The `DefId` is needed to distinguish free regions in
|
||||||
|
/// the event of shadowing.
|
||||||
|
Named(DefId, Symbol),
|
||||||
|
|
||||||
|
/// Anonymous region for the implicit env pointer parameter
|
||||||
|
/// to a closure
|
||||||
|
ClosureEnv,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LateParamRegionKind {
|
||||||
|
pub fn from_bound(var: BoundVar, br: BoundRegionKind) -> LateParamRegionKind {
|
||||||
|
match br {
|
||||||
|
BoundRegionKind::Anon => LateParamRegionKind::Anon(var.as_u32()),
|
||||||
|
BoundRegionKind::Named(def_id, name) => LateParamRegionKind::Named(def_id, name),
|
||||||
|
BoundRegionKind::ClosureEnv => LateParamRegionKind::ClosureEnv,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_named(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
LateParamRegionKind::Named(_, name) => {
|
||||||
|
name != kw::UnderscoreLifetime && name != kw::Empty
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_name(&self) -> Option<Symbol> {
|
||||||
|
if self.is_named() {
|
||||||
|
match *self {
|
||||||
|
LateParamRegionKind::Named(_, name) => return Some(name),
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_id(&self) -> Option<DefId> {
|
||||||
|
match *self {
|
||||||
|
LateParamRegionKind::Named(id, _) => Some(id),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)]
|
#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)]
|
||||||
|
|
|
@ -77,7 +77,23 @@ impl fmt::Debug for ty::BoundRegionKind {
|
||||||
|
|
||||||
impl fmt::Debug for ty::LateParamRegion {
|
impl fmt::Debug for ty::LateParamRegion {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "ReLateParam({:?}, {:?})", self.scope, self.bound_region)
|
write!(f, "ReLateParam({:?}, {:?})", self.scope, self.kind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for ty::LateParamRegionKind {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match *self {
|
||||||
|
ty::LateParamRegionKind::Anon(idx) => write!(f, "BrAnon({idx})"),
|
||||||
|
ty::LateParamRegionKind::Named(did, name) => {
|
||||||
|
if did.is_crate_root() {
|
||||||
|
write!(f, "BrNamed({name})")
|
||||||
|
} else {
|
||||||
|
write!(f, "BrNamed({did:?}, {name})")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ty::LateParamRegionKind::ClosureEnv => write!(f, "BrEnv"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,13 +54,13 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
let param = anon_param_info.param;
|
let param = anon_param_info.param;
|
||||||
let new_ty = anon_param_info.param_ty;
|
let new_ty = anon_param_info.param_ty;
|
||||||
let new_ty_span = anon_param_info.param_ty_span;
|
let new_ty_span = anon_param_info.param_ty_span;
|
||||||
let br = anon_param_info.br;
|
|
||||||
let is_first = anon_param_info.is_first;
|
let is_first = anon_param_info.is_first;
|
||||||
let scope_def_id = region_info.scope;
|
let scope_def_id = region_info.scope;
|
||||||
let is_impl_item = region_info.is_impl_item;
|
let is_impl_item = region_info.is_impl_item;
|
||||||
|
|
||||||
match br {
|
match anon_param_info.kind {
|
||||||
ty::BoundRegionKind::Named(_, kw::UnderscoreLifetime) | ty::BoundRegionKind::Anon => {}
|
ty::LateParamRegionKind::Named(_, kw::UnderscoreLifetime)
|
||||||
|
| ty::LateParamRegionKind::Anon(_) => {}
|
||||||
_ => {
|
_ => {
|
||||||
/* not an anonymous region */
|
/* not an anonymous region */
|
||||||
debug!("try_report_named_anon_conflict: not an anonymous region");
|
debug!("try_report_named_anon_conflict: not an anonymous region");
|
||||||
|
|
|
@ -17,8 +17,8 @@ pub struct AnonymousParamInfo<'tcx> {
|
||||||
pub param: &'tcx hir::Param<'tcx>,
|
pub param: &'tcx hir::Param<'tcx>,
|
||||||
/// The type corresponding to the anonymous region parameter.
|
/// The type corresponding to the anonymous region parameter.
|
||||||
pub param_ty: Ty<'tcx>,
|
pub param_ty: Ty<'tcx>,
|
||||||
/// The `ty::BoundRegionKind` corresponding to the anonymous region.
|
/// The `ty::LateParamRegionKind` corresponding to the anonymous region.
|
||||||
pub br: ty::BoundRegionKind,
|
pub kind: ty::LateParamRegionKind,
|
||||||
/// The `Span` of the parameter type.
|
/// The `Span` of the parameter type.
|
||||||
pub param_ty_span: Span,
|
pub param_ty_span: Span,
|
||||||
/// Signals that the argument is the first parameter in the declaration.
|
/// Signals that the argument is the first parameter in the declaration.
|
||||||
|
@ -43,11 +43,11 @@ pub fn find_param_with_region<'tcx>(
|
||||||
anon_region: Region<'tcx>,
|
anon_region: Region<'tcx>,
|
||||||
replace_region: Region<'tcx>,
|
replace_region: Region<'tcx>,
|
||||||
) -> Option<AnonymousParamInfo<'tcx>> {
|
) -> Option<AnonymousParamInfo<'tcx>> {
|
||||||
let (id, br) = match *anon_region {
|
let (id, kind) = match *anon_region {
|
||||||
ty::ReLateParam(late_param) => (late_param.scope, late_param.bound_region),
|
ty::ReLateParam(late_param) => (late_param.scope, late_param.kind),
|
||||||
ty::ReEarlyParam(ebr) => {
|
ty::ReEarlyParam(ebr) => {
|
||||||
let region_def = tcx.generics_of(generic_param_scope).region_param(ebr, tcx).def_id;
|
let region_def = tcx.generics_of(generic_param_scope).region_param(ebr, tcx).def_id;
|
||||||
(tcx.parent(region_def), ty::BoundRegionKind::Named(region_def, ebr.name))
|
(tcx.parent(region_def), ty::LateParamRegionKind::Named(region_def, ebr.name))
|
||||||
}
|
}
|
||||||
_ => return None, // not a free region
|
_ => return None, // not a free region
|
||||||
};
|
};
|
||||||
|
@ -96,7 +96,7 @@ pub fn find_param_with_region<'tcx>(
|
||||||
let ty_hir_id = fn_decl.inputs[index].hir_id;
|
let ty_hir_id = fn_decl.inputs[index].hir_id;
|
||||||
let param_ty_span = hir.span(ty_hir_id);
|
let param_ty_span = hir.span(ty_hir_id);
|
||||||
let is_first = index == 0;
|
let is_first = index == 0;
|
||||||
AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, br, is_first }
|
AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, kind, is_first }
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1095,13 +1095,13 @@ fn msg_span_from_named_region<'tcx>(
|
||||||
(text, Some(span))
|
(text, Some(span))
|
||||||
}
|
}
|
||||||
ty::ReLateParam(ref fr) => {
|
ty::ReLateParam(ref fr) => {
|
||||||
if !fr.bound_region.is_named()
|
if !fr.kind.is_named()
|
||||||
&& let Some((ty, _)) = find_anon_type(tcx, generic_param_scope, region)
|
&& let Some((ty, _)) = find_anon_type(tcx, generic_param_scope, region)
|
||||||
{
|
{
|
||||||
("the anonymous lifetime defined here".to_string(), Some(ty.span))
|
("the anonymous lifetime defined here".to_string(), Some(ty.span))
|
||||||
} else {
|
} else {
|
||||||
match fr.bound_region {
|
match fr.kind {
|
||||||
ty::BoundRegionKind::Named(param_def_id, name) => {
|
ty::LateParamRegionKind::Named(param_def_id, name) => {
|
||||||
let span = tcx.def_span(param_def_id);
|
let span = tcx.def_span(param_def_id);
|
||||||
let text = if name == kw::UnderscoreLifetime {
|
let text = if name == kw::UnderscoreLifetime {
|
||||||
"the anonymous lifetime as defined here".to_string()
|
"the anonymous lifetime as defined here".to_string()
|
||||||
|
@ -1110,7 +1110,7 @@ fn msg_span_from_named_region<'tcx>(
|
||||||
};
|
};
|
||||||
(text, Some(span))
|
(text, Some(span))
|
||||||
}
|
}
|
||||||
ty::BoundRegionKind::Anon => (
|
ty::LateParamRegionKind::Anon(_) => (
|
||||||
"the anonymous lifetime as defined here".to_string(),
|
"the anonymous lifetime as defined here".to_string(),
|
||||||
Some(tcx.def_span(generic_param_scope)),
|
Some(tcx.def_span(generic_param_scope)),
|
||||||
),
|
),
|
||||||
|
|
|
@ -39,14 +39,14 @@ impl<'a> DescriptionCtx<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::ReLateParam(ref fr) => {
|
ty::ReLateParam(ref fr) => {
|
||||||
if !fr.bound_region.is_named()
|
if !fr.kind.is_named()
|
||||||
&& let Some((ty, _)) = find_anon_type(tcx, generic_param_scope, region)
|
&& let Some((ty, _)) = find_anon_type(tcx, generic_param_scope, region)
|
||||||
{
|
{
|
||||||
(Some(ty.span), "defined_here", String::new())
|
(Some(ty.span), "defined_here", String::new())
|
||||||
} else {
|
} else {
|
||||||
let scope = fr.scope.expect_local();
|
let scope = fr.scope.expect_local();
|
||||||
match fr.bound_region {
|
match fr.kind {
|
||||||
ty::BoundRegionKind::Named(_, name) => {
|
ty::LateParamRegionKind::Named(_, name) => {
|
||||||
let span = if let Some(param) = tcx
|
let span = if let Some(param) = tcx
|
||||||
.hir()
|
.hir()
|
||||||
.get_generics(scope)
|
.get_generics(scope)
|
||||||
|
@ -62,7 +62,7 @@ impl<'a> DescriptionCtx<'a> {
|
||||||
(Some(span), "as_defined", name.to_string())
|
(Some(span), "as_defined", name.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::BoundRegionKind::Anon => {
|
ty::LateParamRegionKind::Anon(_) => {
|
||||||
let span = Some(tcx.def_span(scope));
|
let span = Some(tcx.def_span(scope));
|
||||||
(span, "defined_here", String::new())
|
(span, "defined_here", String::new())
|
||||||
}
|
}
|
||||||
|
|
|
@ -475,7 +475,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
|
||||||
.def_id,
|
.def_id,
|
||||||
),
|
),
|
||||||
ty::ReBound(_, r) => r.kind.get_id(),
|
ty::ReBound(_, r) => r.kind.get_id(),
|
||||||
ty::ReLateParam(r) => r.bound_region.get_id(),
|
ty::ReLateParam(r) => r.kind.get_id(),
|
||||||
ty::ReStatic
|
ty::ReStatic
|
||||||
| ty::ReVar(_)
|
| ty::ReVar(_)
|
||||||
| ty::RePlaceholder(_)
|
| ty::RePlaceholder(_)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue