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 /library/alloc/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 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/collections/vec_deque/iter.rs | 1 | ||||
| -rw-r--r-- | library/alloc/src/collections/vec_deque/iter_mut.rs | 1 | ||||
| -rw-r--r-- | library/alloc/src/vec/into_iter.rs | 1 |
3 files changed, 0 insertions, 3 deletions
diff --git a/library/alloc/src/collections/vec_deque/iter.rs b/library/alloc/src/collections/vec_deque/iter.rs index e8290809276..19198ab3aa1 100644 --- a/library/alloc/src/collections/vec_deque/iter.rs +++ b/library/alloc/src/collections/vec_deque/iter.rs @@ -122,7 +122,6 @@ impl<'a, T> Iterator for Iter<'a, T> { } #[inline] - #[doc(hidden)] unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item { // Safety: The TrustedRandomAccess contract requires that callers only pass an index // that is in bounds. diff --git a/library/alloc/src/collections/vec_deque/iter_mut.rs b/library/alloc/src/collections/vec_deque/iter_mut.rs index ee2df0d5160..b78c0d5e1b3 100644 --- a/library/alloc/src/collections/vec_deque/iter_mut.rs +++ b/library/alloc/src/collections/vec_deque/iter_mut.rs @@ -100,7 +100,6 @@ impl<'a, T> Iterator for IterMut<'a, T> { } #[inline] - #[doc(hidden)] unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item { // Safety: The TrustedRandomAccess contract requires that callers only pass an index // that is in bounds. diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 8134eea570a..a7df6f59b59 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -202,7 +202,6 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> { self.len() } - #[doc(hidden)] unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> Self::Item where Self: TrustedRandomAccessNoCoerce, |
