diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-05-09 18:45:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-09 18:45:36 +0200 |
| commit | 6c8001b85ce0b318422e44efec1fe67690ab22d3 (patch) | |
| tree | 00f2a0987e2022b0bc3db1bbff149f6be7491f56 /src | |
| parent | 28d800ce1cb1636c79efba842a158ff76a0d3921 (diff) | |
| parent | 9d157ada35c0e363e30344526755649c3399f7de (diff) | |
| download | rust-6c8001b85ce0b318422e44efec1fe67690ab22d3.tar.gz rust-6c8001b85ce0b318422e44efec1fe67690ab22d3.zip | |
Rollup merge of #96008 - fmease:warn-on-useless-doc-hidden-on-assoc-impl-items, r=lcnr
Warn on unused `#[doc(hidden)]` attributes on trait impl items
[Zulip conversation](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/.E2.9C.94.20Validy.20checks.20for.20.60.23.5Bdoc.28hidden.29.5D.60).
Whether an associated item in a trait impl is shown or hidden in the documentation entirely depends on the corresponding item in the trait declaration. Rustdoc completely ignores `#[doc(hidden)]` attributes on impl items. No error or warning is emitted:
```rust
pub trait Tr { fn f(); }
pub struct Ty;
impl Tr for Ty { #[doc(hidden)] fn f() {} }
// ^^^^^^^^^^^^^^ ignored by rustdoc and currently
// no error or warning issued
```
This may lead users to the wrong belief that the attribute has an effect. In fact, several such cases are found in the standard library (I've removed all of them in this PR).
There does not seem to exist any incentive to allow this in the future either: Impl'ing a trait for a type means the type *fully* conforms to its API. Users can add `#[doc(hidden)]` to the whole impl if they want to hide the implementation or add the attribute to the corresponding associated item in the trait declaration to hide the specific item. Hiding an implementation of an associated item does not make much sense: The associated item can still be found on the trait page.
This PR emits the warn-by-default lint `unused_attribute` for this case with a future-incompat warning.
`@rustbot` label T-compiler T-rustdoc A-lint
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/lint/unused/unused-attr-doc-hidden.fixed | 42 | ||||
| -rw-r--r-- | src/test/ui/lint/unused/unused-attr-doc-hidden.rs | 42 | ||||
| -rw-r--r-- | src/test/ui/lint/unused/unused-attr-doc-hidden.stderr | 67 |
3 files changed, 151 insertions, 0 deletions
diff --git a/src/test/ui/lint/unused/unused-attr-doc-hidden.fixed b/src/test/ui/lint/unused/unused-attr-doc-hidden.fixed new file mode 100644 index 00000000000..36a14097ac3 --- /dev/null +++ b/src/test/ui/lint/unused/unused-attr-doc-hidden.fixed @@ -0,0 +1,42 @@ +#![deny(unused_attributes)] +#![crate_type = "lib"] +// run-rustfix + +pub trait Trait { + type It; + const IT: (); + fn it0(); + fn it1(); + fn it2(); +} + +pub struct Implementor; + +impl Trait for Implementor { + + type It = (); + //~^^ ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted + + + const IT: () = (); + //~^^ ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted + + #[doc(alias = "aka")] + fn it0() {} + //~^^ ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted + + #[doc(alias = "this", )] + fn it1() {} + //~^^ ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted + + #[doc()] + fn it2() {} + //~^^ ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted + //~| ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted +} diff --git a/src/test/ui/lint/unused/unused-attr-doc-hidden.rs b/src/test/ui/lint/unused/unused-attr-doc-hidden.rs new file mode 100644 index 00000000000..e58c4f22f31 --- /dev/null +++ b/src/test/ui/lint/unused/unused-attr-doc-hidden.rs @@ -0,0 +1,42 @@ +#![deny(unused_attributes)] +#![crate_type = "lib"] +// run-rustfix + +pub trait Trait { + type It; + const IT: (); + fn it0(); + fn it1(); + fn it2(); +} + +pub struct Implementor; + +impl Trait for Implementor { + #[doc(hidden)] + type It = (); + //~^^ ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted + + #[doc(hidden)] + const IT: () = (); + //~^^ ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted + + #[doc(hidden, alias = "aka")] + fn it0() {} + //~^^ ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted + + #[doc(alias = "this", hidden,)] + fn it1() {} + //~^^ ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted + + #[doc(hidden, hidden)] + fn it2() {} + //~^^ ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted + //~| ERROR `#[doc(hidden)]` is ignored + //~| WARNING this was previously accepted +} diff --git a/src/test/ui/lint/unused/unused-attr-doc-hidden.stderr b/src/test/ui/lint/unused/unused-attr-doc-hidden.stderr new file mode 100644 index 00000000000..fd1202a29de --- /dev/null +++ b/src/test/ui/lint/unused/unused-attr-doc-hidden.stderr @@ -0,0 +1,67 @@ +error: `#[doc(hidden)]` is ignored on trait impl items + --> $DIR/unused-attr-doc-hidden.rs:16:5 + | +LL | #[doc(hidden)] + | ^^^^^^^^^^^^^^ help: remove this attribute + | +note: the lint level is defined here + --> $DIR/unused-attr-doc-hidden.rs:1:9 + | +LL | #![deny(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ + = 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 + +error: `#[doc(hidden)]` is ignored on trait impl items + --> $DIR/unused-attr-doc-hidden.rs:21:5 + | +LL | #[doc(hidden)] + | ^^^^^^^^^^^^^^ help: remove this attribute + | + = 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 + +error: `#[doc(hidden)]` is ignored on trait impl items + --> $DIR/unused-attr-doc-hidden.rs:26:11 + | +LL | #[doc(hidden, alias = "aka")] + | ^^^^^^-- + | | + | help: remove this attribute + | + = 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 + +error: `#[doc(hidden)]` is ignored on trait impl items + --> $DIR/unused-attr-doc-hidden.rs:31:27 + | +LL | #[doc(alias = "this", hidden,)] + | ^^^^^^- + | | + | help: remove this attribute + | + = 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 + +error: `#[doc(hidden)]` is ignored on trait impl items + --> $DIR/unused-attr-doc-hidden.rs:36:11 + | +LL | #[doc(hidden, hidden)] + | ^^^^^^-- + | | + | help: remove this attribute + | + = 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 + +error: `#[doc(hidden)]` is ignored on trait impl items + --> $DIR/unused-attr-doc-hidden.rs:36:19 + | +LL | #[doc(hidden, hidden)] + | ^^^^^^ help: remove this attribute + | + = 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 + +error: aborting due to 6 previous errors + |
