Remove DynKind

This commit is contained in:
León Orell Valerian Liehr
2025-09-17 04:16:47 +02:00
parent a015919e54
commit 26f3337d4e
74 changed files with 142 additions and 237 deletions

View File

@@ -399,7 +399,7 @@ pub struct TraitObjectVisitor(pub FxIndexSet<DefId>);
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for TraitObjectVisitor {
fn visit_ty(&mut self, t: Ty<'tcx>) {
match t.kind() {
ty::Dynamic(preds, re, _) if re.is_static() => {
ty::Dynamic(preds, re) if re.is_static() => {
if let Some(def_id) = preds.principal_def_id() {
self.0.insert(def_id);
}

View File

@@ -292,7 +292,7 @@ impl<T> Trait<T> for X {
);
}
}
(ty::Dynamic(t, _, ty::DynKind::Dyn), ty::Alias(ty::Opaque, alias))
(ty::Dynamic(t, _), ty::Alias(ty::Opaque, alias))
if let Some(def_id) = t.principal_def_id()
&& tcx
.explicit_item_self_bounds(alias.def_id)
@@ -314,9 +314,7 @@ impl<T> Trait<T> for X {
values.found, values.expected,
));
}
(ty::Dynamic(t, _, ty::DynKind::Dyn), _)
if let Some(def_id) = t.principal_def_id() =>
{
(ty::Dynamic(t, _), _) if let Some(def_id) = t.principal_def_id() => {
let mut has_matching_impl = false;
tcx.for_each_relevant_impl(def_id, values.found, |did| {
if DeepRejectCtxt::relate_rigid_infer(tcx)
@@ -335,9 +333,7 @@ impl<T> Trait<T> for X {
));
}
}
(_, ty::Dynamic(t, _, ty::DynKind::Dyn))
if let Some(def_id) = t.principal_def_id() =>
{
(_, ty::Dynamic(t, _)) if let Some(def_id) = t.principal_def_id() => {
let mut has_matching_impl = false;
tcx.for_each_relevant_impl(def_id, values.expected, |did| {
if DeepRejectCtxt::relate_rigid_infer(tcx)
@@ -489,7 +485,7 @@ impl<T> Trait<T> for X {
&& let Some(then) = blk.expr
&& def.is_box()
&& let boxed_ty = args.type_at(0)
&& let ty::Dynamic(t, _, _) = boxed_ty.kind()
&& let ty::Dynamic(t, _) = boxed_ty.kind()
&& let Some(def_id) = t.principal_def_id()
&& let mut impl_def_ids = vec![]
&& let _ =

View File

@@ -430,7 +430,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let mut alt_span = None;
if let Some(ty) = ty
&& sub.is_static()
&& let ty::Dynamic(preds, _, ty::DynKind::Dyn) = ty.kind()
&& let ty::Dynamic(preds, _) = ty.kind()
&& let Some(def_id) = preds.principal_def_id()
{
for (clause, span) in

View File

@@ -554,7 +554,7 @@ fn attempt_dyn_to_enum_suggestion(
// defaults to assuming that things are *not* sized, whereas we want to
// fall back to assuming that things may be sized.
match impl_type.kind() {
ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::DynKind::Dyn) => {
ty::Str | ty::Slice(_) | ty::Dynamic(_, _) => {
return None;
}
_ => {}

View File

@@ -237,7 +237,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
}
}
if let ty::Dynamic(traits, _, _) = self_ty.kind() {
if let ty::Dynamic(traits, _) = self_ty.kind() {
for t in traits.iter() {
if let ty::ExistentialPredicate::Trait(trait_ref) = t.skip_binder() {
self_types.push(self.tcx.def_path_str(trait_ref.def_id));

View File

@@ -1131,7 +1131,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
},
)
}
ty::Dynamic(data, _, ty::Dyn) => data.iter().find_map(|pred| {
ty::Dynamic(data, _) => data.iter().find_map(|pred| {
if let ty::ExistentialPredicate::Projection(proj) = pred.skip_binder()
&& self.tcx.is_lang_item(proj.def_id, LangItem::FnOnceOutput)
// for existential projection, args are shifted over by 1
@@ -1520,7 +1520,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let ty::Ref(_, object_ty, hir::Mutability::Not) = target_ty.kind() else {
return;
};
let ty::Dynamic(predicates, _, ty::Dyn) = object_ty.kind() else {
let ty::Dynamic(predicates, _) = object_ty.kind() else {
return;
};
let self_ref_ty = Ty::new_imm_ref(self.tcx, self.tcx.lifetimes.re_erased, self_ty);
@@ -1883,7 +1883,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let ObligationCauseCode::SizedReturnType = obligation.cause.code() else {
return false;
};
let ty::Dynamic(_, _, ty::Dyn) = trait_pred.self_ty().skip_binder().kind() else {
let ty::Dynamic(_, _) = trait_pred.self_ty().skip_binder().kind() else {
return false;
};

View File

@@ -669,7 +669,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// These may potentially implement `FnPtr`
ty::Placeholder(..)
| ty::Dynamic(_, _, _)
| ty::Dynamic(_, _)
| ty::Alias(_, _)
| ty::Infer(_)
| ty::Param(..)
@@ -991,7 +991,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
match (source.kind(), target.kind()) {
// Trait+Kx+'a -> Trait+Ky+'b (upcasts).
(&ty::Dynamic(a_data, a_region, ty::Dyn), &ty::Dynamic(b_data, b_region, ty::Dyn)) => {
(&ty::Dynamic(a_data, a_region), &ty::Dynamic(b_data, b_region)) => {
// Upcast coercions permit several things:
//
// 1. Dropping auto traits, e.g., `Foo + Send` to `Foo`
@@ -1054,7 +1054,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
// `T` -> `Trait`
(_, &ty::Dynamic(_, _, ty::Dyn)) => {
(_, &ty::Dynamic(_, _)) => {
candidates.vec.push(BuiltinUnsizeCandidate);
}
@@ -1327,7 +1327,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Pat(_, _)
| ty::FnPtr(..)
| ty::UnsafeBinder(_)
| ty::Dynamic(_, _, _)
| ty::Dynamic(_, _)
| ty::Closure(..)
| ty::CoroutineClosure(..)
| ty::Coroutine(_, _)

View File

@@ -1023,10 +1023,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let a_ty = self.infcx.shallow_resolve(predicate.self_ty());
let b_ty = self.infcx.shallow_resolve(predicate.trait_ref.args.type_at(1));
let ty::Dynamic(a_data, a_region, ty::Dyn) = *a_ty.kind() else {
let ty::Dynamic(a_data, a_region) = *a_ty.kind() else {
bug!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`")
};
let ty::Dynamic(b_data, b_region, ty::Dyn) = *b_ty.kind() else {
let ty::Dynamic(b_data, b_region) = *b_ty.kind() else {
bug!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`")
};
@@ -1062,10 +1062,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?source, ?target, "confirm_builtin_unsize_candidate");
Ok(match (source.kind(), target.kind()) {
// Trait+Kx+'a -> Trait+Ky+'b (auto traits and lifetime subtyping).
(&ty::Dynamic(data_a, r_a, dyn_a), &ty::Dynamic(data_b, r_b, dyn_b))
if dyn_a == dyn_b =>
{
// `dyn Trait + Kx + 'a` -> `dyn Trait + Ky + 'b` (auto traits and lifetime subtyping).
(&ty::Dynamic(data_a, r_a), &ty::Dynamic(data_b, r_b)) => {
// See `assemble_candidates_for_unsizing` for more info.
// We already checked the compatibility of auto traits within `assemble_candidates_for_unsizing`.
let existential_predicates = if data_b.principal().is_some() {
@@ -1098,7 +1096,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.map(ty::Binder::dummy),
)
};
let source_trait = Ty::new_dynamic(tcx, existential_predicates, r_b, dyn_a);
let source_trait = Ty::new_dynamic(tcx, existential_predicates, r_b);
// Require that the traits involved in this upcast are **equal**;
// only the **lifetime bound** is changed.
@@ -1122,7 +1120,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
// `T` -> `dyn Trait`
(_, &ty::Dynamic(data, r, ty::Dyn)) => {
(_, &ty::Dynamic(data, r)) => {
let mut object_dids = data.auto_traits().chain(data.principal_def_id());
if let Some(did) = object_dids.find(|did| !tcx.is_dyn_compatible(*did)) {
return Err(SelectionError::TraitDynIncompatible(did));

View File

@@ -317,7 +317,7 @@ pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRe
"vtable trait ref should be normalized"
);
let ty::Dynamic(source, _, _) = *key.self_ty().kind() else {
let ty::Dynamic(source, _) = *key.self_ty().kind() else {
bug!();
};
let source_principal = tcx.instantiate_bound_regions_with_erased(
@@ -384,13 +384,13 @@ pub(crate) fn supertrait_vtable_slot<'tcx>(
let (source, target) = key;
// If the target principal is `None`, we can just return `None`.
let ty::Dynamic(target_data, _, _) = *target.kind() else {
let ty::Dynamic(target_data, _) = *target.kind() else {
bug!();
};
let target_principal = tcx.instantiate_bound_regions_with_erased(target_data.principal()?);
// Given that we have a target principal, it is a bug for there not to be a source principal.
let ty::Dynamic(source_data, _, _) = *source.kind() else {
let ty::Dynamic(source_data, _) = *source.kind() else {
bug!();
};
let source_principal = tcx.instantiate_bound_regions_with_erased(

View File

@@ -915,7 +915,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
// We recurse into the binder below.
}
ty::Dynamic(data, r, _) => {
ty::Dynamic(data, r) => {
// WfObject
//
// Here, we defer WF checking due to higher-ranked