Fix elided_lifetimes_in_associated_constant compiler warning.
Will become an error in a future rust release. https://github.com/rust-lang/rust/issues/115010
This commit is contained in:
parent
e81f706abe
commit
39b9f59fe7
|
|
@ -700,10 +700,21 @@ pub fn generate_rust_msg(module_: &str, prefix_: &str, name_: &str) -> proc_macr
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
.map(|(const_name, typ)| {
|
.map(|(const_name, typ)| {
|
||||||
let typ: Box<syn::Type> = syn::parse_str(typ).unwrap();
|
|
||||||
let const_name = format_ident!("{const_name}");
|
let const_name = format_ident!("{const_name}");
|
||||||
let value = format_ident!("{key}__{const_name}");
|
let value = format_ident!("{key}__{const_name}");
|
||||||
quote! { pub const #const_name: #typ = #value; }
|
if let Ok(mut typ) = syn::parse_str::<Box<syn::TypeReference>>(typ) {
|
||||||
|
// If the constant is a reference, rustc needs it to be static.
|
||||||
|
// (see https://github.com/rust-lang/rust/issues/115010)
|
||||||
|
typ.lifetime = Some(syn::Lifetime::new("'static", proc_macro2::Span::call_site()));
|
||||||
|
quote! { pub const #const_name: #typ = #value; }
|
||||||
|
}
|
||||||
|
else if let Ok(typ) = syn::parse_str::<Box<syn::Type>>(typ) {
|
||||||
|
// Value
|
||||||
|
quote! { pub const #const_name: #typ = #value; }
|
||||||
|
} else {
|
||||||
|
// Something else, hope for the best but will most likely fail to compile.
|
||||||
|
quote! { pub const #const_name: #typ = #value; }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue