Skip to content

Commit

Permalink
Resolve unused field of ReplaceSelf syntax tree visitor
Browse files Browse the repository at this point in the history
    warning: field `0` is never read
      --> src/receiver.rs:81:24
       |
    81 | pub struct ReplaceSelf(pub Span);
       |            ----------- ^^^^^^^^
       |            |
       |            field in this struct
       |
       = note: `#[warn(dead_code)]` on by default
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
       |
    81 | pub struct ReplaceSelf(());
       |                        ~~
  • Loading branch information
dtolnay committed Mar 24, 2024
1 parent cd8286b commit 82cb95c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ fn transform_sig(
// ___ret
// })
fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
let mut self_span = None;
let mut replace_self = false;
let decls = sig
.inputs
.iter()
Expand All @@ -346,8 +346,8 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
mutability,
..
}) => {
replace_self = true;
let ident = Ident::new("__self", self_token.span);
self_span = Some(self_token.span);
quote!(let #mutability #ident = #self_token;)
}
FnArg::Typed(arg) => {
Expand Down Expand Up @@ -389,9 +389,8 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
})
.collect::<Vec<_>>();

if let Some(span) = self_span {
let mut replace_self = ReplaceSelf(span);
replace_self.visit_block_mut(block);
if replace_self {
ReplaceSelf.visit_block_mut(block);
}

let stmts = &block.stmts;
Expand Down
4 changes: 2 additions & 2 deletions src/receiver.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use proc_macro2::{Group, Span, TokenStream, TokenTree};
use proc_macro2::{Group, TokenStream, TokenTree};
use syn::visit_mut::{self, VisitMut};
use syn::{
Block, ExprPath, Ident, Item, Macro, Pat, PatIdent, Path, Receiver, Signature, Token, TypePath,
Expand Down Expand Up @@ -78,7 +78,7 @@ impl VisitMut for HasSelf {
}
}

pub struct ReplaceSelf(pub Span);
pub struct ReplaceSelf;

impl ReplaceSelf {
#[cfg_attr(not(self_span_hack), allow(clippy::unused_self))]
Expand Down

0 comments on commit 82cb95c

Please sign in to comment.