Skip to content

Commit 37a35c5

Browse files
bors[bot]toasteater
andauthored
Merge #701
701: Add automatically_derived and allow lints in macros r=toasteater a=toasteater This should prevent clippy lints from showing up in user code in the future. See: - https://doc.rust-lang.org/reference/attributes/derive.html - https://doc.rust-lang.org/rustc/lints/groups.html - https://github.com/rust-lang/rust-clippy#clippy Co-authored-by: toasteater <48371905+toasteater@users.noreply.github.com>
2 parents 50794d0 + 29f33e1 commit 37a35c5

File tree

7 files changed

+31
-4
lines changed

7 files changed

+31
-4
lines changed

gdnative-core/src/nativescript/macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ macro_rules! godot_wrap_method_inner {
101101
use ::gdnative::FromVarargs;
102102

103103
#[derive(FromVarargs)]
104+
#[allow(clippy::used_underscore_binding)]
104105
struct Args {
105106
$($pname: $pty,)*
106107
$(#[opt] $opt_pname: $opt_pty,)*

gdnative-derive/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,18 @@ pub fn derive_from_varargs(input: TokenStream) -> TokenStream {
243243
Err(err) => err.to_compile_error().into(),
244244
}
245245
}
246+
247+
/// Returns a standard header for derived implementations.
248+
///
249+
/// Adds the `automatically_derived` attribute and prevents common lints from triggering
250+
/// in user code. See:
251+
///
252+
/// - https://doc.rust-lang.org/reference/attributes/derive.html
253+
/// - https://doc.rust-lang.org/rustc/lints/groups.html
254+
/// - https://github.com/rust-lang/rust-clippy#clippy
255+
fn automatically_derived() -> proc_macro2::TokenStream {
256+
quote! {
257+
#[automatically_derived]
258+
#[allow(nonstandard_style, unused, clippy::style, clippy::complexity, clippy::perf, clippy::pedantic)]
259+
}
260+
}

gdnative-derive/src/methods.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub(crate) struct ExportArgs {
6868
}
6969

7070
pub(crate) fn derive_methods(item_impl: ItemImpl) -> TokenStream2 {
71+
let derived = crate::automatically_derived();
7172
let (impl_block, export) = impl_gdnative_expose(item_impl);
7273

7374
let class_name = export.class_ty;
@@ -140,9 +141,9 @@ pub(crate) fn derive_methods(item_impl: ItemImpl) -> TokenStream2 {
140141
.collect::<Vec<_>>();
141142

142143
quote::quote!(
143-
144144
#impl_block
145145

146+
#derived
146147
impl gdnative::nativescript::NativeClassMethods for #class_name {
147148
fn register(#builder: &::gdnative::nativescript::init::ClassBuilder<Self>) {
148149
use gdnative::nativescript::init::*;

gdnative-derive/src/native_script.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ pub(crate) struct DeriveData {
1818
}
1919

2020
pub(crate) fn impl_empty_nativeclass(derive_input: &DeriveInput) -> TokenStream2 {
21+
let derived = crate::automatically_derived();
2122
let name = &derive_input.ident;
2223

2324
quote! {
25+
#derived
2426
impl ::gdnative::prelude::NativeClass for #name {
2527
type Base = ::gdnative::api::Object;
2628
type UserData = ::gdnative::prelude::LocalCellData<Self>;
@@ -36,6 +38,7 @@ pub(crate) fn impl_empty_nativeclass(derive_input: &DeriveInput) -> TokenStream2
3638
}
3739

3840
pub(crate) fn derive_native_class(derive_input: &DeriveInput) -> Result<TokenStream, syn::Error> {
41+
let derived = crate::automatically_derived();
3942
let data = parse_derive_input(&derive_input)?;
4043

4144
// generate NativeClass impl
@@ -117,6 +120,7 @@ pub(crate) fn derive_native_class(derive_input: &DeriveInput) -> Result<TokenStr
117120
};
118121

119122
quote!(
123+
#derived
120124
impl ::gdnative::nativescript::NativeClass for #name {
121125
type Base = #base;
122126
type UserData = #user_data;

gdnative-derive/src/varargs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use syn::{spanned::Spanned, Data, DeriveInput, Ident};
99
use crate::extend_bounds::with_visitor;
1010

1111
pub(crate) fn derive_from_varargs(input: DeriveInput) -> Result<TokenStream2, syn::Error> {
12+
let derived = crate::automatically_derived();
13+
1214
if let Data::Struct(struct_data) = input.data {
1315
let ident = input.ident;
1416

@@ -32,6 +34,7 @@ pub(crate) fn derive_from_varargs(input: DeriveInput) -> Result<TokenStream2, sy
3234
Fields::Unnamed(fields) => &fields.unnamed,
3335
Fields::Unit => {
3436
return Ok(quote! {
37+
#derived
3538
impl #generics ::gdnative::nativescript::init::method::FromVarargs for #ident #generics #where_clause {
3639
fn read<'a>(
3740
#input_ident: &mut ::gdnative::nativescript::init::method::Varargs<'a>,
@@ -109,7 +112,7 @@ pub(crate) fn derive_from_varargs(input: DeriveInput) -> Result<TokenStream2, sy
109112
.collect::<Vec<_>>();
110113

111114
Ok(quote! {
112-
#[allow(unused_variables)]
115+
#derived
113116
impl #generics ::gdnative::nativescript::init::method::FromVarargs for #ident #generics #where_clause {
114117
fn read<'a>(
115118
#input_ident: &mut ::gdnative::nativescript::init::method::Varargs<'a>,

gdnative-derive/src/variant/from.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub(crate) fn expand_from_variant(derive_data: DeriveData) -> Result<TokenStream
1212
mut generics,
1313
} = derive_data;
1414

15+
let derived = crate::automatically_derived();
16+
1517
for param in generics.type_params_mut() {
1618
param.default = None;
1719
}
@@ -106,7 +108,7 @@ pub(crate) fn expand_from_variant(derive_data: DeriveData) -> Result<TokenStream
106108
let where_clause = &generics.where_clause;
107109

108110
let result = quote! {
109-
#[allow(unused_variables)]
111+
#derived
110112
impl #generics ::gdnative::core_types::FromVariant for #ident #generics #where_clause {
111113
fn from_variant(
112114
#input_ident: &::gdnative::core_types::Variant

gdnative-derive/src/variant/to.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub(crate) fn expand_to_variant(
1616
let trait_path = trait_kind.trait_path();
1717
let to_variant_fn = trait_kind.to_variant_fn();
1818
let to_variant_receiver = trait_kind.to_variant_receiver();
19+
let derived = crate::automatically_derived();
1920

2021
for param in generics.type_params_mut() {
2122
param.default = None;
@@ -71,7 +72,7 @@ pub(crate) fn expand_to_variant(
7172
let where_clause = &generics.where_clause;
7273

7374
let result = quote! {
74-
#[allow(unused_variables)]
75+
#derived
7576
impl #generics #trait_path for #ident #generics #where_clause {
7677
fn #to_variant_fn(#to_variant_receiver) -> ::gdnative::core_types::Variant {
7778
use #trait_path;

0 commit comments

Comments
 (0)