Remove DefId
from EarlyParamRegion
(tedium/diagnostics)
This commit is contained in:
parent
bd6344d829
commit
fe2d7794ca
27 changed files with 266 additions and 157 deletions
|
@ -1488,13 +1488,14 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
|
||||
/// Returns the `DefId` and the `BoundRegionKind` corresponding to the given region.
|
||||
pub fn is_suitable_region(self, mut region: Region<'tcx>) -> Option<FreeRegionInfo> {
|
||||
pub fn is_suitable_region(
|
||||
self,
|
||||
generic_param_scope: LocalDefId,
|
||||
mut region: Region<'tcx>,
|
||||
) -> Option<FreeRegionInfo> {
|
||||
let (suitable_region_binding_scope, bound_region) = loop {
|
||||
let def_id = match region.kind() {
|
||||
ty::ReLateParam(fr) => fr.bound_region.get_id()?.as_local()?,
|
||||
ty::ReEarlyParam(ebr) => ebr.def_id.as_local()?,
|
||||
_ => return None, // not a free region
|
||||
};
|
||||
let def_id =
|
||||
region.opt_param_def_id(self, generic_param_scope.to_def_id())?.as_local()?;
|
||||
let scope = self.local_parent(def_id);
|
||||
if self.def_kind(scope) == DefKind::OpaqueTy {
|
||||
// Lifetime params of opaque types are synthetic and thus irrelevant to
|
||||
|
@ -2633,7 +2634,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
return ty::Region::new_early_param(
|
||||
self,
|
||||
ty::EarlyParamRegion {
|
||||
def_id: ebv,
|
||||
index: generics
|
||||
.param_def_id_to_index(self, ebv)
|
||||
.expect("early-bound var should be present in fn generics"),
|
||||
|
|
|
@ -66,7 +66,7 @@ pub struct GenericParamDef {
|
|||
impl GenericParamDef {
|
||||
pub fn to_early_bound_region_data(&self) -> ty::EarlyParamRegion {
|
||||
if let GenericParamDefKind::Lifetime = self.kind {
|
||||
ty::EarlyParamRegion { def_id: self.def_id, index: self.index, name: self.name }
|
||||
ty::EarlyParamRegion { index: self.index, name: self.name }
|
||||
} else {
|
||||
bug!("cannot convert a non-lifetime parameter def to an early bound region")
|
||||
}
|
||||
|
|
|
@ -265,33 +265,6 @@ impl<'tcx> Region<'tcx> {
|
|||
flags
|
||||
}
|
||||
|
||||
/// Given an early-bound or free region, returns the `DefId` where it was bound.
|
||||
/// For example, consider the regions in this snippet of code:
|
||||
///
|
||||
/// ```ignore (illustrative)
|
||||
/// impl<'a> Foo {
|
||||
/// // ^^ -- early bound, declared on an impl
|
||||
///
|
||||
/// fn bar<'b, 'c>(x: &self, y: &'b u32, z: &'c u64) where 'static: 'c
|
||||
/// // ^^ ^^ ^ anonymous, late-bound
|
||||
/// // | early-bound, appears in where-clauses
|
||||
/// // late-bound, appears only in fn args
|
||||
/// {..}
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Here, `free_region_binding_scope('a)` would return the `DefId`
|
||||
/// of the impl, and for all the other highlighted regions, it
|
||||
/// would return the `DefId` of the function. In other cases (not shown), this
|
||||
/// function might return the `DefId` of a closure.
|
||||
pub fn free_region_binding_scope(self, tcx: TyCtxt<'_>) -> DefId {
|
||||
match *self {
|
||||
ty::ReEarlyParam(br) => tcx.parent(br.def_id),
|
||||
ty::ReLateParam(fr) => fr.scope,
|
||||
_ => bug!("free_region_binding_scope invoked on inappropriate region: {:?}", self),
|
||||
}
|
||||
}
|
||||
|
||||
/// True for free regions other than `'static`.
|
||||
pub fn is_param(self) -> bool {
|
||||
matches!(*self, ty::ReEarlyParam(_) | ty::ReLateParam(_))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue