Skip to content

Commit 735e9bb

Browse files
committed
Include assoc const projections in CFI trait object
1 parent 878374e commit 735e9bb

2 files changed

Lines changed: 50 additions & 11 deletions

File tree

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,24 +243,24 @@ fn trait_object_ty<'tcx>(tcx: TyCtxt<'tcx>, poly_trait_ref: ty::PolyTraitRef<'tc
243243
.flat_map(|super_poly_trait_ref| {
244244
tcx.associated_items(super_poly_trait_ref.def_id())
245245
.in_definition_order()
246-
.filter(|item| item.is_type())
246+
.filter(|item| item.is_type() || item.is_const())
247247
.filter(|item| !tcx.generics_require_sized_self(item.def_id))
248-
.map(move |assoc_ty| {
248+
.map(move |assoc_item| {
249249
super_poly_trait_ref.map_bound(|super_trait_ref| {
250-
let alias_ty =
251-
ty::AliasTy::new_from_args(tcx, assoc_ty.def_id, super_trait_ref.args);
252-
let resolved = tcx.normalize_erasing_regions(
250+
let projection_term = ty::AliasTerm::new_from_args(
251+
tcx,
252+
assoc_item.def_id,
253+
super_trait_ref.args,
254+
);
255+
let term = tcx.normalize_erasing_regions(
253256
ty::TypingEnv::fully_monomorphized(),
254-
alias_ty.to_ty(tcx),
257+
projection_term.to_term(tcx),
255258
);
256-
debug!("Resolved {:?} -> {resolved}", alias_ty.to_ty(tcx));
259+
debug!("Projection {:?} -> {term}", projection_term.to_term(tcx),);
257260
ty::ExistentialPredicate::Projection(
258261
ty::ExistentialProjection::erase_self_ty(
259262
tcx,
260-
ty::ProjectionPredicate {
261-
projection_term: alias_ty.into(),
262-
term: resolved.into(),
263-
},
263+
ty::ProjectionPredicate { projection_term, term },
264264
),
265265
)
266266
})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ compile-flags: -Zsanitizer=cfi -Cunsafe-allow-abi-mismatch=sanitizer -Ccodegen-units=1 -Clto
2+
//@ needs-rustc-debug-assertions
3+
//@ needs-sanitizer-cfi
4+
//@ build-pass
5+
//@ no-prefer-dynamic
6+
7+
#![feature(min_generic_const_args)]
8+
#![expect(incomplete_features)]
9+
10+
trait Trait {
11+
#[type_const]
12+
const N: usize;
13+
14+
fn process(&self, _: [u8; Self::N]) -> [u8; Self::N];
15+
}
16+
17+
impl Trait for u8 {
18+
#[type_const]
19+
const N: usize = 2;
20+
21+
fn process(&self, [x, y]: [u8; Self::N]) -> [u8; Self::N] {
22+
[self * x, self + y]
23+
}
24+
}
25+
26+
impl<const N: usize> Trait for [u8; N] {
27+
#[type_const]
28+
const N: usize = N;
29+
30+
fn process(&self, other: [u8; Self::N]) -> [u8; Self::N] {
31+
let mut result = [0; _];
32+
33+
result
34+
}
35+
}
36+
37+
fn main() {
38+
let ops: [Box<dyn Trait<N = 2>>; _] = [Box::new(3), Box::new([1, 1])];
39+
}

0 commit comments

Comments
 (0)