Skip to content

False positive unused_attributes lint on doc(hidden) attribute on associated type #96890

Closed
@dtolnay

Description

@dtolnay

The warning added by #96008 claims that doc(hidden) on an impl item is ignored by rustdoc, but it isn't necessarily.

The warning says:

whether the impl item is `doc(hidden)` or not entirely depends on the corresponding trait item

which is not true in the following repro:

pub trait Trait {
    type A;
    type B;
}

pub struct Struct;

impl Trait for Struct {
    type A = [(); "interesting type".len()];
    #[doc(hidden)]
    type B = [(); "nasty uninteresting type".len()];
}
$ cargo check
warning: `#[doc(hidden)]` is ignored on trait impl items
  --> src/lib.rs:10:5
   |
10 |     #[doc(hidden)]
   |     ^^^^^^^^^^^^^^ help: remove this attribute
   |
   = note: `#[warn(unused_attributes)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: whether the impl item is `doc(hidden)` or not entirely depends on the corresponding trait item

This warning is a false positive. Rustdoc does pay attention to this attribute. For the code above, the rendered documentation of Struct and Trait looks like:

After removing the supposedly unused doc(hidden) attribute and rendering again, the "nasty uninteresting type" that we wanted not shown is going to get rendered on both pages:

(@fmease @lcnr)

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (88860d547 2022-05-09)
binary: rustc
commit-hash: 88860d5474a32f507dde8fba8df35fd2064f11b9
commit-date: 2022-05-09
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions