defmt icon indicating copy to clipboard operation
defmt copied to clipboard

Don't rely on `Span`'s debug representation

Open jonas-schievink opened this issue 4 years ago • 1 comments

defmt needs to generate symbol names that are unique per macro invocation, even when the macro arguments are identical. We don't want to generate a random number to keep builds reproducible, so what we do currently is:

// We want a deterministic, but unique-per-macro-invocation identifier. For that we
// hash the call site `Span`'s debug representation, which contains a counter that
// should disambiguate macro invocations within a crate.
let s = format!("{:?}", Span::call_site());
let mut hasher = DefaultHasher::new();
s.hash(&mut hasher);
hasher.finish()

This relies on the debug representation of Span, which is probably not the best idea.

Until access to line and column of the span is possible in stable Rust (cc https://github.com/rust-lang/rust/issues/54725), we don't really have a good way of fixing this.

jonas-schievink avatar Jan 15 '21 17:01 jonas-schievink

I've opened an internals thread for discussing a solution to this.

madsmtm avatar Jul 23 '22 14:07 madsmtm