Skip to content

Commit 10f56f9

Browse files
authored
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
2 parents ad9725f + ed3c8a7 commit 10f56f9

File tree

4 files changed

+13
-46
lines changed

4 files changed

+13
-46
lines changed

rustc_public/src/ty.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl TyKind {
333333

334334
#[inline]
335335
pub fn is_trait(&self) -> bool {
336-
matches!(self, TyKind::RigidTy(RigidTy::Dynamic(_, _, DynKind::Dyn)))
336+
matches!(self, TyKind::RigidTy(RigidTy::Dynamic(_, _)))
337337
}
338338

339339
#[inline]
@@ -472,7 +472,7 @@ impl TyKind {
472472
}
473473

474474
pub fn trait_principal(&self) -> Option<Binder<ExistentialTraitRef>> {
475-
if let TyKind::RigidTy(RigidTy::Dynamic(predicates, _, _)) = self {
475+
if let TyKind::RigidTy(RigidTy::Dynamic(predicates, _)) = self {
476476
if let Some(Binder { value: ExistentialPredicate::Trait(trait_ref), bound_vars }) =
477477
predicates.first()
478478
{
@@ -562,7 +562,7 @@ pub enum RigidTy {
562562
Closure(ClosureDef, GenericArgs),
563563
Coroutine(CoroutineDef, GenericArgs),
564564
CoroutineClosure(CoroutineClosureDef, GenericArgs),
565-
Dynamic(Vec<Binder<ExistentialPredicate>>, Region, DynKind),
565+
Dynamic(Vec<Binder<ExistentialPredicate>>, Region),
566566
Never,
567567
Tuple(Vec<Ty>),
568568
CoroutineWitness(CoroutineWitnessDef, GenericArgs),
@@ -1206,11 +1206,6 @@ pub enum BoundRegionKind {
12061206
BrEnv,
12071207
}
12081208

1209-
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
1210-
pub enum DynKind {
1211-
Dyn,
1212-
}
1213-
12141209
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
12151210
pub enum ExistentialPredicate {
12161211
Trait(ExistentialTraitRef),

rustc_public/src/unstable/convert/internal.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::mir::alloc::AllocId;
1414
use crate::mir::mono::{Instance, MonoItem, StaticDef};
1515
use crate::mir::{BinOp, Mutability, Place, ProjectionElem, RawPtrKind, Safety, UnOp};
1616
use crate::ty::{
17-
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, DynKind,
17+
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind,
1818
ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FloatTy, FnSig,
1919
GenericArgKind, GenericArgs, IntTy, MirConst, Movability, Pattern, Region, RigidTy, Span,
2020
TermKind, TraitRef, Ty, TyConst, UintTy, VariantDef, VariantIdx,
@@ -188,10 +188,9 @@ impl RustcInternal for RigidTy {
188188
def.0.internal(tables, tcx),
189189
args.internal(tables, tcx),
190190
),
191-
RigidTy::Dynamic(predicate, region, dyn_kind) => rustc_ty::TyKind::Dynamic(
191+
RigidTy::Dynamic(predicate, region) => rustc_ty::TyKind::Dynamic(
192192
tcx.mk_poly_existential_predicates(&predicate.internal(tables, tcx)),
193193
region.internal(tables, tcx),
194-
dyn_kind.internal(tables, tcx),
195194
),
196195
RigidTy::Tuple(tys) => {
197196
rustc_ty::TyKind::Tuple(tcx.mk_type_list(&tys.internal(tables, tcx)))
@@ -460,20 +459,6 @@ impl RustcInternal for BoundVariableKind {
460459
}
461460
}
462461

463-
impl RustcInternal for DynKind {
464-
type T<'tcx> = rustc_ty::DynKind;
465-
466-
fn internal<'tcx>(
467-
&self,
468-
_tables: &mut Tables<'_, BridgeTys>,
469-
_tcx: impl InternalCx<'tcx>,
470-
) -> Self::T<'tcx> {
471-
match self {
472-
DynKind::Dyn => rustc_ty::DynKind::Dyn,
473-
}
474-
}
475-
}
476-
477462
impl RustcInternal for ExistentialPredicate {
478463
type T<'tcx> = rustc_ty::ExistentialPredicate<'tcx>;
479464

rustc_public/src/unstable/convert/stable/ty.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ impl<'tcx> Stable<'tcx> for ty::AliasTerm<'tcx> {
4848
}
4949
}
5050

51-
impl<'tcx> Stable<'tcx> for ty::DynKind {
52-
type T = crate::ty::DynKind;
53-
54-
fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
55-
match self {
56-
ty::Dyn => crate::ty::DynKind::Dyn,
57-
}
58-
}
59-
}
60-
6151
impl<'tcx> Stable<'tcx> for ty::ExistentialPredicate<'tcx> {
6252
type T = crate::ty::ExistentialPredicate;
6353

@@ -439,16 +429,13 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
439429
}
440430
// FIXME(unsafe_binders):
441431
ty::UnsafeBinder(_) => todo!(),
442-
ty::Dynamic(existential_predicates, region, dyn_kind) => {
443-
TyKind::RigidTy(RigidTy::Dynamic(
444-
existential_predicates
445-
.iter()
446-
.map(|existential_predicate| existential_predicate.stable(tables, cx))
447-
.collect(),
448-
region.stable(tables, cx),
449-
dyn_kind.stable(tables, cx),
450-
))
451-
}
432+
ty::Dynamic(existential_predicates, region) => TyKind::RigidTy(RigidTy::Dynamic(
433+
existential_predicates
434+
.iter()
435+
.map(|existential_predicate| existential_predicate.stable(tables, cx))
436+
.collect(),
437+
region.stable(tables, cx),
438+
)),
452439
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
453440
tables.closure_def(*def_id),
454441
generic_args.stable(tables, cx),

rustc_public/src/visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl Visitable for RigidTy {
171171
| RigidTy::CoroutineClosure(_, args)
172172
| RigidTy::FnDef(_, args) => args.visit(visitor),
173173
RigidTy::FnPtr(sig) => sig.visit(visitor),
174-
RigidTy::Dynamic(pred, r, _) => {
174+
RigidTy::Dynamic(pred, r) => {
175175
pred.visit(visitor)?;
176176
r.visit(visitor)
177177
}

0 commit comments

Comments
 (0)