Repository: jaemk/cached (language: rust)

Issue:
nightly rust (1.64.0) reports cached functions as dead code.
Hello there,

First, thanks for this crate, using it with Vaultwarden to speedup some calls which works great.

I sometimes test future clippy results and see if i can fix them upfront already.
When i tried this with the current nightly v1.64.0, it reports that the functions which are cached are dead-code, and during compile it reports those functions are never used. Now i don't know if this is something related to a new way Rust works, or that something need to be changed to this crate maybe.

It looks like false positives to me, since it seem to still work.

This isn't happening on `stable` or `beta`, only on `nightly`.



Discussion / hints:
Thanks for reporting! Maybe we need to add an `#[allow(unused)]` or whatever the flag is to all the generated methods, here's one spot for example https://github.com/jaemk/cached/blob/1d5cf0b28c4ae67af4728c14aec9ef6a8c297968/cached_proc_macro/src/lib.rs#L464
The report is for `*_prime_cache` functions.
So I think it's the lines like this one, then:
https://github.com/jaemk/cached/blob/1d5cf0b28c4ae67af4728c14aec9ef6a8c297968/cached_proc_macro/src/lib.rs#L477

Fix patch:
diff --git a/cached_proc_macro/src/lib.rs b/cached_proc_macro/src/lib.rs
index 6f707d2..8517842 100644
--- a/cached_proc_macro/src/lib.rs
+++ b/cached_proc_macro/src/lib.rs
@@ -475,6 +475,7 @@ pub fn cached(args: TokenStream, input: TokenStream) -> TokenStream {
             }
             // Prime cached function
             #[doc = #prime_fn_indent_doc]
+            #[allow(dead_code)]
             #visibility #prime_sig {
                 use cached::Cached;
                 let key = #key_convert_block;
@@ -502,6 +503,7 @@ pub fn cached(args: TokenStream, input: TokenStream) -> TokenStream {
             }
             // Prime cached function
             #[doc = #prime_fn_indent_doc]
+            #[allow(dead_code)]
             #visibility #prime_sig {
                 use cached::Cached;
                 let key = #key_convert_block;
@@ -925,6 +927,7 @@ pub fn once(args: TokenStream, input: TokenStream) -> TokenStream {
             }
             // Prime cached function
             #[doc = #prime_fn_indent_doc]
+            #[allow(dead_code)]
             #visibility #prime_sig {
                 let now = ::cached::instant::Instant::now();
                 #prime_do_set_return_block
@@ -950,6 +953,7 @@ pub fn once(args: TokenStream, input: TokenStream) -> TokenStream {
             }
             // Prime cached function
             #[doc = #prime_fn_indent_doc]
+            #[allow(dead_code)]
             #visibility #prime_sig {
                 let now = ::cached::instant::Instant::now();
                 #prime_do_set_return_block
@@ -1467,6 +1471,7 @@ pub fn io_cached(args: TokenStream, input: TokenStream) -> TokenStream {
             }
             // Prime cached function
             #[doc = #prime_fn_indent_doc]
+            #[allow(dead_code)]
             #visibility #prime_sig {
                 use cached::IOCachedAsync;
                 let key = #key_convert_block;
@@ -1494,6 +1499,7 @@ pub fn io_cached(args: TokenStream, input: TokenStream) -> TokenStream {
             }
             // Prime cached function
             #[doc = #prime_fn_indent_doc]
+            #[allow(dead_code)]
             #visibility #prime_sig {
                 use cached::IOCached;
                 let key = #key_convert_block;


Test patch: