Rollup merge of #146664 - fmease:clean-up-dyn, r=jdonszelmann
Clean up `ty::Dynamic` 1. As a follow-up to PR rust-lang/rust#143036, remove `DynKind` entirely. 2. Inside HIR ty lowering, consolidate modules `dyn_compatibility` and `lint` into `dyn_trait` * `dyn_compatibility` wasn't about dyn compatibility itself, it's about lowering trait object types * `lint` contained dyn-Trait-specific diagnostics+lints only
This commit is contained in:
commit
540fd20ba6
75 changed files with 691 additions and 786 deletions
|
|
@ -333,7 +333,7 @@ impl TyKind {
|
|||
|
||||
#[inline]
|
||||
pub fn is_trait(&self) -> bool {
|
||||
matches!(self, TyKind::RigidTy(RigidTy::Dynamic(_, _, DynKind::Dyn)))
|
||||
matches!(self, TyKind::RigidTy(RigidTy::Dynamic(_, _)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -472,7 +472,7 @@ impl TyKind {
|
|||
}
|
||||
|
||||
pub fn trait_principal(&self) -> Option<Binder<ExistentialTraitRef>> {
|
||||
if let TyKind::RigidTy(RigidTy::Dynamic(predicates, _, _)) = self {
|
||||
if let TyKind::RigidTy(RigidTy::Dynamic(predicates, _)) = self {
|
||||
if let Some(Binder { value: ExistentialPredicate::Trait(trait_ref), bound_vars }) =
|
||||
predicates.first()
|
||||
{
|
||||
|
|
@ -562,7 +562,7 @@ pub enum RigidTy {
|
|||
Closure(ClosureDef, GenericArgs),
|
||||
Coroutine(CoroutineDef, GenericArgs),
|
||||
CoroutineClosure(CoroutineClosureDef, GenericArgs),
|
||||
Dynamic(Vec<Binder<ExistentialPredicate>>, Region, DynKind),
|
||||
Dynamic(Vec<Binder<ExistentialPredicate>>, Region),
|
||||
Never,
|
||||
Tuple(Vec<Ty>),
|
||||
CoroutineWitness(CoroutineWitnessDef, GenericArgs),
|
||||
|
|
@ -1206,11 +1206,6 @@ pub enum BoundRegionKind {
|
|||
BrEnv,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
|
||||
pub enum DynKind {
|
||||
Dyn,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
|
||||
pub enum ExistentialPredicate {
|
||||
Trait(ExistentialTraitRef),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use crate::mir::alloc::AllocId;
|
|||
use crate::mir::mono::{Instance, MonoItem, StaticDef};
|
||||
use crate::mir::{BinOp, Mutability, Place, ProjectionElem, RawPtrKind, Safety, UnOp};
|
||||
use crate::ty::{
|
||||
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, DynKind,
|
||||
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind,
|
||||
ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FloatTy, FnSig,
|
||||
GenericArgKind, GenericArgs, IntTy, MirConst, Movability, Pattern, Region, RigidTy, Span,
|
||||
TermKind, TraitRef, Ty, TyConst, UintTy, VariantDef, VariantIdx,
|
||||
|
|
@ -188,10 +188,9 @@ impl RustcInternal for RigidTy {
|
|||
def.0.internal(tables, tcx),
|
||||
args.internal(tables, tcx),
|
||||
),
|
||||
RigidTy::Dynamic(predicate, region, dyn_kind) => rustc_ty::TyKind::Dynamic(
|
||||
RigidTy::Dynamic(predicate, region) => rustc_ty::TyKind::Dynamic(
|
||||
tcx.mk_poly_existential_predicates(&predicate.internal(tables, tcx)),
|
||||
region.internal(tables, tcx),
|
||||
dyn_kind.internal(tables, tcx),
|
||||
),
|
||||
RigidTy::Tuple(tys) => {
|
||||
rustc_ty::TyKind::Tuple(tcx.mk_type_list(&tys.internal(tables, tcx)))
|
||||
|
|
@ -460,20 +459,6 @@ impl RustcInternal for BoundVariableKind {
|
|||
}
|
||||
}
|
||||
|
||||
impl RustcInternal for DynKind {
|
||||
type T<'tcx> = rustc_ty::DynKind;
|
||||
|
||||
fn internal<'tcx>(
|
||||
&self,
|
||||
_tables: &mut Tables<'_, BridgeTys>,
|
||||
_tcx: impl InternalCx<'tcx>,
|
||||
) -> Self::T<'tcx> {
|
||||
match self {
|
||||
DynKind::Dyn => rustc_ty::DynKind::Dyn,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RustcInternal for ExistentialPredicate {
|
||||
type T<'tcx> = rustc_ty::ExistentialPredicate<'tcx>;
|
||||
|
||||
|
|
|
|||
|
|
@ -48,16 +48,6 @@ impl<'tcx> Stable<'tcx> for ty::AliasTerm<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::DynKind {
|
||||
type T = crate::ty::DynKind;
|
||||
|
||||
fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
|
||||
match self {
|
||||
ty::Dyn => crate::ty::DynKind::Dyn,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for ty::ExistentialPredicate<'tcx> {
|
||||
type T = crate::ty::ExistentialPredicate;
|
||||
|
||||
|
|
@ -439,16 +429,13 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
|
|||
}
|
||||
// FIXME(unsafe_binders):
|
||||
ty::UnsafeBinder(_) => todo!(),
|
||||
ty::Dynamic(existential_predicates, region, dyn_kind) => {
|
||||
TyKind::RigidTy(RigidTy::Dynamic(
|
||||
existential_predicates
|
||||
.iter()
|
||||
.map(|existential_predicate| existential_predicate.stable(tables, cx))
|
||||
.collect(),
|
||||
region.stable(tables, cx),
|
||||
dyn_kind.stable(tables, cx),
|
||||
))
|
||||
}
|
||||
ty::Dynamic(existential_predicates, region) => TyKind::RigidTy(RigidTy::Dynamic(
|
||||
existential_predicates
|
||||
.iter()
|
||||
.map(|existential_predicate| existential_predicate.stable(tables, cx))
|
||||
.collect(),
|
||||
region.stable(tables, cx),
|
||||
)),
|
||||
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
|
||||
tables.closure_def(*def_id),
|
||||
generic_args.stable(tables, cx),
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ impl Visitable for RigidTy {
|
|||
| RigidTy::CoroutineClosure(_, args)
|
||||
| RigidTy::FnDef(_, args) => args.visit(visitor),
|
||||
RigidTy::FnPtr(sig) => sig.visit(visitor),
|
||||
RigidTy::Dynamic(pred, r, _) => {
|
||||
RigidTy::Dynamic(pred, r) => {
|
||||
pred.visit(visitor)?;
|
||||
r.visit(visitor)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue