aboutsummaryrefslogtreecommitdiff
path: root/macros/src
diff options
context:
space:
mode:
authorGravatar Hugo van der Wijst <hvanderwijst@tesla.com> 2019-01-22 15:23:16 -0800
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-02-16 00:23:01 +0100
commita654d13eefa846b9dc7fcdc1ccf5af43fc33834e (patch)
treece780231e9857112166fe082e78388f26f27115c /macros/src
parent82c533cbf43c56da0960de7b48e7a6d1cc8defd0 (diff)
downloadrtic-a654d13eefa846b9dc7fcdc1ccf5af43fc33834e.tar.gz
rtic-a654d13eefa846b9dc7fcdc1ccf5af43fc33834e.tar.zst
rtic-a654d13eefa846b9dc7fcdc1ccf5af43fc33834e.zip
Seed RNG with package name and prepend string to full random name.
Diffstat (limited to 'macros/src')
-rw-r--r--macros/src/codegen.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs
index 9eb875c7..9fc0e271 100644
--- a/macros/src/codegen.rs
+++ b/macros/src/codegen.rs
@@ -1998,7 +1998,12 @@ struct IdentGenerator {
impl IdentGenerator {
fn new() -> IdentGenerator {
- IdentGenerator { rng: rand::rngs::SmallRng::seed_from_u64(0) }
+ let crate_name = env!("CARGO_PKG_NAME");
+ let seed = [0u8; 16];
+ for (i, b) in crate_name.bytes().enumerate() {
+ seed[i%seed.len()].wrapping_add(b);
+ }
+ IdentGenerator { rng: rand::rngs::SmallRng::from_seed(seed) }
}
fn mk_ident(&mut self, name: Option<&str>) -> Ident {
@@ -2007,8 +2012,9 @@ impl IdentGenerator {
n = 4;
format!("{}_", name)
} else {
+ let crate_name = env!("CARGO_PKG_NAME").replace("-", "_").to_lowercase();
n = 16;
- String::new()
+ format!("{}__internal__", crate_name)
};
for i in 0..n {