Skip to content

Commit 5321e52

Browse files
authored
core: ensure callsites in test have unique addresses (#2681)
The test relies on TEST_CALLSITE_1 and TEST_CALLSITE_2 to have different addresses. However, as they are zero-sized types, this is not guaranteed. This fixes the test failure with LLVM 17 and certain optimization options reported at rust-lang/rust#114699.
1 parent 941b159 commit 5321e52

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tracing-core/src/field.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,9 @@ mod test {
978978
use super::*;
979979
use crate::metadata::{Kind, Level, Metadata};
980980

981-
struct TestCallsite1;
982-
static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1;
981+
// Make sure TEST_CALLSITE_* have non-zero size, so they can't be located at the same address.
982+
struct TestCallsite1(u8);
983+
static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1(0);
983984
static TEST_META_1: Metadata<'static> = metadata! {
984985
name: "field_test1",
985986
target: module_path!(),
@@ -999,8 +1000,8 @@ mod test {
9991000
}
10001001
}
10011002

1002-
struct TestCallsite2;
1003-
static TEST_CALLSITE_2: TestCallsite2 = TestCallsite2;
1003+
struct TestCallsite2(u8);
1004+
static TEST_CALLSITE_2: TestCallsite2 = TestCallsite2(0);
10041005
static TEST_META_2: Metadata<'static> = metadata! {
10051006
name: "field_test2",
10061007
target: module_path!(),

0 commit comments

Comments
 (0)