rust - 你能弃用 Rust 中的某个属性吗?

标签 rust attributes deprecated deprecation-warning rust-proc-macros

假设我有这个宏定义:

#[proc_macro_derive(Builder, attributes(builder, group, groups))]
#[proc_macro_error]
pub fn derive_builder(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    // -- snip --
}

我想弃用group,并让用户使用groups。你不能简单地这样做:

#[proc_macro_derive(Builder, attributes(builder, #[deprecated] group, groups))]

抛出警告目前只有 available on nightly

如何告诉用户逐步停止使用group

最佳答案

就像compile_error!()一样,扩展为对已弃用函数的调用。也许,最好的方法是从宏的支持库中使用已弃用的导出函数:

#[deprecated = "the `group` attribute is deprecated. Use `groups` instead"]
#[doc(hidden)]
pub const fn group() {}

并扩展到类似:

const _: () = ::my_crate::group();

当然,请确保设置正确的跨度,以便错误指向正确的位置。

关于rust - 你能弃用 Rust 中的某个属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77267611/

相关文章:

rust - 有没有办法让拍手使用文件中的默认值?

Python 类 : linked attributes

colors - 将颜色属性添加到 NetworkX 上的节点以导出到 Gephi

php - 已弃用的 PHP 函数的替代方法 : eregi_replace

java - 当 @SuppressWarnings ("deprecation") 不起作用时如何避免弃用警告?

rust - 如何使用 match 以保证非详尽且不需要克隆的方式修改可变变量?

rust - 使用 Rust 在 PATH 中查找可执行文件

javascript - 如何向现有的 html 元素或 div 添加新的数据属性?

c++ - 请帮助 : [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]

image - Rust 打开文件扩展名以外格式的图像