Skip to content

Commit 540fd20

Browse files
authored
Rollup merge of #146664 - fmease:clean-up-dyn, r=jdonszelmann
Clean up `ty::Dynamic` 1. As a follow-up to PR #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 34a805b + 34062b1 commit 540fd20

File tree

75 files changed

+691
-786
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+691
-786
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
438438

439439
let elaborated_args =
440440
std::iter::zip(*args, &generics.own_params).map(|(arg, param)| {
441-
if let Some(ty::Dynamic(obj, _, ty::Dyn)) = arg.as_type().map(Ty::kind) {
441+
if let Some(ty::Dynamic(obj, _)) = arg.as_type().map(Ty::kind) {
442442
let default = tcx.object_lifetime_default(param.def_id);
443443

444444
let re_static = tcx.lifetimes.re_static;
@@ -464,7 +464,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
464464

465465
has_dyn = true;
466466

467-
Ty::new_dynamic(tcx, obj, implied_region, ty::Dyn).into()
467+
Ty::new_dynamic(tcx, obj, implied_region).into()
468468
} else {
469469
arg
470470
}

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
19031903
| ty::Slice(_)
19041904
| ty::FnDef(_, _)
19051905
| ty::FnPtr(..)
1906-
| ty::Dynamic(_, _, _)
1906+
| ty::Dynamic(_, _)
19071907
| ty::Closure(_, _)
19081908
| ty::CoroutineClosure(_, _)
19091909
| ty::Coroutine(_, _)
@@ -1949,7 +1949,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
19491949
| ty::Ref(_, _, _)
19501950
| ty::FnDef(_, _)
19511951
| ty::FnPtr(..)
1952-
| ty::Dynamic(_, _, _)
1952+
| ty::Dynamic(_, _)
19531953
| ty::CoroutineWitness(..)
19541954
| ty::Never
19551955
| ty::UnsafeBinder(_)

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,9 +1487,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
14871487
unsize_to: None,
14881488
},
14891489
);
1490-
} else if let ty::Dynamic(src_tty, _src_lt, ty::Dyn) =
1490+
} else if let ty::Dynamic(src_tty, _src_lt) =
14911491
*self.struct_tail(src.ty, location).kind()
1492-
&& let ty::Dynamic(dst_tty, dst_lt, ty::Dyn) =
1492+
&& let ty::Dynamic(dst_tty, dst_lt) =
14931493
*self.struct_tail(dst.ty, location).kind()
14941494
&& src_tty.principal().is_some()
14951495
&& dst_tty.principal().is_some()
@@ -1511,15 +1511,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
15111511
// FIXME: Once we disallow casting `*const dyn Trait + 'short`
15121512
// to `*const dyn Trait + 'long`, then this can just be `src_lt`.
15131513
dst_lt,
1514-
ty::Dyn,
15151514
);
15161515
let dst_obj = Ty::new_dynamic(
15171516
tcx,
15181517
tcx.mk_poly_existential_predicates(
15191518
&dst_tty.without_auto_traits().collect::<Vec<_>>(),
15201519
),
15211520
dst_lt,
1522-
ty::Dyn,
15231521
);
15241522

15251523
debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ pub(crate) fn codegen_drop<'tcx>(
715715
fx.bcx.ins().jump(ret_block, &[]);
716716
} else {
717717
match ty.kind() {
718-
ty::Dynamic(_, _, ty::Dyn) => {
718+
ty::Dynamic(_, _) => {
719719
// IN THIS ARM, WE HAVE:
720720
// ty = *mut (dyn Trait)
721721
// which is: exists<T> ( *mut T, Vtable<T: Trait> )

compiler/rustc_codegen_cranelift/src/unsize.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ pub(crate) fn unsized_info<'tcx>(
3030
fx.pointer_type,
3131
len.try_to_target_usize(fx.tcx).expect("expected monomorphic const in codegen") as i64,
3232
),
33-
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
34-
if src_dyn_kind == target_dyn_kind =>
35-
{
33+
(&ty::Dynamic(data_a, _), &ty::Dynamic(data_b, _)) => {
3634
let old_info =
3735
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
3836
let b_principal_def_id = data_b.principal_def_id();

compiler/rustc_codegen_cranelift/src/value_and_place.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,7 @@ pub(crate) fn assert_assignable<'tcx>(
909909
);
910910
// fn(&T) -> for<'l> fn(&'l T) is allowed
911911
}
912-
(&ty::Dynamic(from_traits, _, _from_kind), &ty::Dynamic(to_traits, _, _to_kind)) => {
913-
// FIXME(dyn-star): Do the right thing with DynKinds
912+
(&ty::Dynamic(from_traits, _), &ty::Dynamic(to_traits, _)) => {
914913
for (from, to) in from_traits.iter().zip(to_traits) {
915914
let from = fx.tcx.normalize_erasing_late_bound_regions(fx.typing_env(), from);
916915
let to = fx.tcx.normalize_erasing_late_bound_regions(fx.typing_env(), to);

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
168168
(&ty::Array(_, len), &ty::Slice(_)) => cx.const_usize(
169169
len.try_to_target_usize(cx.tcx()).expect("expected monomorphic const in codegen"),
170170
),
171-
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
172-
if src_dyn_kind == target_dyn_kind =>
173-
{
171+
(&ty::Dynamic(data_a, _), &ty::Dynamic(data_b, _)) => {
174172
let old_info =
175173
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
176174
let b_principal_def_id = data_b.principal_def_id();
@@ -208,7 +206,7 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
208206
old_info
209207
}
210208
}
211-
(_, ty::Dynamic(data, _, _)) => meth::get_vtable(
209+
(_, ty::Dynamic(data, _)) => meth::get_vtable(
212210
cx,
213211
source,
214212
data.principal()

compiler/rustc_codegen_ssa/src/meth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn dyn_trait_in_self<'tcx>(
7878
) -> Option<ty::ExistentialTraitRef<'tcx>> {
7979
for arg in ty.peel_refs().walk() {
8080
if let GenericArgKind::Type(ty) = arg.kind()
81-
&& let ty::Dynamic(data, _, _) = ty.kind()
81+
&& let ty::Dynamic(data, _) = ty.kind()
8282
{
8383
// FIXME(arbitrary_self_types): This is likely broken for receivers which
8484
// have a "non-self" trait objects as a generic argument.

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
614614
let (maybe_null, drop_fn, fn_abi, drop_instance) = match ty.kind() {
615615
// FIXME(eddyb) perhaps move some of this logic into
616616
// `Instance::resolve_drop_in_place`?
617-
ty::Dynamic(_, _, ty::Dyn) => {
617+
ty::Dynamic(_, _) => {
618618
// IN THIS ARM, WE HAVE:
619619
// ty = *mut (dyn Trait)
620620
// which is: exists<T> ( *mut T, Vtable<T: Trait> )

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
658658
let val = self.read_immediate(&receiver)?;
659659
break self.ref_to_mplace(&val)?;
660660
}
661-
ty::Dynamic(.., ty::Dyn) => break receiver.assert_mem_place(), // no immediate unsized values
661+
ty::Dynamic(..) => break receiver.assert_mem_place(), // no immediate unsized values
662662
_ => {
663663
// Not there yet, search for the only non-ZST field.
664664
// (The rules for `DispatchFromDyn` ensure there's exactly one such field.)
@@ -675,7 +675,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
675675
// (For that reason we also cannot use `unpack_dyn_trait`.)
676676
let receiver_tail =
677677
self.tcx.struct_tail_for_codegen(receiver_place.layout.ty, self.typing_env);
678-
let ty::Dynamic(receiver_trait, _, ty::Dyn) = receiver_tail.kind() else {
678+
let ty::Dynamic(receiver_trait, _) = receiver_tail.kind() else {
679679
span_bug!(self.cur_span(), "dynamic call on non-`dyn` type {}", receiver_tail)
680680
};
681681
assert!(receiver_place.layout.is_unsized());
@@ -822,7 +822,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
822822
// instead we do the virtual call stuff ourselves. It's easier here than in `eval_fn_call`
823823
// since we can just get a place of the underlying type and use `mplace_to_ref`.
824824
let place = match place.layout.ty.kind() {
825-
ty::Dynamic(data, _, ty::Dyn) => {
825+
ty::Dynamic(data, _) => {
826826
// Dropping a trait object. Need to find actual drop fn.
827827
self.unpack_dyn_trait(&place, data)?
828828
}

0 commit comments

Comments
 (0)