From 315fd9005c8294ecf2d9cce84d1d5a53da656b19 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 7 Jul 2024 13:16:41 -0700 Subject: [PATCH 1/2] Turn off syn/clone-impls feature --- Cargo.toml | 2 +- src/expand.rs | 4 ++-- src/lifetime.rs | 6 +++--- src/receiver.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a4cbd72..c1ef661 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0.74" quote = "1.0.35" -syn = { version = "2.0.46", default-features = false, features = ["full", "visit-mut", "parsing", "printing", "proc-macro", "clone-impls"] } +syn = { version = "2.0.46", default-features = false, features = ["full", "visit-mut", "parsing", "printing", "proc-macro"] } [dev-dependencies] futures = "0.3.30" diff --git a/src/expand.rs b/src/expand.rs index 793e084..5bbf2bd 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -169,8 +169,8 @@ fn transform_sig( sig.fn_token.span = sig.asyncness.take().unwrap().span; let (ret_arrow, ret) = match &sig.output { - ReturnType::Default => (Token![->](Span::call_site()), quote!(())), - ReturnType::Type(arrow, ret) => (*arrow, quote!(#ret)), + ReturnType::Default => (quote!(->), quote!(())), + ReturnType::Type(arrow, ret) => (quote!(#arrow), quote!(#ret)), }; let mut lifetimes = CollectLifetimes::new(); diff --git a/src/lifetime.rs b/src/lifetime.rs index a7babfb..6065861 100644 --- a/src/lifetime.rs +++ b/src/lifetime.rs @@ -19,7 +19,7 @@ impl CollectLifetimes { } } - fn visit_opt_lifetime(&mut self, reference: Token![&], lifetime: &mut Option) { + fn visit_opt_lifetime(&mut self, reference: &Token![&], lifetime: &mut Option) { match lifetime { None => *lifetime = Some(self.next_lifetime(reference.span)), Some(lifetime) => self.visit_lifetime(lifetime), @@ -45,14 +45,14 @@ impl CollectLifetimes { impl VisitMut for CollectLifetimes { fn visit_receiver_mut(&mut self, arg: &mut Receiver) { if let Some((reference, lifetime)) = &mut arg.reference { - self.visit_opt_lifetime(*reference, lifetime); + self.visit_opt_lifetime(reference, lifetime); } else { visit_mut::visit_type_mut(self, &mut arg.ty); } } fn visit_type_reference_mut(&mut self, ty: &mut TypeReference) { - self.visit_opt_lifetime(ty.and_token, &mut ty.lifetime); + self.visit_opt_lifetime(&ty.and_token, &mut ty.lifetime); visit_mut::visit_type_reference_mut(self, ty); } diff --git a/src/receiver.rs b/src/receiver.rs index e4627f1..1531be6 100644 --- a/src/receiver.rs +++ b/src/receiver.rs @@ -42,8 +42,8 @@ struct HasMutPat(Option); impl VisitMut for HasMutPat { fn visit_pat_ident_mut(&mut self, i: &mut PatIdent) { - if let Some(m) = i.mutability { - self.0 = Some(m); + if let Some(m) = &i.mutability { + self.0 = Some(Token![mut](m.span)); } else { visit_mut::visit_pat_ident_mut(self, i); } From b6c606384471c26a06852c0586304965237c0b95 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 7 Jul 2024 13:17:49 -0700 Subject: [PATCH 2/2] Ignore trivially_copy_pass_by_ref pedantic clippy lint When syn/clone-impls isn't enabled, this type is not Copy. warning: this argument (4 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> src/lifetime.rs:22:49 | 22 | fn visit_opt_lifetime(&mut self, reference: &Token![&], lifetime: &mut Option) { | ^^^^^^^^^^ help: consider passing by value instead: `$crate::token::And` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref = note: `-W clippy::trivially-copy-pass-by-ref` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::trivially_copy_pass_by_ref)]` --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index cc8b628..6983455 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -327,7 +327,8 @@ clippy::module_name_repetitions, clippy::shadow_unrelated, clippy::similar_names, - clippy::too_many_lines + clippy::too_many_lines, + clippy::trivially_copy_pass_by_ref )] extern crate proc_macro;