1
Fork 0

Use the opaque_types_defined_by query to cheaply check for whether a hidden type may be registered for an opaque type

This commit is contained in:
Oli Scherer 2023-04-25 08:07:44 +00:00
parent 6ae803eedf
commit 4e92f761fe
17 changed files with 368 additions and 162 deletions

View file

@ -172,6 +172,10 @@ impl EraseType for ty::Binder<'_, ty::FnSig<'_>> {
type Result = [u8; size_of::<ty::Binder<'static, ty::FnSig<'static>>>()];
}
impl EraseType for ty::Binder<'_, &'_ ty::List<Ty<'_>>> {
type Result = [u8; size_of::<ty::Binder<'static, &'static ty::List<Ty<'static>>>>()];
}
impl<T0, T1> EraseType for (&'_ T0, &'_ T1) {
type Result = [u8; size_of::<(&'static (), &'static ())>()];
}

View file

@ -1265,7 +1265,7 @@ impl<'tcx> AliasTy<'tcx> {
/// Extracts the underlying trait reference and own substs from this projection.
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
/// then this function would return a `T: Iterator` trait reference and `['a]` as the own substs
/// then this function would return a `T: StreamingIterator` trait reference and `['a]` as the own substs
pub fn trait_ref_and_own_substs(
self,
tcx: TyCtxt<'tcx>,

View file

@ -36,7 +36,12 @@ pub struct Discr<'tcx> {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum CheckRegions {
No,
/// Only permit early bound regions. This is useful for Adts which
/// can never have late bound regions.
OnlyEarlyBound,
/// Permit both late bound and early bound regions. Use this for functions,
/// which frequently have late bound regions.
Bound,
}
#[derive(Copy, Clone, Debug)]
@ -471,15 +476,21 @@ impl<'tcx> TyCtxt<'tcx> {
ignore_regions: CheckRegions,
) -> Result<(), NotUniqueParam<'tcx>> {
let mut seen = GrowableBitSet::default();
let mut seen_late = FxHashSet::default();
for arg in substs {
match arg.unpack() {
GenericArgKind::Lifetime(lt) => match (ignore_regions, lt.kind()) {
(CheckRegions::OnlyEarlyBound, ty::ReEarlyBound(p)) => {
(CheckRegions::Bound, ty::ReLateBound(di, reg)) => {
if !seen_late.insert((di, reg)) {
return Err(NotUniqueParam::DuplicateParam(lt.into()));
}
}
(CheckRegions::OnlyEarlyBound | CheckRegions::Bound, ty::ReEarlyBound(p)) => {
if !seen.insert(p.index) {
return Err(NotUniqueParam::DuplicateParam(lt.into()));
}
}
(CheckRegions::OnlyEarlyBound, _) => {
(CheckRegions::OnlyEarlyBound | CheckRegions::Bound, _) => {
return Err(NotUniqueParam::NotParam(lt.into()));
}
(CheckRegions::No, _) => {}