summaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAlberto Planas <aplanas@suse.com>2021-09-17 11:34:11 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2021-11-26 02:36:23 +0100
commit04f5c0715832feee6c059128cd5cd70056e861f7 (patch)
tree016cfe995140081fa587878a3c3b25a43ac88ea3 /src/codegen
parent302b4842a39ed3a50d3d4dc8b3d2ce066b40fd83 (diff)
Drop 'static for pub const strings for rustc>1.17
Constant and static declaration have a 'static live time by default, that is already elided since 1.17. Clippy complains on this kind of strings that are present in the generated code. This patch remove the 'static live time for those strings when rustc > 1.17 via a new added RustFeature. Fix #1612 Signed-off-by: Alberto Planas <aplanas@suse.com>
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/mod.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index b703a106..19886e3d 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -665,10 +665,21 @@ impl CodeGenerator for Var {
match String::from_utf8(bytes.clone()) {
Ok(string) => {
let cstr = helpers::ast_ty::cstr_expr(string);
- result.push(quote! {
- #(#attrs)*
- pub const #canonical_ident : &'static #ty = #cstr ;
- });
+ if ctx
+ .options()
+ .rust_features
+ .static_lifetime_elision
+ {
+ result.push(quote! {
+ #(#attrs)*
+ pub const #canonical_ident : &#ty = #cstr ;
+ });
+ } else {
+ result.push(quote! {
+ #(#attrs)*
+ pub const #canonical_ident : &'static #ty = #cstr ;
+ });
+ }
}
Err(..) => {
let bytes = helpers::ast_ty::byte_array_expr(bytes);