diff options
| author | Ralf Jung <post@ralfj.de> | 2023-03-24 16:01:26 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-03-24 16:53:18 +0100 |
| commit | c2fddfd8e256855c11529b79a4987b2137590f90 (patch) | |
| tree | cbd567b9b53f7f0852145036679841ed09df1365 /src | |
| parent | f421586eed77de266a3f99ffa8a5687b7d2d893c (diff) | |
| download | rust-c2fddfd8e256855c11529b79a4987b2137590f90.tar.gz rust-c2fddfd8e256855c11529b79a4987b2137590f90.zip | |
miri: fix raw pointer dyn receivers
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/miri/tests/pass/dyn-arbitrary-self.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tools/miri/tests/pass/dyn-arbitrary-self.rs b/src/tools/miri/tests/pass/dyn-arbitrary-self.rs index 94cf465e884..fc58775a195 100644 --- a/src/tools/miri/tests/pass/dyn-arbitrary-self.rs +++ b/src/tools/miri/tests/pass/dyn-arbitrary-self.rs @@ -123,8 +123,35 @@ fn pointers_and_wrappers() { assert_eq!(wpw.wrapper_ptr_wrapper(), 7); } +fn raw_ptr_receiver() { + use std::ptr; + + trait Foo { + fn foo(self: *const Self) -> &'static str; + } + + impl Foo for i32 { + fn foo(self: *const Self) -> &'static str { + "I'm an i32!" + } + } + + impl Foo for u32 { + fn foo(self: *const Self) -> &'static str { + "I'm a u32!" + } + } + + let null_i32 = ptr::null::<i32>() as *const dyn Foo; + let null_u32 = ptr::null::<u32>() as *const dyn Foo; + + assert_eq!("I'm an i32!", null_i32.foo()); + assert_eq!("I'm a u32!", null_u32.foo()); +} + fn main() { pin_box_dyn(); stdlib_pointers(); pointers_and_wrappers(); + raw_ptr_receiver(); } |
