From 5321e52263e24788a78363bd4411d8c04671bee3 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 14 Aug 2023 19:08:45 +0200 Subject: [PATCH] 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 https://github.com/rust-lang/rust/issues/114699. --- tracing-core/src/field.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tracing-core/src/field.rs b/tracing-core/src/field.rs index 80ca065ba3..2c8596117c 100644 --- a/tracing-core/src/field.rs +++ b/tracing-core/src/field.rs @@ -978,8 +978,9 @@ mod test { use super::*; use crate::metadata::{Kind, Level, Metadata}; - struct TestCallsite1; - static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1; + // Make sure TEST_CALLSITE_* have non-zero size, so they can't be located at the same address. + struct TestCallsite1(u8); + static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1(0); static TEST_META_1: Metadata<'static> = metadata! { name: "field_test1", target: module_path!(), @@ -999,8 +1000,8 @@ mod test { } } - struct TestCallsite2; - static TEST_CALLSITE_2: TestCallsite2 = TestCallsite2; + struct TestCallsite2(u8); + static TEST_CALLSITE_2: TestCallsite2 = TestCallsite2(0); static TEST_META_2: Metadata<'static> = metadata! { name: "field_test2", target: module_path!(),