Skip to content

Commit c211c67

Browse files
JohnTitorehuss
authored andcommitted
Rollup merge of #98336 - fmease:remove-faulty-doc-hidden-lint, r=GuillaumeGomez
Remove the unused-`#[doc(hidden)]` logic from the `unused_attributes` lint Fixes #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 #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 #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`
1 parent fec9ff3 commit c211c67

File tree

4 files changed

+2
-225
lines changed

4 files changed

+2
-225
lines changed

compiler/rustc_passes/src/check_attr.rs

+2-74
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7-
use rustc_ast::tokenstream::DelimSpan;
8-
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MacArgs, MetaItemKind, NestedMetaItem};
7+
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
98
use rustc_data_structures::fx::FxHashMap;
109
use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan};
1110
use rustc_feature::{AttributeDuplicates, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
@@ -815,68 +814,6 @@ impl CheckAttrVisitor<'_> {
815814
}
816815
}
817816

818-
/// Checks `#[doc(hidden)]` attributes. Returns `true` if valid.
819-
fn check_doc_hidden(
820-
&self,
821-
attr: &Attribute,
822-
meta_index: usize,
823-
meta: &NestedMetaItem,
824-
hir_id: HirId,
825-
target: Target,
826-
) -> bool {
827-
if let Target::AssocConst
828-
| Target::AssocTy
829-
| Target::Method(MethodKind::Trait { body: true }) = target
830-
{
831-
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
832-
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
833-
834-
if Target::from_item(containing_item) == Target::Impl {
835-
let meta_items = attr.meta_item_list().unwrap();
836-
837-
let (span, replacement_span) = if meta_items.len() == 1 {
838-
(attr.span, attr.span)
839-
} else {
840-
let meta_span = meta.span();
841-
(
842-
meta_span,
843-
meta_span.until(match meta_items.get(meta_index + 1) {
844-
Some(next_item) => next_item.span(),
845-
None => match attr.get_normal_item().args {
846-
MacArgs::Delimited(DelimSpan { close, .. }, ..) => close,
847-
_ => unreachable!(),
848-
},
849-
}),
850-
)
851-
};
852-
853-
// FIXME: #[doc(hidden)] was previously erroneously allowed on trait impl items,
854-
// so for backward compatibility only emit a warning and do not mark it as invalid.
855-
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, span, |lint| {
856-
lint.build("`#[doc(hidden)]` is ignored on trait impl items")
857-
.warn(
858-
"this was previously accepted by the compiler but is \
859-
being phased out; it will become a hard error in \
860-
a future release!",
861-
)
862-
.note(
863-
"whether the impl item is `doc(hidden)` or not \
864-
entirely depends on the corresponding trait item",
865-
)
866-
.span_suggestion(
867-
replacement_span,
868-
"remove this attribute",
869-
String::new(),
870-
Applicability::MachineApplicable,
871-
)
872-
.emit();
873-
});
874-
}
875-
}
876-
877-
true
878-
}
879-
880817
/// Checks that an attribute is *not* used at the crate level. Returns `true` if valid.
881818
fn check_attr_not_crate_level(
882819
&self,
@@ -995,7 +932,7 @@ impl CheckAttrVisitor<'_> {
995932
let mut is_valid = true;
996933

997934
if let Some(mi) = attr.meta() && let Some(list) = mi.meta_item_list() {
998-
for (meta_index, meta) in list.into_iter().enumerate() {
935+
for meta in list {
999936
if let Some(i_meta) = meta.meta_item() {
1000937
match i_meta.name_or_empty() {
1001938
sym::alias
@@ -1036,15 +973,6 @@ impl CheckAttrVisitor<'_> {
1036973
is_valid = false;
1037974
}
1038975

1039-
sym::hidden if !self.check_doc_hidden(attr,
1040-
meta_index,
1041-
meta,
1042-
hir_id,
1043-
target,
1044-
) => {
1045-
is_valid = false;
1046-
}
1047-
1048976
// no_default_passes: deprecated
1049977
// passes: deprecated
1050978
// plugins: removed, but rustdoc warns about it itself

src/test/ui/lint/unused/unused-attr-doc-hidden.fixed

-42
This file was deleted.

src/test/ui/lint/unused/unused-attr-doc-hidden.rs

-42
This file was deleted.

src/test/ui/lint/unused/unused-attr-doc-hidden.stderr

-67
This file was deleted.

0 commit comments

Comments
 (0)