rust/tests/ui/sanitizer/cfi-virtual-auto.rs
Matthew Maurer f434c27067 CFI: Strip auto traits off Self for virtual calls
Additional trait bounds beyond the principal trait and its implications
are not possible in the vtable. This means that if a receiver is
`&dyn Foo + Send`, the function will only be expecting `&dyn Foo`.

This strips those auto traits off before CFI encoding.
2024-03-23 18:30:45 +00:00

23 lines
533 B
Rust

// Tests that calling a trait object method on a trait object with additional auto traits works.
//@ needs-sanitizer-cfi
// FIXME(#122848) Remove only-linux once OSX CFI binaries work
//@ only-linux
//@ compile-flags: --crate-type=bin -Cprefer-dynamic=off -Clto -Zsanitizer=cfi
//@ compile-flags: -C target-feature=-crt-static -C codegen-units=1 -C opt-level=0
//@ run-pass
trait Foo {
fn foo(&self);
}
struct Bar;
impl Foo for Bar {
fn foo(&self) {}
}
pub fn main() {
let x: &(dyn Foo + Send) = &Bar;
x.foo();
}