Skip to content

Commit 2e9d962

Browse files
authored
Rollup merge of #127882 - compiler-errors:cfi-sized-self-gat, r=oli-obk
Don't elaborate associated types with Sized bounds in `trait_object_ty` in cfi The elaboration mechanism introduced in #123005 didn't filter for associated types with `Self: Sized` bounds, which since #112319 has excluded them from the object type. Fixes #127881 cc `@maurer` `@rcvalle`
2 parents 4db3d12 + 29f5d8f commit 2e9d962

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ fn trait_object_ty<'tcx>(tcx: TyCtxt<'tcx>, poly_trait_ref: ty::PolyTraitRef<'tc
232232
tcx.associated_items(super_poly_trait_ref.def_id())
233233
.in_definition_order()
234234
.filter(|item| item.kind == ty::AssocKind::Type)
235+
.filter(|item| !tcx.generics_require_sized_self(item.def_id))
235236
.map(move |assoc_ty| {
236237
super_poly_trait_ref.map_bound(|super_trait_ref| {
237238
let alias_ty =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Check that we only elaborate non-`Self: Sized` associated types when
2+
// erasing the receiver from trait ref.
3+
4+
//@ revisions: cfi kcfi
5+
// FIXME(#122848) Remove only-linux once OSX CFI binaries work
6+
//@ only-linux
7+
//@ [cfi] needs-sanitizer-cfi
8+
//@ [kcfi] needs-sanitizer-kcfi
9+
//@ compile-flags: -C target-feature=-crt-static
10+
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
11+
//@ [cfi] compile-flags: -Z sanitizer=cfi
12+
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
13+
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
14+
//@ run-pass
15+
16+
trait Foo {
17+
type Bar<'a>
18+
where
19+
Self: Sized;
20+
21+
fn test(&self);
22+
}
23+
24+
impl Foo for () {
25+
type Bar<'a> = ()
26+
where
27+
Self: Sized;
28+
29+
fn test(&self) {}
30+
}
31+
32+
fn test(x: &dyn Foo) {
33+
x.test();
34+
}
35+
36+
fn main() {
37+
test(&());
38+
}

0 commit comments

Comments
 (0)