Skip to content

macros use fields more than once #1739

Closed
@Skepfyr

Description

@Skepfyr

Bug Report

Some tracing macros can use the fields provided more than once causing confusing and non-local error messages.

Version

Discovered on 0.1.29, from a code read also looks to be present on master.

Crates

tracing

Description

#[derive(Debug)]
struct Foo;

#[derive(Debug)]
struct Bar(Foo);

pub fn foo(foo: Foo) {
    tracing::error!("{:?}", Bar(foo))
}

when the above code is compiled with the log feature enabled, you get the following compiler error:

error[E0382]: use of moved value: `foo`
 --> src/lib.rs:8:33
  |
7 | pub fn foo(foo: Foo) {
  |            --- move occurs because `foo` has type `Foo`, which does not implement the `Copy` trait
8 |     tracing::error!("{:?}", Bar(foo))
  |                                 ^^^
  |                                 |
  |                                 value moved here
  |                                 value used here after move

For more information about this error, try `rustc --explain E0382`.

(You can also extend this to weird and wonderful effects, such as a counter that depends on the feature flags and log level.)

This error is confusing by itself, but is made worse by the fact that it can be triggered indirectly; this (A) compiles fine without the log feature enabled, but if a crate (B) depends on A and (even indirectly) enables the log feature then A will fail to compile as part of B, but will compile fine by itself.

From a quick code read I think there may be other macros affected by this, but I haven't investigated any further.

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/tracingRelated to the `tracing` cratekind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions