Skip to content

Commit 39b9f59

Browse files
committed
Fix elided_lifetimes_in_associated_constant compiler warning.
Will become an error in a future rust release. rust-lang/rust#115010
1 parent e81f706 commit 39b9f59

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

r2r_msg_gen/src/lib.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,21 @@ pub fn generate_rust_msg(module_: &str, prefix_: &str, name_: &str) -> proc_macr
700700
.into_iter()
701701
.flatten()
702702
.map(|(const_name, typ)| {
703-
let typ: Box<syn::Type> = syn::parse_str(typ).unwrap();
704703
let const_name = format_ident!("{const_name}");
705704
let value = format_ident!("{key}__{const_name}");
706-
quote! { pub const #const_name: #typ = #value; }
705+
if let Ok(mut typ) = syn::parse_str::<Box<syn::TypeReference>>(typ) {
706+
// If the constant is a reference, rustc needs it to be static.
707+
// (see https://github.com/rust-lang/rust/issues/115010)
708+
typ.lifetime = Some(syn::Lifetime::new("'static", proc_macro2::Span::call_site()));
709+
quote! { pub const #const_name: #typ = #value; }
710+
}
711+
else if let Ok(typ) = syn::parse_str::<Box<syn::Type>>(typ) {
712+
// Value
713+
quote! { pub const #const_name: #typ = #value; }
714+
} else {
715+
// Something else, hope for the best but will most likely fail to compile.
716+
quote! { pub const #const_name: #typ = #value; }
717+
}
707718
})
708719
.collect();
709720

0 commit comments

Comments
 (0)