Skip to content

Commit

Permalink
Deprecate the unstable concat_idents!
Browse files Browse the repository at this point in the history
`concat_idents` has been around unstably for a long time, but there is
now a better (but still unstable) way to join identifiers using
`${concat(...)}` syntax with `macro_metavar_expr_concat`. This resolves
a lot of the problems with `concat_idents` and is on a better track
toward stabilization, so there is no need to keep both versions around.
`concat_idents!` still has a lot of use in the ecosystem so deprecate it
before removing, as discussed in [1].

Link: rust-lang#124225
[1]: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Removing.20.60concat_idents.60
  • Loading branch information
tgross35 committed Feb 26, 2025
1 parent cb06d12 commit 4f7ea23
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 42 deletions.
4 changes: 4 additions & 0 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,10 @@ pub(crate) mod builtin {
issue = "29599",
reason = "`concat_idents` is not stable enough for use and is subject to change"
)]
#[deprecated(
since = "1.87.0",
note = "use `${concat(...)}` with the `macro_metavar_expr_concat` feature instead"
)]
#[rustc_builtin_macro]
#[macro_export]
macro_rules! concat_idents {
Expand Down
1 change: 1 addition & 0 deletions library/core/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub use crate::hash::macros::Hash;

#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow(deprecated)]
#[cfg_attr(bootstrap, allow(deprecated_in_future))]
#[doc(no_inline)]
pub use crate::{
assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ pub use core::primitive;
// Re-export built-in macros defined through core.
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow(deprecated)]
#[cfg_attr(bootstrap, allow(deprecated_in_future))]
pub use core::{
assert, assert_matches, cfg, column, compile_error, concat, concat_idents, const_format_args,
env, file, format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax,
Expand Down
1 change: 1 addition & 0 deletions library/std/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub use crate::result::Result::{self, Err, Ok};
// Re-exported built-in macros
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow(deprecated)]
#[cfg_attr(bootstrap, allow(deprecated_in_future))]
#[doc(no_inline)]
pub use core::prelude::v1::{
assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
Expand Down
3 changes: 3 additions & 0 deletions src/doc/unstable-book/src/library-features/concat-idents.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

The tracking issue for this feature is: [#29599]

This feature is deprecated, to be replaced by [`macro_metavar_expr_concat`].

[#29599]: https://github.com/rust-lang/rust/issues/29599
[`macro_metavar_expr_concat`]: https://github.com/rust-lang/rust/issues/124225

------------------------

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/feature-gates/feature-gate-concat_idents.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![expect(deprecated)] // concat_idents is deprecated

const XY_1: i32 = 10;

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/feature-gates/feature-gate-concat_idents.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: use of unstable library feature `concat_idents`: `concat_idents` is not stable enough for use and is subject to change
--> $DIR/feature-gate-concat_idents.rs:5:13
--> $DIR/feature-gate-concat_idents.rs:7:13
|
LL | let a = concat_idents!(X, Y_1);
| ^^^^^^^^^^^^^
Expand All @@ -9,7 +9,7 @@ LL | let a = concat_idents!(X, Y_1);
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `concat_idents`: `concat_idents` is not stable enough for use and is subject to change
--> $DIR/feature-gate-concat_idents.rs:6:13
--> $DIR/feature-gate-concat_idents.rs:8:13
|
LL | let b = concat_idents!(X, Y_2);
| ^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/feature-gates/feature-gate-concat_idents2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![expect(deprecated)] // concat_idents is deprecated

fn main() {
concat_idents!(a, b); //~ ERROR `concat_idents` is not stable enough
//~| ERROR cannot find value `ab` in this scope
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/feature-gates/feature-gate-concat_idents2.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: use of unstable library feature `concat_idents`: `concat_idents` is not stable enough for use and is subject to change
--> $DIR/feature-gate-concat_idents2.rs:2:5
--> $DIR/feature-gate-concat_idents2.rs:4:5
|
LL | concat_idents!(a, b);
| ^^^^^^^^^^^^^
Expand All @@ -9,7 +9,7 @@ LL | concat_idents!(a, b);
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0425]: cannot find value `ab` in this scope
--> $DIR/feature-gate-concat_idents2.rs:2:5
--> $DIR/feature-gate-concat_idents2.rs:4:5
|
LL | concat_idents!(a, b);
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/feature-gates/feature-gate-concat_idents3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![expect(deprecated)] // concat_idents is deprecated

const XY_1: i32 = 10;

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/feature-gates/feature-gate-concat_idents3.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: use of unstable library feature `concat_idents`: `concat_idents` is not stable enough for use and is subject to change
--> $DIR/feature-gate-concat_idents3.rs:5:20
--> $DIR/feature-gate-concat_idents3.rs:7:20
|
LL | assert_eq!(10, concat_idents!(X, Y_1));
| ^^^^^^^^^^^^^
Expand All @@ -9,7 +9,7 @@ LL | assert_eq!(10, concat_idents!(X, Y_1));
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `concat_idents`: `concat_idents` is not stable enough for use and is subject to change
--> $DIR/feature-gate-concat_idents3.rs:6:20
--> $DIR/feature-gate-concat_idents3.rs:8:20
|
LL | assert_eq!(20, concat_idents!(X, Y_2));
| ^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions tests/ui/issues/issue-32950.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(concat_idents)]
#![expect(deprecated)] // concat_idents is deprecated

#[derive(Debug)]
struct Baz<T>(
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/issues/issue-32950.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: `derive` cannot be used on items with type macros
--> $DIR/issue-32950.rs:5:5
--> $DIR/issue-32950.rs:6:5
|
LL | concat_idents!(Foo, Bar)
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0412]: cannot find type `FooBar` in this scope
--> $DIR/issue-32950.rs:5:5
--> $DIR/issue-32950.rs:6:5
|
LL | concat_idents!(Foo, Bar)
| ^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
Expand Down
1 change: 1 addition & 0 deletions tests/ui/issues/issue-50403.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(concat_idents)]
#![expect(deprecated)] // concat_idents is deprecated

fn main() {
let x = concat_idents!(); //~ ERROR `concat_idents!()` takes 1 or more arguments
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-50403.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `concat_idents!()` takes 1 or more arguments
--> $DIR/issue-50403.rs:4:13
--> $DIR/issue-50403.rs:5:13
|
LL | let x = concat_idents!();
| ^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions tests/ui/macros/macros-nonfatal-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#![feature(trace_macros, concat_idents)]
#![feature(stmt_expr_attributes)]
#![expect(deprecated)] // concat_idents is deprecated

use std::arch::asm;

Expand Down
Loading

0 comments on commit 4f7ea23

Please sign in to comment.