Skip to content

Commit e725273

Browse files
committed
Do not warn on inherent doc(hidden) assoc items
1 parent f24ef2e commit e725273

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl CheckAttrVisitor<'_> {
832832
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
833833
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
834834

835-
if Target::from_item(containing_item) == Target::Impl {
835+
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = containing_item.kind {
836836
let meta_items = attr.meta_item_list().unwrap();
837837

838838
let (span, replacement_span) = if meta_items.len() == 1 {

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
#![deny(unused_attributes)]
1+
#![feature(inherent_associated_types)]
2+
#![allow(dead_code, incomplete_features)]
23
#![crate_type = "lib"]
4+
#![deny(unused_attributes)]
35
// run-rustfix
46

57
pub trait Trait {
@@ -12,6 +14,17 @@ pub trait Trait {
1214

1315
pub struct Implementor;
1416

17+
impl Implementor {
18+
#[doc(hidden)] // no error
19+
type Inh = ();
20+
21+
#[doc(hidden)] // no error
22+
const INH: () = ();
23+
24+
#[doc(hidden)] // no error
25+
fn inh() {}
26+
}
27+
1528
impl Trait for Implementor {
1629

1730
type It = ();

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
#![deny(unused_attributes)]
1+
#![feature(inherent_associated_types)]
2+
#![allow(dead_code, incomplete_features)]
23
#![crate_type = "lib"]
4+
#![deny(unused_attributes)]
35
// run-rustfix
46

57
pub trait Trait {
@@ -12,6 +14,17 @@ pub trait Trait {
1214

1315
pub struct Implementor;
1416

17+
impl Implementor {
18+
#[doc(hidden)] // no error
19+
type Inh = ();
20+
21+
#[doc(hidden)] // no error
22+
const INH: () = ();
23+
24+
#[doc(hidden)] // no error
25+
fn inh() {}
26+
}
27+
1528
impl Trait for Implementor {
1629
#[doc(hidden)]
1730
type It = ();

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error: `#[doc(hidden)]` is ignored on trait impl items
2-
--> $DIR/unused-attr-doc-hidden.rs:16:5
2+
--> $DIR/unused-attr-doc-hidden.rs:29:5
33
|
44
LL | #[doc(hidden)]
55
| ^^^^^^^^^^^^^^ help: remove this attribute
66
|
77
note: the lint level is defined here
8-
--> $DIR/unused-attr-doc-hidden.rs:1:9
8+
--> $DIR/unused-attr-doc-hidden.rs:4:9
99
|
1010
LL | #![deny(unused_attributes)]
1111
| ^^^^^^^^^^^^^^^^^
1212
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1313
= note: whether the impl item is `doc(hidden)` or not entirely depends on the corresponding trait item
1414

1515
error: `#[doc(hidden)]` is ignored on trait impl items
16-
--> $DIR/unused-attr-doc-hidden.rs:21:5
16+
--> $DIR/unused-attr-doc-hidden.rs:34:5
1717
|
1818
LL | #[doc(hidden)]
1919
| ^^^^^^^^^^^^^^ help: remove this attribute
@@ -22,7 +22,7 @@ LL | #[doc(hidden)]
2222
= note: whether the impl item is `doc(hidden)` or not entirely depends on the corresponding trait item
2323

2424
error: `#[doc(hidden)]` is ignored on trait impl items
25-
--> $DIR/unused-attr-doc-hidden.rs:26:11
25+
--> $DIR/unused-attr-doc-hidden.rs:39:11
2626
|
2727
LL | #[doc(hidden, alias = "aka")]
2828
| ^^^^^^--
@@ -33,7 +33,7 @@ LL | #[doc(hidden, alias = "aka")]
3333
= note: whether the impl item is `doc(hidden)` or not entirely depends on the corresponding trait item
3434

3535
error: `#[doc(hidden)]` is ignored on trait impl items
36-
--> $DIR/unused-attr-doc-hidden.rs:31:27
36+
--> $DIR/unused-attr-doc-hidden.rs:44:27
3737
|
3838
LL | #[doc(alias = "this", hidden,)]
3939
| ^^^^^^-
@@ -44,7 +44,7 @@ LL | #[doc(alias = "this", hidden,)]
4444
= note: whether the impl item is `doc(hidden)` or not entirely depends on the corresponding trait item
4545

4646
error: `#[doc(hidden)]` is ignored on trait impl items
47-
--> $DIR/unused-attr-doc-hidden.rs:36:11
47+
--> $DIR/unused-attr-doc-hidden.rs:49:11
4848
|
4949
LL | #[doc(hidden, hidden)]
5050
| ^^^^^^--
@@ -55,7 +55,7 @@ LL | #[doc(hidden, hidden)]
5555
= note: whether the impl item is `doc(hidden)` or not entirely depends on the corresponding trait item
5656

5757
error: `#[doc(hidden)]` is ignored on trait impl items
58-
--> $DIR/unused-attr-doc-hidden.rs:36:19
58+
--> $DIR/unused-attr-doc-hidden.rs:49:19
5959
|
6060
LL | #[doc(hidden, hidden)]
6161
| ^^^^^^ help: remove this attribute

0 commit comments

Comments
 (0)