-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn on unused #[doc(hidden)]
attributes on trait impl items
#96008
Warn on unused #[doc(hidden)]
attributes on trait impl items
#96008
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
For the bug you detected, please open an issue (and assign it to yourself) and fix it in another PR. Otherwise, this PR looks good to me, thanks! |
070aca7
to
8b19067
Compare
This comment was marked as outdated.
This comment was marked as outdated.
8b19067
to
9c81d0c
Compare
I personally think we should treat this similar to other, previously silently ignored attributes. E.g. struct Foo(#[inline] ());
Imo this should be a Though that's for @rust-lang/lang @rust-lang/docs to decide. |
☔ The latest upstream changes (presumably #92566) made this pull request unmergeable. Please resolve the merge conflicts. |
Since nobody else voiced their opinion, I will integrate the lint |
👍 to treating it like the other attributes -- there have been a ton of these, like |
@rustbot author |
9c81d0c
to
02e490e
Compare
02e490e
to
9d157ad
Compare
📌 Commit 9d157ad has been approved by |
…askrgr Rollup of 6 pull requests Successful merges: - rust-lang#95483 (Improve floating point documentation) - rust-lang#96008 (Warn on unused `#[doc(hidden)]` attributes on trait impl items) - rust-lang#96841 (Revert "Implement [OsStr]::join", which was merged without FCP.) - rust-lang#96844 (Actually fix ICE from rust-lang#96583) - rust-lang#96854 (Some subst cleanup) - rust-lang#96858 (Remove unused param from search.js::checkPath) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
👍. So long as (like here) reverting it doesn't break people, it doesn't need a full FCP. |
FWIW the rustdoc that shipped with 1.56.0 and older versions of Rust does look at A typical case looks like: pub trait Trait {
fn public_fn();
#[doc(hidden)]
fn __private_fn() {…}
}
impl Trait for Struct {
fn public_fn() {…}
#[doc(hidden)]
fn __private_fn() {…}
} Without Rust 1.56.0 is only 6 months old so it's not unreasonable that libraries would want to support it. |
I noticed in a different one of my crates that the I filed #96890 to follow up. |
Oh, I didn't know older versions of rustdoc behave differently in this scenario. Is 1.56 the last version where rustdoc behaved differently? (Well, for 1.62 I even extended the new behavior, see #95769) |
Do not emit the lint `unused_attributes` for *inherent* `#[doc(hidden)]` associated items Fixes rust-lang#97205 (embarrassing oversight from rust-lang#96008). `@rustbot` label A-lint
…t, r=GuillaumeGomez Remove the unused-`#[doc(hidden)]` logic from the `unused_attributes` lint Fixes rust-lang#96890. It was found out that `#[doc(hidden)]` on trait impl items does indeed have an effect on the generated documentation (see the linked issue). In my opinion and the one of [others](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Validy.20checks.20for.20.60.23.5Bdoc.28hidden.29.5D.60/near/281846219), rustdoc's output is actually a bit flawed in that regard but that should be tracked in a new issue I suppose (I will open an issue for that in the near future). The check was introduced in rust-lang#96008 which is marked to be part of version `1.62` (current `beta`). As far as I understand, this means that **this PR needs to be backported** to `beta` to fix rust-lang#96890 on time. Correct me if I am wrong. CC `@dtolnay` (in case you would like to agree or disagree with my decision to fully remove this check) `@rustbot` label A-lint T-compiler T-rustdoc r? `@rust-lang/compiler`
…t, r=GuillaumeGomez Remove the unused-`#[doc(hidden)]` logic from the `unused_attributes` lint Fixes rust-lang#96890. It was found out that `#[doc(hidden)]` on trait impl items does indeed have an effect on the generated documentation (see the linked issue). In my opinion and the one of [others](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Validy.20checks.20for.20.60.23.5Bdoc.28hidden.29.5D.60/near/281846219), rustdoc's output is actually a bit flawed in that regard but that should be tracked in a new issue I suppose (I will open an issue for that in the near future). The check was introduced in rust-lang#96008 which is marked to be part of version `1.62` (current `beta`). As far as I understand, this means that **this PR needs to be backported** to `beta` to fix rust-lang#96890 on time. Correct me if I am wrong. CC `@dtolnay` (in case you would like to agree or disagree with my decision to fully remove this check) `@rustbot` label A-lint T-compiler T-rustdoc r? `@rust-lang/compiler`
Zulip conversation.
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: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