Skip to content

Commit 2bc2a0d

Browse files
For now, ignore target checking for doc attributes in attr_parsing
1 parent 9fdec81 commit 2bc2a0d

File tree

9 files changed

+53
-162
lines changed

9 files changed

+53
-162
lines changed

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::lints::AttributeLintKind;
77
use rustc_span::{Span, Symbol, edition, sym};
88
use thin_vec::ThinVec;
99

10-
use super::prelude::{Allow, AllowedTargets, Error, MethodKind, Target};
10+
use super::prelude::{ALL_TARGETS, AllowedTargets};
1111
use super::{AcceptMapping, AttributeParser};
1212
use crate::context::{AcceptContext, FinalizeContext, Stage};
1313
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, PathParser};
@@ -583,37 +583,39 @@ impl<S: Stage> AttributeParser<S> for DocParser {
583583
this.accept_single_doc_attr(cx, args);
584584
},
585585
)];
586-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
587-
Allow(Target::ExternCrate),
588-
Allow(Target::Use),
589-
Allow(Target::Static),
590-
Allow(Target::Const),
591-
Allow(Target::Fn),
592-
Allow(Target::Mod),
593-
Allow(Target::ForeignMod),
594-
Allow(Target::TyAlias),
595-
Allow(Target::Enum),
596-
Allow(Target::Variant),
597-
Allow(Target::Struct),
598-
Allow(Target::Field),
599-
Allow(Target::Union),
600-
Allow(Target::Trait),
601-
Allow(Target::TraitAlias),
602-
Allow(Target::Impl { of_trait: true }),
603-
Allow(Target::Impl { of_trait: false }),
604-
Allow(Target::AssocConst),
605-
Allow(Target::Method(MethodKind::Inherent)),
606-
Allow(Target::Method(MethodKind::Trait { body: true })),
607-
Allow(Target::Method(MethodKind::Trait { body: false })),
608-
Allow(Target::Method(MethodKind::TraitImpl)),
609-
Allow(Target::AssocTy),
610-
Allow(Target::ForeignFn),
611-
Allow(Target::ForeignStatic),
612-
Allow(Target::ForeignTy),
613-
Allow(Target::MacroDef),
614-
Allow(Target::Crate),
615-
Error(Target::WherePredicate),
616-
]);
586+
// FIXME: Currently emitted from 2 different places, generating duplicated warnings.
587+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
588+
// const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
589+
// Allow(Target::ExternCrate),
590+
// Allow(Target::Use),
591+
// Allow(Target::Static),
592+
// Allow(Target::Const),
593+
// Allow(Target::Fn),
594+
// Allow(Target::Mod),
595+
// Allow(Target::ForeignMod),
596+
// Allow(Target::TyAlias),
597+
// Allow(Target::Enum),
598+
// Allow(Target::Variant),
599+
// Allow(Target::Struct),
600+
// Allow(Target::Field),
601+
// Allow(Target::Union),
602+
// Allow(Target::Trait),
603+
// Allow(Target::TraitAlias),
604+
// Allow(Target::Impl { of_trait: true }),
605+
// Allow(Target::Impl { of_trait: false }),
606+
// Allow(Target::AssocConst),
607+
// Allow(Target::Method(MethodKind::Inherent)),
608+
// Allow(Target::Method(MethodKind::Trait { body: true })),
609+
// Allow(Target::Method(MethodKind::Trait { body: false })),
610+
// Allow(Target::Method(MethodKind::TraitImpl)),
611+
// Allow(Target::AssocTy),
612+
// Allow(Target::ForeignFn),
613+
// Allow(Target::ForeignStatic),
614+
// Allow(Target::ForeignTy),
615+
// Allow(Target::MacroDef),
616+
// Allow(Target::Crate),
617+
// Error(Target::WherePredicate),
618+
// ]);
617619

618620
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
619621
if self.nb_doc_attrs != 0 {

tests/ui/attributes/issue-115264-expr-field.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ struct X {
1212
fn main() {
1313
let _ = X {
1414
#[doc(alias = "StructItem")]
15-
//~^ WARN: attribute cannot be used on struct fields
16-
//~| WARN: this was previously accepted by the compiler but is being phased out
1715
foo: 123,
1816
};
1917
}

tests/ui/attributes/issue-115264-expr-field.stderr

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/ui/attributes/issue-115264-pat-field.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ struct X {
1212
fn main() {
1313
let X {
1414
#[doc(alias = "StructItem")]
15-
//~^ WARN: attribute cannot be used on pattern fields
16-
//~| WARN: this was previously accepted by the compiler but is being phased out
1715
foo
1816
} = X {
1917
foo: 123

tests/ui/attributes/issue-115264-pat-field.stderr

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/ui/lint/unused/useless-comment.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ fn foo() {
1818
/// a //~ ERROR unused doc comment
1919
#[doc(test(attr(allow(dead_code))))]
2020
//~^ ERROR unused doc comment
21-
//~| ERROR `#[doc]` attribute cannot be used on statements
22-
//~| WARN this was previously accepted by the compiler
2321
let x = 12;
2422

2523
/// multi-line //~ ERROR unused doc comment
@@ -30,8 +28,6 @@ fn foo() {
3028
1 => {},
3129
#[doc(test(attr(allow(dead_code))))]
3230
//~^ ERROR unused doc comment
33-
//~| ERROR `#[doc]` attribute cannot be used on match arms [unused_attributes]
34-
//~| WARN this was previously accepted by the compiler
3531
_ => {}
3632
}
3733

@@ -47,8 +43,6 @@ fn foo() {
4743

4844
#[doc(test(attr(allow(dead_code))))]
4945
//~^ ERROR unused doc comment
50-
//~| ERROR `#[doc]` attribute cannot be used on statements
51-
//~| WARN this was previously accepted by the compiler
5246
let x = /** comment */ 47; //~ ERROR unused doc comment
5347

5448
/// dox //~ ERROR unused doc comment

tests/ui/lint/unused/useless-comment.stderr

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LL | unsafe extern "C" { }
3333
= help: use `//` for a plain comment
3434

3535
error: unused doc comment
36-
--> $DIR/useless-comment.rs:45:5
36+
--> $DIR/useless-comment.rs:41:5
3737
|
3838
LL | /// bar
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macro invocations
@@ -56,14 +56,14 @@ error: unused doc comment
5656
|
5757
LL | #[doc(test(attr(allow(dead_code))))]
5858
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59-
...
59+
LL |
6060
LL | let x = 12;
6161
| ----------- rustdoc does not generate documentation for statements
6262
|
6363
= help: use `//` for a plain comment
6464

6565
error: unused doc comment
66-
--> $DIR/useless-comment.rs:25:5
66+
--> $DIR/useless-comment.rs:23:5
6767
|
6868
LL | / /// multi-line
6969
LL | | /// doc comment
@@ -73,15 +73,15 @@ LL | / match x {
7373
LL | | /// c
7474
LL | | 1 => {},
7575
LL | | #[doc(test(attr(allow(dead_code))))]
76-
... |
76+
LL | |
7777
LL | | _ => {}
7878
LL | | }
7979
| |_____- rustdoc does not generate documentation for expressions
8080
|
8181
= help: use `//` for a plain comment
8282

8383
error: unused doc comment
84-
--> $DIR/useless-comment.rs:29:9
84+
--> $DIR/useless-comment.rs:27:9
8585
|
8686
LL | /// c
8787
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -91,18 +91,18 @@ LL | 1 => {},
9191
= help: use `//` for a plain comment
9292

9393
error: unused doc comment
94-
--> $DIR/useless-comment.rs:31:9
94+
--> $DIR/useless-comment.rs:29:9
9595
|
9696
LL | #[doc(test(attr(allow(dead_code))))]
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98-
...
98+
LL |
9999
LL | _ => {}
100100
| ------- rustdoc does not generate documentation for match arms
101101
|
102102
= help: use `//` for a plain comment
103103

104104
error: unused doc comment
105-
--> $DIR/useless-comment.rs:38:5
105+
--> $DIR/useless-comment.rs:34:5
106106
|
107107
LL | /// foo
108108
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -112,7 +112,7 @@ LL | unsafe {}
112112
= help: use `//` for a plain comment
113113

114114
error: unused doc comment
115-
--> $DIR/useless-comment.rs:41:5
115+
--> $DIR/useless-comment.rs:37:5
116116
|
117117
LL | #[doc = "foo"]
118118
| ^^^^^^^^^^^^^^
@@ -123,7 +123,7 @@ LL | 3;
123123
= help: use `//` for a plain comment
124124

125125
error: unused doc comment
126-
--> $DIR/useless-comment.rs:42:5
126+
--> $DIR/useless-comment.rs:38:5
127127
|
128128
LL | #[doc = "bar"]
129129
| ^^^^^^^^^^^^^^
@@ -133,26 +133,26 @@ LL | 3;
133133
= help: use `//` for a plain comment
134134

135135
error: unused doc comment
136-
--> $DIR/useless-comment.rs:48:5
136+
--> $DIR/useless-comment.rs:44:5
137137
|
138138
LL | #[doc(test(attr(allow(dead_code))))]
139139
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
140-
...
140+
LL |
141141
LL | let x = /** comment */ 47;
142142
| -------------------------- rustdoc does not generate documentation for statements
143143
|
144144
= help: use `//` for a plain comment
145145

146146
error: unused doc comment
147-
--> $DIR/useless-comment.rs:52:13
147+
--> $DIR/useless-comment.rs:46:13
148148
|
149149
LL | let x = /** comment */ 47;
150150
| ^^^^^^^^^^^^^^ -- rustdoc does not generate documentation for expressions
151151
|
152152
= help: use `/* */` for a plain comment
153153

154154
error: unused doc comment
155-
--> $DIR/useless-comment.rs:54:5
155+
--> $DIR/useless-comment.rs:48:5
156156
|
157157
LL | /// dox
158158
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -163,37 +163,5 @@ LL | | }
163163
|
164164
= help: use `//` for a plain comment
165165

166-
error: `#[doc]` attribute cannot be used on statements
167-
--> $DIR/useless-comment.rs:19:5
168-
|
169-
LL | #[doc(test(attr(allow(dead_code))))]
170-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
171-
|
172-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
173-
= help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements
174-
note: the lint level is defined here
175-
--> $DIR/useless-comment.rs:4:9
176-
|
177-
LL | #![deny(unused_attributes)]
178-
| ^^^^^^^^^^^^^^^^^
179-
180-
error: `#[doc]` attribute cannot be used on match arms
181-
--> $DIR/useless-comment.rs:31:9
182-
|
183-
LL | #[doc(test(attr(allow(dead_code))))]
184-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
185-
|
186-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
187-
= help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements
188-
189-
error: `#[doc]` attribute cannot be used on statements
190-
--> $DIR/useless-comment.rs:48:5
191-
|
192-
LL | #[doc(test(attr(allow(dead_code))))]
193-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
194-
|
195-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
196-
= help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements
197-
198-
error: aborting due to 18 previous errors
166+
error: aborting due to 15 previous errors
199167

tests/ui/rustdoc/check-doc-alias-attr-location.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,14 @@ impl Foo for Bar {
2121
type X = i32;
2222
fn foo(#[doc(alias = "qux")] _x: u32) -> Self::X {
2323
//~^ ERROR
24-
//~| WARN `#[doc]` attribute cannot be used on function params
25-
//~| WARN: this was previously accepted by the compiler
2624
#[doc(alias = "stmt")]
2725
//~^ ERROR
28-
//~| WARN `#[doc]` attribute cannot be used on statements
29-
//~| WARN: this was previously accepted by the compiler
3026
let x = 0;
3127
#[doc(alias = "expr")]
3228
//~^ ERROR
33-
//~| WARN `#[doc]` attribute cannot be used on expressions
34-
//~| WARN: this was previously accepted by the compiler
3529
match x {
3630
#[doc(alias = "arm")]
3731
//~^ ERROR
38-
//~| WARN `#[doc]` attribute cannot be used on match arms
39-
//~| WARN: this was previously accepted by the compiler
4032
_ => 0
4133
}
4234
}

tests/ui/rustdoc/check-doc-alias-attr-location.stderr

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,59 +29,22 @@ LL | #[doc(alias = "assoc")]
2929
| ^^^^^^^
3030

3131
error: `#[doc(alias = "...")]` isn't allowed on statement
32-
--> $DIR/check-doc-alias-attr-location.rs:26:23
32+
--> $DIR/check-doc-alias-attr-location.rs:24:23
3333
|
3434
LL | #[doc(alias = "stmt")]
3535
| ^^^^^^
3636

3737
error: `#[doc(alias = "...")]` isn't allowed on expression
38-
--> $DIR/check-doc-alias-attr-location.rs:31:23
38+
--> $DIR/check-doc-alias-attr-location.rs:27:23
3939
|
4040
LL | #[doc(alias = "expr")]
4141
| ^^^^^^
4242

4343
error: `#[doc(alias = "...")]` isn't allowed on match arm
44-
--> $DIR/check-doc-alias-attr-location.rs:36:27
44+
--> $DIR/check-doc-alias-attr-location.rs:30:27
4545
|
4646
LL | #[doc(alias = "arm")]
4747
| ^^^^^
4848

49-
warning: `#[doc]` attribute cannot be used on function params
50-
--> $DIR/check-doc-alias-attr-location.rs:22:12
51-
|
52-
LL | fn foo(#[doc(alias = "qux")] _x: u32) -> Self::X {
53-
| ^^^^^^^^^^^^^^^^^^^^^
54-
|
55-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
56-
= help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements
57-
= note: requested on the command line with `-W unused-attributes`
58-
59-
warning: `#[doc]` attribute cannot be used on statements
60-
--> $DIR/check-doc-alias-attr-location.rs:26:9
61-
|
62-
LL | #[doc(alias = "stmt")]
63-
| ^^^^^^^^^^^^^^^^^^^^^^
64-
|
65-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
66-
= help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements
67-
68-
warning: `#[doc]` attribute cannot be used on expressions
69-
--> $DIR/check-doc-alias-attr-location.rs:31:9
70-
|
71-
LL | #[doc(alias = "expr")]
72-
| ^^^^^^^^^^^^^^^^^^^^^^
73-
|
74-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
75-
= help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements
76-
77-
warning: `#[doc]` attribute cannot be used on match arms
78-
--> $DIR/check-doc-alias-attr-location.rs:36:13
79-
|
80-
LL | #[doc(alias = "arm")]
81-
| ^^^^^^^^^^^^^^^^^^^^^
82-
|
83-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
84-
= help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements
85-
86-
error: aborting due to 8 previous errors; 4 warnings emitted
49+
error: aborting due to 8 previous errors
8750

0 commit comments

Comments
 (0)