about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-10-06 17:00:02 +0000
committerbors <bors@rust-lang.org>2024-10-06 17:00:02 +0000
commit8422e27b276fade36294d3ba13a754cf48459c7a (patch)
treef198ab12983956b96dbf4274816291c3ba6f5a75 /tests
parent373971abe48287f47ead6304b19279f34b6fcce5 (diff)
parent00ed47b8496bacb9da0196127508e07ba5d14bb4 (diff)
Auto merge of #129670 - est31:cfg_attr_crate_type_name_error, r=Urgau
Make deprecated_cfg_attr_crate_type_name a hard error

Turns the forward compatibility lint added by #83744 into a hard error, so now, while the `#![crate_name]` and `#![crate_type]` attributes are still allowed in raw form, they are now forbidden to be nested inside a `#![cfg_attr()]` attribute.

The following will now be an error:

```Rust
#![cfg_attr(foo, crate_name = "foobar")]
#![cfg_attr(foo, crate_type = "bin")]
```

This code will continue working and is not deprecated:

```Rust
#![crate_name = "foobar"]
#![crate_type = "lib"]
```

The reasoning for this is explained in #83744: it allows us to not have to cfg-expand in order to determine the crate's type and name.

As of filing the PR, exactly two years have passed since #99784 has been merged, which has turned the lint's default warning level into an error, so there has been ample time to move off the now-forbidden syntax.

cc #91632 - tracking issue for the lint
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/cfg/crate-attributes-using-cfg_attr.rs (renamed from tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.rs)4
-rw-r--r--tests/ui/cfg/crate-attributes-using-cfg_attr.stderr30
-rw-r--r--tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr41
3 files changed, 30 insertions, 45 deletions
diff --git a/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.rs b/tests/ui/cfg/crate-attributes-using-cfg_attr.rs
index 3ced3a630e3..f99fad881f2 100644
--- a/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.rs
+++ b/tests/ui/cfg/crate-attributes-using-cfg_attr.rs
@@ -3,13 +3,9 @@
 
 #![cfg_attr(foo, crate_type="bin")]
 //~^ERROR `crate_type` within
-//~| WARN this was previously accepted
 //~|ERROR `crate_type` within
-//~| WARN this was previously accepted
 #![cfg_attr(foo, crate_name="bar")]
 //~^ERROR `crate_name` within
-//~| WARN this was previously accepted
 //~|ERROR `crate_name` within
-//~| WARN this was previously accepted
 
 fn main() {}
diff --git a/tests/ui/cfg/crate-attributes-using-cfg_attr.stderr b/tests/ui/cfg/crate-attributes-using-cfg_attr.stderr
new file mode 100644
index 00000000000..1dfca2b88d0
--- /dev/null
+++ b/tests/ui/cfg/crate-attributes-using-cfg_attr.stderr
@@ -0,0 +1,30 @@
+error: `crate_type` within an `#![cfg_attr]` attribute is forbidden
+  --> $DIR/crate-attributes-using-cfg_attr.rs:4:18
+   |
+LL | #![cfg_attr(foo, crate_type="bin")]
+   |                  ^^^^^^^^^^^^^^^^
+
+error: `crate_name` within an `#![cfg_attr]` attribute is forbidden
+  --> $DIR/crate-attributes-using-cfg_attr.rs:7:18
+   |
+LL | #![cfg_attr(foo, crate_name="bar")]
+   |                  ^^^^^^^^^^^^^^^^
+
+error: `crate_type` within an `#![cfg_attr]` attribute is forbidden
+  --> $DIR/crate-attributes-using-cfg_attr.rs:4:18
+   |
+LL | #![cfg_attr(foo, crate_type="bin")]
+   |                  ^^^^^^^^^^^^^^^^
+   |
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+
+error: `crate_name` within an `#![cfg_attr]` attribute is forbidden
+  --> $DIR/crate-attributes-using-cfg_attr.rs:7:18
+   |
+LL | #![cfg_attr(foo, crate_name="bar")]
+   |                  ^^^^^^^^^^^^^^^^
+   |
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+
+error: aborting due to 4 previous errors
+
diff --git a/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr b/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr
deleted file mode 100644
index 82b2d7d1b1d..00000000000
--- a/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr
+++ /dev/null
@@ -1,41 +0,0 @@
-error: `crate_type` within an `#![cfg_attr]` attribute is deprecated
-  --> $DIR/future-compat-crate-attributes-using-cfg_attr.rs:4:18
-   |
-LL | #![cfg_attr(foo, crate_type="bin")]
-   |                  ^^^^^^^^^^^^^^^^
-   |
-   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632>
-   = note: `#[deny(deprecated_cfg_attr_crate_type_name)]` on by default
-
-error: `crate_name` within an `#![cfg_attr]` attribute is deprecated
-  --> $DIR/future-compat-crate-attributes-using-cfg_attr.rs:9:18
-   |
-LL | #![cfg_attr(foo, crate_name="bar")]
-   |                  ^^^^^^^^^^^^^^^^
-   |
-   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632>
-
-error: `crate_type` within an `#![cfg_attr]` attribute is deprecated
-  --> $DIR/future-compat-crate-attributes-using-cfg_attr.rs:4:18
-   |
-LL | #![cfg_attr(foo, crate_type="bin")]
-   |                  ^^^^^^^^^^^^^^^^
-   |
-   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632>
-   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
-
-error: `crate_name` within an `#![cfg_attr]` attribute is deprecated
-  --> $DIR/future-compat-crate-attributes-using-cfg_attr.rs:9:18
-   |
-LL | #![cfg_attr(foo, crate_name="bar")]
-   |                  ^^^^^^^^^^^^^^^^
-   |
-   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632>
-   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
-
-error: aborting due to 4 previous errors
-