Skip to content

Commit ed109e1

Browse files
Implement macro-based deref!() syntax for deref patterns
Stop using `box PAT` syntax for deref patterns, as it's misleading and also causes their semantics being tangled up.
1 parent 88ef094 commit ed109e1

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

core/src/macros/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,18 @@ pub(crate) mod builtin {
17141714
builtin # type_ascribe($expr, $ty)
17151715
}
17161716

1717+
#[cfg(not(bootstrap))]
1718+
/// Unstable placeholder for deref patterns.
1719+
#[allow_internal_unstable(builtin_syntax)]
1720+
#[unstable(
1721+
feature = "deref_patterns",
1722+
issue = "87121",
1723+
reason = "placeholder syntax for deref patterns"
1724+
)]
1725+
pub macro deref($pat:pat) {
1726+
builtin # deref($pat)
1727+
}
1728+
17171729
/// Unstable implementation detail of the `rustc` compiler, do not use.
17181730
#[rustc_builtin_macro]
17191731
#[stable(feature = "rust1", since = "1.0.0")]

core/src/prelude/v1.rs

+8
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,11 @@ pub use crate::macros::builtin::cfg_eval;
103103
reason = "placeholder syntax for type ascription"
104104
)]
105105
pub use crate::macros::builtin::type_ascribe;
106+
107+
#[cfg(not(bootstrap))]
108+
#[unstable(
109+
feature = "deref_patterns",
110+
issue = "87121",
111+
reason = "placeholder syntax for deref patterns"
112+
)]
113+
pub use crate::macros::builtin::deref;

std/src/prelude/v1.rs

+9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ pub use core::prelude::v1::cfg_eval;
9191
)]
9292
pub use core::prelude::v1::type_ascribe;
9393

94+
#[cfg(not(bootstrap))]
95+
// Do not `doc(no_inline)` either.
96+
#[unstable(
97+
feature = "deref_patterns",
98+
issue = "87121",
99+
reason = "placeholder syntax for deref patterns"
100+
)]
101+
pub use core::prelude::v1::deref;
102+
94103
// The file so far is equivalent to core/src/prelude/v1.rs. It is duplicated
95104
// rather than glob imported because we want docs to show these re-exports as
96105
// pointing to within `std`.

0 commit comments

Comments
 (0)