Skip to content

Commit 4d6f12b

Browse files
Add tests for duplicated usage of doc(auto_cfg) and doc(no_auto_cfg)
1 parent af26fea commit 4d6f12b

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

compiler/rustc_passes/src/check_attr.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,12 @@ impl CheckAttrVisitor<'_> {
949949

950950
/// Checks that `doc(auto_cfg)` is valid (i.e. no value) and warn if it's used whereas the
951951
/// "equivalent feature" is already enabled.
952-
fn check_auto_cfg(&self, meta: &MetaItem, hir_id: HirId, seen: &mut FxHashMap<Symbol, Span>) -> bool {
952+
fn check_auto_cfg(
953+
&self,
954+
meta: &MetaItem,
955+
hir_id: HirId,
956+
seen: &mut FxHashMap<Symbol, Span>,
957+
) -> bool {
953958
let name = meta.name_or_empty();
954959
if !meta.is_word() {
955960
self.tcx
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// edition: 2021
22
#![deny(warnings)]
3-
#![doc(no_auto_cfg)]
4-
/*#![doc(no_auto_cfg(1))] //~ ERROR
3+
#![doc(no_auto_cfg)] //~ ERROR
4+
//~^ ERROR
5+
#![doc(auto_cfg, no_auto_cfg)] //~ ERROR
6+
#![doc(no_auto_cfg(1))] //~ ERROR
57
#![doc(no_auto_cfg = 1)] //~ ERROR
68
#![doc(auto_cfg(1))] //~ ERROR
79
#![doc(auto_cfg = 1)] //~ ERROR
@@ -10,4 +12,4 @@
1012
//~^ WARN
1113
#[doc(no_auto_cfg)] //~ ERROR
1214
//~^ WARN
13-
pub struct Bar;*/
15+
pub struct Bar;

src/test/rustdoc-ui/doc_no_auto_cfg.stderr

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this attribute can only be applied at the crate level
2-
--> $DIR/doc_no_auto_cfg.rs:9:7
2+
--> $DIR/doc_no_auto_cfg.rs:11:7
33
|
44
LL | #[doc(auto_cfg)]
55
| ^^^^^^^^
@@ -19,7 +19,7 @@ LL | #![doc(auto_cfg)]
1919
| ~~~~~~~~~~~~~~~~~
2020

2121
error: this attribute can only be applied at the crate level
22-
--> $DIR/doc_no_auto_cfg.rs:11:7
22+
--> $DIR/doc_no_auto_cfg.rs:13:7
2323
|
2424
LL | #[doc(no_auto_cfg)]
2525
| ^^^^^^^^^^^
@@ -32,29 +32,52 @@ help: to apply to the crate, use an inner attribute
3232
LL | #![doc(no_auto_cfg)]
3333
| ~~~~~~~~~~~~~~~~~~~~
3434

35+
error: `doc(no_auto_cfg)` is enabled by default before the 2024 edition
36+
--> $DIR/doc_no_auto_cfg.rs:3:8
37+
|
38+
LL | #![doc(no_auto_cfg)]
39+
| ^^^^^^^^^^^
40+
|
41+
= note: `#[deny(unused_attributes)]` implied by `#[deny(warnings)]`
42+
43+
error: `doc(no_auto_cfg)` is enabled by default before the 2024 edition
44+
--> $DIR/doc_no_auto_cfg.rs:5:18
45+
|
46+
LL | #![doc(auto_cfg, no_auto_cfg)]
47+
| ^^^^^^^^^^^
48+
49+
error: please don't specify both `doc(auto_cfg)` and `doc(no_auto_cfg)`
50+
--> $DIR/doc_no_auto_cfg.rs:3:8
51+
|
52+
LL | #![doc(no_auto_cfg)]
53+
| ^^^^^^^^^^^
54+
LL |
55+
LL | #![doc(auto_cfg, no_auto_cfg)]
56+
| ----------- the other is specified here
57+
3558
error: `#![doc(no_auto_cfg)]` attribute doesn't expect a value
36-
--> $DIR/doc_no_auto_cfg.rs:4:8
59+
--> $DIR/doc_no_auto_cfg.rs:6:8
3760
|
3861
LL | #![doc(no_auto_cfg(1))]
3962
| ^^^^^^^^^^^^^^
4063

4164
error: `#![doc(no_auto_cfg)]` attribute doesn't expect a value
42-
--> $DIR/doc_no_auto_cfg.rs:5:8
65+
--> $DIR/doc_no_auto_cfg.rs:7:8
4366
|
4467
LL | #![doc(no_auto_cfg = 1)]
4568
| ^^^^^^^^^^^^^^^
4669

4770
error: `#![doc(auto_cfg)]` attribute doesn't expect a value
48-
--> $DIR/doc_no_auto_cfg.rs:6:8
71+
--> $DIR/doc_no_auto_cfg.rs:8:8
4972
|
5073
LL | #![doc(auto_cfg(1))]
5174
| ^^^^^^^^^^^
5275

5376
error: `#![doc(auto_cfg)]` attribute doesn't expect a value
54-
--> $DIR/doc_no_auto_cfg.rs:7:8
77+
--> $DIR/doc_no_auto_cfg.rs:9:8
5578
|
5679
LL | #![doc(auto_cfg = 1)]
5780
| ^^^^^^^^^^^^
5881

59-
error: aborting due to 6 previous errors
82+
error: aborting due to 9 previous errors
6083

0 commit comments

Comments
 (0)