-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #96008 - fmease:warn-on-useless-doc-hidden-on-assoc-i…
…mpl-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
- Loading branch information
Showing
18 changed files
with
225 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Oops, something went wrong.