-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/rust-lang/rust/issues/103763
- Loading branch information
1 parent
4cc46c3
commit dd36e62
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/target | ||
.DS_Store | ||
/.vscode | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
dist/ | ||
pkg/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Result | ||
|
||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/target | ||
.DS_Store | ||
/.vscode | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
dist/ | ||
pkg/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "arc_ptr_eq" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Result | ||
|
||
https://github.com/rust-lang/rust/issues/103763 | ||
|
||
``` | ||
$ cargo run | ||
Compiling arc_ptr_eq v0.1.0 (/Users/globalyoung/Documents/test/test/rust/rust_release/rust1_72/arc_ptr_eq) | ||
Finished dev [unoptimized + debuginfo] target(s) in 0.10s | ||
Running `target/debug/arc_ptr_eq` | ||
Found one! | ||
[src/main.rs:23] a_data_addr = 0x000000016ee2a6a0 | ||
[src/main.rs:24] b_data_addr = 0x000000016ee2a6a0 | ||
[src/main.rs:25] a = 0x000000016ee2a6a0 | ||
[src/main.rs:26] b = 0x000000016ee2a6a0 | ||
[src/main.rs:27] a_msg = "Zst" | ||
[src/main.rs:28] b_msg = "Msg(good gravy)" | ||
[src/main.rs:37] (*zm.0).type_id() = TypeId { | ||
t: 177224103700599114721518439526924153296, | ||
} | ||
[src/main.rs:38] (*zm.1).type_id() = TypeId { | ||
t: 18653999097659511391617033891817030262, | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::any::Any; | ||
|
||
trait Trait: Any { | ||
fn msg(&self) -> String; | ||
} | ||
|
||
fn pair(a: *const dyn Trait, b: *const dyn Trait) { | ||
let a_msg; | ||
let b_msg; | ||
unsafe { | ||
a_msg = a.as_ref().unwrap().msg(); | ||
b_msg = b.as_ref().unwrap().msg(); | ||
} | ||
|
||
let a_data_addr = a as *const (); | ||
let b_data_addr = b as *const (); | ||
|
||
// The question: for non-null a, b, | ||
// if `a_data_addr == b_data_addr`, can you ever have `a_msg != b_msg` ? | ||
|
||
if a_msg != b_msg && a_data_addr == b_data_addr { | ||
println!("Found one!"); | ||
dbg!(a_data_addr); | ||
dbg!(b_data_addr); | ||
dbg!(a); | ||
dbg!(b); | ||
dbg!(a_msg); | ||
dbg!(b_msg); | ||
} | ||
} | ||
|
||
fn main() { | ||
let zm = (Zst, Msg("good gravy")); | ||
let zm: (&dyn Trait, &dyn Trait) = (&zm.0, &zm.1); | ||
pair(zm.0, zm.1); | ||
|
||
dbg!((*zm.0).type_id()); | ||
dbg!((*zm.1).type_id()); | ||
} | ||
|
||
struct Zst; | ||
struct Msg(&'static str); | ||
|
||
impl Trait for Zst { | ||
fn msg(&self) -> String { | ||
format!("Zst") | ||
} | ||
} | ||
impl Trait for Msg { | ||
fn msg(&self) -> String { | ||
format!("Msg({})", self.0) | ||
} | ||
} |