Skip to content

Commit 9e1b2b5

Browse files
authored
Unrolled build for #151947
Rollup merge of #151947 - mu001999-contrib:fix/151878, r=fmease Include assoc const projections in CFI trait object Fixes #151878 After #150843, projections of trait objects should include assoc consts, but the cfi `trait_object_ty` still include only assoc types. So that we got the ICE `expected 1 projection but got 0`.
2 parents 92ea9b2 + 990c558 commit 9e1b2b5

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

‎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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 = 0;
13+
fn process(&self, _: [u8; Self::N]) {}
14+
}
15+
16+
impl Trait for () {}
17+
18+
fn main() {
19+
let _x: &dyn Trait<N = 0> = &();
20+
}

0 commit comments

Comments
 (0)