From 67508f3714296ffb0cf9820e1c1ba46b082227a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Tue, 21 Jun 2022 13:42:34 +0200 Subject: [PATCH] Remove `#[doc(hidden)]` logic from `unused_attributes` lint --- compiler/rustc_passes/src/check_attr.rs | 76 +------------------ .../lint/unused/unused-attr-doc-hidden.fixed | 55 -------------- .../ui/lint/unused/unused-attr-doc-hidden.rs | 55 -------------- .../lint/unused/unused-attr-doc-hidden.stderr | 67 ---------------- 4 files changed, 2 insertions(+), 251 deletions(-) delete mode 100644 src/test/ui/lint/unused/unused-attr-doc-hidden.fixed delete mode 100644 src/test/ui/lint/unused/unused-attr-doc-hidden.rs delete mode 100644 src/test/ui/lint/unused/unused-attr-doc-hidden.stderr diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 4ef0f590a1f..536d45b2399 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -4,8 +4,7 @@ //! conflicts between multiple such attributes attached to the same //! item. -use rustc_ast::tokenstream::DelimSpan; -use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MacArgs, MetaItemKind, NestedMetaItem}; +use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan}; use rustc_expand::base::resolve_path; @@ -899,68 +898,6 @@ impl CheckAttrVisitor<'_> { } } - /// Checks `#[doc(hidden)]` attributes. Returns `true` if valid. - fn check_doc_hidden( - &self, - attr: &Attribute, - meta_index: usize, - meta: &NestedMetaItem, - hir_id: HirId, - target: Target, - ) -> bool { - if let Target::AssocConst - | Target::AssocTy - | Target::Method(MethodKind::Trait { body: true }) = target - { - let parent_hir_id = self.tcx.hir().get_parent_item(hir_id); - let containing_item = self.tcx.hir().expect_item(parent_hir_id); - - if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = containing_item.kind { - let meta_items = attr.meta_item_list().unwrap(); - - let (span, replacement_span) = if meta_items.len() == 1 { - (attr.span, attr.span) - } else { - let meta_span = meta.span(); - ( - meta_span, - meta_span.until(match meta_items.get(meta_index + 1) { - Some(next_item) => next_item.span(), - None => match attr.get_normal_item().args { - MacArgs::Delimited(DelimSpan { close, .. }, ..) => close, - _ => unreachable!(), - }, - }), - ) - }; - - // FIXME: #[doc(hidden)] was previously erroneously allowed on trait impl items, - // so for backward compatibility only emit a warning and do not mark it as invalid. - self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, span, |lint| { - lint.build("`#[doc(hidden)]` is ignored on trait impl items") - .warn( - "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", - ) - .span_suggestion( - replacement_span, - "remove this attribute", - "", - Applicability::MachineApplicable, - ) - .emit(); - }); - } - } - - true - } - /// Checks that an attribute is *not* used at the crate level. Returns `true` if valid. fn check_attr_not_crate_level( &self, @@ -1079,7 +1016,7 @@ impl CheckAttrVisitor<'_> { let mut is_valid = true; if let Some(mi) = attr.meta() && let Some(list) = mi.meta_item_list() { - for (meta_index, meta) in list.into_iter().enumerate() { + for meta in list { if let Some(i_meta) = meta.meta_item() { match i_meta.name_or_empty() { sym::alias @@ -1127,15 +1064,6 @@ impl CheckAttrVisitor<'_> { is_valid = false; } - sym::hidden if !self.check_doc_hidden(attr, - meta_index, - meta, - hir_id, - target, - ) => { - is_valid = false; - } - // no_default_passes: deprecated // passes: deprecated // plugins: removed, but rustdoc warns about it itself diff --git a/src/test/ui/lint/unused/unused-attr-doc-hidden.fixed b/src/test/ui/lint/unused/unused-attr-doc-hidden.fixed deleted file mode 100644 index 362ad55707a..00000000000 --- a/src/test/ui/lint/unused/unused-attr-doc-hidden.fixed +++ /dev/null @@ -1,55 +0,0 @@ -#![feature(inherent_associated_types)] -#![allow(dead_code, incomplete_features)] -#![crate_type = "lib"] -#![deny(unused_attributes)] -// run-rustfix - -pub trait Trait { - type It; - const IT: (); - fn it0(); - fn it1(); - fn it2(); -} - -pub struct Implementor; - -impl Implementor { - #[doc(hidden)] // no error - type Inh = (); - - #[doc(hidden)] // no error - const INH: () = (); - - #[doc(hidden)] // no error - fn inh() {} -} - -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 deleted file mode 100644 index d493ed6dae2..00000000000 --- a/src/test/ui/lint/unused/unused-attr-doc-hidden.rs +++ /dev/null @@ -1,55 +0,0 @@ -#![feature(inherent_associated_types)] -#![allow(dead_code, incomplete_features)] -#![crate_type = "lib"] -#![deny(unused_attributes)] -// run-rustfix - -pub trait Trait { - type It; - const IT: (); - fn it0(); - fn it1(); - fn it2(); -} - -pub struct Implementor; - -impl Implementor { - #[doc(hidden)] // no error - type Inh = (); - - #[doc(hidden)] // no error - const INH: () = (); - - #[doc(hidden)] // no error - fn inh() {} -} - -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 deleted file mode 100644 index f167bd460db..00000000000 --- a/src/test/ui/lint/unused/unused-attr-doc-hidden.stderr +++ /dev/null @@ -1,67 +0,0 @@ -error: `#[doc(hidden)]` is ignored on trait impl items - --> $DIR/unused-attr-doc-hidden.rs:29:5 - | -LL | #[doc(hidden)] - | ^^^^^^^^^^^^^^ help: remove this attribute - | -note: the lint level is defined here - --> $DIR/unused-attr-doc-hidden.rs:4: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:34: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:39: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:44: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:49: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:49: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 -