Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6c01273

Browse files
committed
Plumb dyn trait representation through ty::Dynamic
1 parent eff35e5 commit 6c01273

File tree

29 files changed

+110
-57
lines changed

29 files changed

+110
-57
lines changed

compiler/rustc_codegen_ssa/src/meth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'a, 'tcx> VirtualIndex {
6969
fn expect_dyn_trait_in_self<'tcx>(ty: Ty<'tcx>) -> ty::PolyExistentialTraitRef<'tcx> {
7070
for arg in ty.peel_refs().walk() {
7171
if let GenericArgKind::Type(ty) = arg.unpack() {
72-
if let ty::Dynamic(data, _) = ty.kind() {
72+
if let ty::Dynamic(data, _, _) = ty.kind() {
7373
return data.principal().expect("expected principal trait object");
7474
}
7575
}

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
312312
let new_vptr = self.get_vtable_ptr(ty, data_b.principal())?;
313313
self.write_immediate(Immediate::new_dyn_trait(old_data, new_vptr, self), dest)
314314
}
315-
(_, &ty::Dynamic(ref data, _)) => {
315+
(_, &ty::Dynamic(ref data, _, _repr)) => {
316316
// Initial cast from sized to dyn trait
317317
let vtable = self.get_vtable_ptr(src_pointee_ty, data.principal())?;
318318
let ptr = self.read_scalar(src)?;

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
9595
| ty::Ref(_, _, _)
9696
| ty::FnDef(_, _)
9797
| ty::FnPtr(_)
98-
| ty::Dynamic(_, _)
98+
| ty::Dynamic(_, _, _)
9999
| ty::Closure(_, _)
100100
| ty::Generator(_, _, _)
101101
| ty::GeneratorWitness(_)

compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
4848
| ty::FnPtr(_)
4949
| ty::Never
5050
| ty::Tuple(_)
51-
| ty::Dynamic(_, _) => self.pretty_print_type(ty),
51+
| ty::Dynamic(_, _, _) => self.pretty_print_type(ty),
5252

5353
// Placeholders (all printed as `_` to uniformize them).
5454
ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => {

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ pub struct TraitObjectVisitor(pub FxHashSet<DefId>);
544544
impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor {
545545
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
546546
match t.kind() {
547-
ty::Dynamic(preds, re) if re.is_static() => {
547+
ty::Dynamic(preds, re, _) if re.is_static() => {
548548
if let Some(def_id) = preds.principal_def_id() {
549549
self.0.insert(def_id);
550550
}

compiler/rustc_lint/src/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
222222
}
223223
has_emitted
224224
}
225-
ty::Dynamic(binder, _) => {
225+
ty::Dynamic(binder, _, _) => {
226226
let mut has_emitted = false;
227227
for predicate in binder.iter() {
228228
if let ty::ExistentialPredicate::Trait(ref trait_ref) =

compiler/rustc_middle/src/ty/context.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ use rustc_span::{Span, DUMMY_SP};
6363
use rustc_target::abi::{Layout, LayoutS, TargetDataLayout, VariantIdx};
6464
use rustc_target::spec::abi;
6565
use rustc_type_ir::sty::TyKind::*;
66-
use rustc_type_ir::{InternAs, InternIteratorElement, Interner, TypeFlags};
66+
use rustc_type_ir::{
67+
InternAs, InternIteratorElement, Interner, TraitObjectRepresentation, TypeFlags,
68+
};
6769

6870
use std::any::Any;
6971
use std::borrow::Borrow;
@@ -2545,8 +2547,9 @@ impl<'tcx> TyCtxt<'tcx> {
25452547
self,
25462548
obj: &'tcx List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>>,
25472549
reg: ty::Region<'tcx>,
2550+
repr: TraitObjectRepresentation,
25482551
) -> Ty<'tcx> {
2549-
self.mk_ty(Dynamic(obj, reg))
2552+
self.mk_ty(Dynamic(obj, reg, repr))
25502553
}
25512554

25522555
#[inline]

compiler/rustc_middle/src/ty/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
467467
}
468468
}
469469

470-
Dynamic(dty, _) => {
470+
Dynamic(dty, _, _) => {
471471
for pred in *dty {
472472
match pred.skip_binder() {
473473
ExistentialPredicate::Trait(_) | ExistentialPredicate::Projection(_) => {

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl FlagComputation {
171171
self.add_substs(substs);
172172
}
173173

174-
&ty::Dynamic(obj, r) => {
174+
&ty::Dynamic(obj, r, _) => {
175175
for predicate in obj.iter() {
176176
self.bound_computation(predicate, |computation, predicate| match predicate {
177177
ty::ExistentialPredicate::Trait(tr) => computation.add_substs(tr.substs),

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,8 @@ where
24642464

24652465
match tcx.struct_tail_erasing_lifetimes(pointee, cx.param_env()).kind() {
24662466
ty::Slice(_) | ty::Str => TyMaybeWithLayout::Ty(tcx.types.usize),
2467-
ty::Dynamic(_, _) => {
2467+
// FIXME(eholk): Do the right thing with trait object representation
2468+
ty::Dynamic(_, _, _repr) => {
24682469
TyMaybeWithLayout::Ty(tcx.mk_imm_ref(
24692470
tcx.lifetimes.re_static,
24702471
tcx.mk_array(tcx.types.usize, 3),

0 commit comments

Comments
 (0)