Skip to content

tracing::instrument breaks "type ... is more private than the item" warnings #3207

@grahamc

Description

@grahamc

Bug Report

Version

tracing 0.1.41

Platform

Darwin Grahams-MacBook-Pro.local 24.2.0 Darwin Kernel Version 24.2.0: Fri Dec 6 19:02:12 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6031 arm64 arm Darwin

but also play.rust-lang.org.

Crates

  • tracing

Description

Marking a function with tracing::instrument obscures type visibility errors.

The following code has a warning that the pub function hi returns Foo, which is not pub:

struct Foo {}

pub fn hi() -> Foo {
    Foo {}
}

and the error:

warning: type `Foo` is more private than the item `hi`
 --> src/lib.rs:5:1
  |
5 | pub fn hi() -> Foo {
  | ^^^^^^^^^^^^^^^^^^ function `hi` is reachable at visibility `pub`
  |
note: but type `Foo` is only usable at visibility `pub(crate)`
 --> src/lib.rs:3:1
  |
3 | struct Foo {}
  | ^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

However, if I mark hi with tracing::instrument...:

use tracing; // 0.1.41;

struct Foo {}

#[tracing::instrument]
pub fn hi() -> Foo {
    Foo {}
}

The warning goes away:

   Compiling playground v0.0.1 (/playground)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.41s

I would expect Rust to continue issuing warnings about these types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions