File tree Expand file tree Collapse file tree 6 files changed +122
-0
lines changed Expand file tree Collapse file tree 6 files changed +122
-0
lines changed Original file line number Diff line number Diff line change
1
+ /target
2
+ .DS_Store
3
+ /.vscode
4
+ # Generated by Cargo
5
+ # will have compiled files and executables
6
+ debug /
7
+ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
8
+ # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
9
+ Cargo.lock
10
+ # These are backup files generated by rustfmt
11
+ ** /* .rs.bk
12
+ # MSVC Windows builds of rustc generate these, which store debugging information
13
+ * .pdb
14
+ dist /
15
+ pkg /
Original file line number Diff line number Diff line change
1
+ # Result
2
+
3
+ ```
4
+
5
+ ```
Original file line number Diff line number Diff line change
1
+ /target
2
+ .DS_Store
3
+ /.vscode
4
+ # Generated by Cargo
5
+ # will have compiled files and executables
6
+ debug /
7
+ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
8
+ # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
9
+ Cargo.lock
10
+ # These are backup files generated by rustfmt
11
+ ** /* .rs.bk
12
+ # MSVC Windows builds of rustc generate these, which store debugging information
13
+ * .pdb
14
+ dist /
15
+ pkg /
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " arc_ptr_eq"
3
+ version = " 0.1.0"
4
+ edition = " 2021"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+
8
+ [dependencies ]
Original file line number Diff line number Diff line change
1
+ # Result
2
+
3
+ https://github.com/rust-lang/rust/issues/103763
4
+
5
+ ```
6
+
7
+ $ cargo run
8
+ Compiling arc_ptr_eq v0.1.0 (/Users/globalyoung/Documents/test/test/rust/rust_release/rust1_72/arc_ptr_eq)
9
+ Finished dev [unoptimized + debuginfo] target(s) in 0.10s
10
+ Running `target/debug/arc_ptr_eq`
11
+
12
+ Found one!
13
+ [src/main.rs:23] a_data_addr = 0x000000016ee2a6a0
14
+ [src/main.rs:24] b_data_addr = 0x000000016ee2a6a0
15
+ [src/main.rs:25] a = 0x000000016ee2a6a0
16
+ [src/main.rs:26] b = 0x000000016ee2a6a0
17
+ [src/main.rs:27] a_msg = "Zst"
18
+ [src/main.rs:28] b_msg = "Msg(good gravy)"
19
+ [src/main.rs:37] (*zm.0).type_id() = TypeId {
20
+ t: 177224103700599114721518439526924153296,
21
+ }
22
+ [src/main.rs:38] (*zm.1).type_id() = TypeId {
23
+ t: 18653999097659511391617033891817030262,
24
+ }
25
+
26
+ ```
Original file line number Diff line number Diff line change
1
+ use std:: any:: Any ;
2
+
3
+ trait Trait : Any {
4
+ fn msg ( & self ) -> String ;
5
+ }
6
+
7
+ fn pair ( a : * const dyn Trait , b : * const dyn Trait ) {
8
+ let a_msg;
9
+ let b_msg;
10
+ unsafe {
11
+ a_msg = a. as_ref ( ) . unwrap ( ) . msg ( ) ;
12
+ b_msg = b. as_ref ( ) . unwrap ( ) . msg ( ) ;
13
+ }
14
+
15
+ let a_data_addr = a as * const ( ) ;
16
+ let b_data_addr = b as * const ( ) ;
17
+
18
+ // The question: for non-null a, b,
19
+ // if `a_data_addr == b_data_addr`, can you ever have `a_msg != b_msg` ?
20
+
21
+ if a_msg != b_msg && a_data_addr == b_data_addr {
22
+ println ! ( "Found one!" ) ;
23
+ dbg ! ( a_data_addr) ;
24
+ dbg ! ( b_data_addr) ;
25
+ dbg ! ( a) ;
26
+ dbg ! ( b) ;
27
+ dbg ! ( a_msg) ;
28
+ dbg ! ( b_msg) ;
29
+ }
30
+ }
31
+
32
+ fn main ( ) {
33
+ let zm = ( Zst , Msg ( "good gravy" ) ) ;
34
+ let zm: ( & dyn Trait , & dyn Trait ) = ( & zm. 0 , & zm. 1 ) ;
35
+ pair ( zm. 0 , zm. 1 ) ;
36
+
37
+ dbg ! ( ( * zm. 0 ) . type_id( ) ) ;
38
+ dbg ! ( ( * zm. 1 ) . type_id( ) ) ;
39
+ }
40
+
41
+ struct Zst ;
42
+ struct Msg ( & ' static str ) ;
43
+
44
+ impl Trait for Zst {
45
+ fn msg ( & self ) -> String {
46
+ format ! ( "Zst" )
47
+ }
48
+ }
49
+ impl Trait for Msg {
50
+ fn msg ( & self ) -> String {
51
+ format ! ( "Msg({})" , self . 0 )
52
+ }
53
+ }
You can’t perform that action at this time.
0 commit comments