From 7f8dbf098b2b1876dba38e39c46589e7736926d9 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 2 Aug 2021 11:42:28 -0700 Subject: [PATCH] Remove `#[path]` example from 1.54 blog post. --- posts/2021-07-29-Rust-1.54.0.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/posts/2021-07-29-Rust-1.54.0.md b/posts/2021-07-29-Rust-1.54.0.md index aae548ea8..7bfa75966 100644 --- a/posts/2021-07-29-Rust-1.54.0.md +++ b/posts/2021-07-29-Rust-1.54.0.md @@ -33,11 +33,29 @@ Rust 1.54 supports invoking function-like macros inside attributes. Function-lik #![doc = include_str!("README.md")] ``` -Macros can be nested inside the attribute as well, for example to include content generated by a build script: +Macros can be nested inside the attribute as well. +For example, the `concat!` macro can be used to construct a doc comment from within a macro that uses `stringify!` to include substitutions: ```rust -#[path = concat!(env!("OUT_DIR"), "/generated.rs")] -mod generated; +macro_rules! make_function { + ($name:ident, $value:expr) => { + #[doc = concat!("The `", stringify!($name), "` example.")] + /// + /// # Example + /// + /// ``` + #[doc = concat!( + "assert_eq!(", module_path!(), "::", stringify!($name), "(), ", + stringify!($value), ");") + ] + /// ``` + pub fn $name() -> i32 { + $value + } + }; +} + +make_function! {func_name, 123} ``` Read [here](https://github.com/rust-lang/rust/pull/83366) for more details.