Skip to content

Commit 1f3b19d

Browse files
bors[bot]Bromeon
andauthored
Merge #853
853: Clippy warnings on nightly + first cargo-deny entry r=Bromeon a=Bromeon ### clippy warnings The first commit fixes warnings on nightly: ```rs Checking gdnative-derive v0.9.3 (/home/runner/work/godot-rust/godot-rust/gdnative-derive) error: methods called `from_*` usually take no `self` --> gdnative-derive/src/variant/repr.rs:174:9 | 174 | &self, | ^^^^^ | = note: `-D clippy::wrong-self-convention` implied by `-D clippy::style` = help: consider choosing a less ambiguous name = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention error: methods called `from_*` usually take no `self` --> gdnative-derive/src/variant/repr.rs:330:21 | 330 | fn from_variant(&self, variant: &TokenStream2) -> TokenStream2 { | ^^^^^ | = help: consider choosing a less ambiguous name = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention ``` --- ### cargo-deny entry After reading [this Reddit post](https://www.reddit.com/r/rust/comments/sdgcg9/unsoundness_in_owning_ref), the `owning_ref` crate seemed to be a good candidate for cargo-deny. First, it hasn't been maintained in two years, and second, there is [known unsoundness](https://github.com/noamtashma/owning-ref-unsoundness) but it's not marked in any CVE database. I'm not suggesting we go hunt down crates now, but if people come across other problematic crates, let's add them. That doesn't mean there will be a strict ban on such crates forever, but it means adding a potentially problematic dependency is a concious, opt-in process. bors try Co-authored-by: Jan Haller <[email protected]>
2 parents 42a6e76 + 668f3a1 commit 1f3b19d

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

gdnative-derive/src/variant/from.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) fn expand_from_variant(derive_data: DeriveData) -> Result<TokenStream
2222

2323
let return_expr = match repr {
2424
Repr::Struct(var_repr) => {
25-
let from_variant = var_repr.from_variant(&input_ident, &quote! { #ident })?;
25+
let from_variant = var_repr.make_from_variant_expr(&input_ident, &quote! { #ident })?;
2626
quote! {
2727
{
2828
#from_variant
@@ -54,7 +54,8 @@ pub(crate) fn expand_from_variant(derive_data: DeriveData) -> Result<TokenStream
5454
let var_from_variants = variants
5555
.iter()
5656
.map(|(var_ident, var_repr)| {
57-
var_repr.from_variant(&var_input_ident, &quote! { #ident::#var_ident })
57+
var_repr
58+
.make_from_variant_expr(&var_input_ident, &quote! { #ident::#var_ident })
5859
})
5960
.collect::<Result<Vec<_>, _>>()?;
6061

gdnative-derive/src/variant/repr.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl VariantRepr {
101101
}
102102
}
103103

104-
pub(crate) fn to_variant(
104+
pub(crate) fn make_to_variant_expr(
105105
&self,
106106
trait_kind: ToVariantTrait,
107107
) -> Result<TokenStream2, syn::Error> {
@@ -119,13 +119,13 @@ impl VariantRepr {
119119
"cannot skip the only field in a tuple",
120120
));
121121
}
122-
field.to_variant(trait_kind)
122+
field.make_to_variant_expr(trait_kind)
123123
} else {
124124
let exprs = fields.iter().filter_map(|f| {
125125
if f.attr.skip_to_variant {
126126
None
127127
} else {
128-
Some(f.to_variant(trait_kind))
128+
Some(f.make_to_variant_expr(trait_kind))
129129
}
130130
});
131131

@@ -150,7 +150,7 @@ impl VariantRepr {
150150
let name_string_literals =
151151
name_strings.iter().map(|string| Literal::string(string));
152152

153-
let exprs = fields.iter().map(|f| f.to_variant(trait_kind));
153+
let exprs = fields.iter().map(|f| f.make_to_variant_expr(trait_kind));
154154

155155
quote! {
156156
{
@@ -170,7 +170,7 @@ impl VariantRepr {
170170
Ok(tokens)
171171
}
172172

173-
pub(crate) fn from_variant(
173+
pub(crate) fn make_from_variant_expr(
174174
&self,
175175
variant: &Ident,
176176
ctor: &TokenStream2,
@@ -199,7 +199,7 @@ impl VariantRepr {
199199
"cannot skip the only field in a tuple",
200200
));
201201
}
202-
let expr = field.from_variant(&quote!(#variant));
202+
let expr = field.make_from_variant_expr(&quote!(#variant));
203203
quote! {
204204
{
205205
#expr.map(#ctor)
@@ -224,7 +224,7 @@ impl VariantRepr {
224224
let expr_variant = &quote!(&__array.get(__index));
225225
let non_skipped_exprs = non_skipped_fields
226226
.iter()
227-
.map(|f| f.from_variant(expr_variant));
227+
.map(|f| f.make_from_variant_expr(expr_variant));
228228

229229
quote! {
230230
{
@@ -283,7 +283,7 @@ impl VariantRepr {
283283
let expr_variant = &quote!(&__dict.get_or_nil(&__key));
284284
let exprs = non_skipped_fields
285285
.iter()
286-
.map(|f| f.from_variant(expr_variant));
286+
.map(|f| f.make_from_variant_expr(expr_variant));
287287

288288
quote! {
289289
{
@@ -317,7 +317,7 @@ impl VariantRepr {
317317
}
318318

319319
impl Field {
320-
fn to_variant(&self, trait_kind: ToVariantTrait) -> TokenStream2 {
320+
fn make_to_variant_expr(&self, trait_kind: ToVariantTrait) -> TokenStream2 {
321321
let Field { ident, attr, .. } = self;
322322
if let Some(to_variant_with) = &attr.to_variant_with {
323323
quote!(#to_variant_with(#ident))
@@ -327,7 +327,7 @@ impl Field {
327327
}
328328
}
329329

330-
fn from_variant(&self, variant: &TokenStream2) -> TokenStream2 {
330+
fn make_from_variant_expr(&self, variant: &TokenStream2) -> TokenStream2 {
331331
if let Some(from_variant_with) = &self.attr.from_variant_with {
332332
quote!(#from_variant_with(#variant))
333333
} else {

gdnative-derive/src/variant/to.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) fn expand_to_variant(
2525
let return_expr = match repr {
2626
Repr::Struct(var_repr) => {
2727
let destructure_pattern = var_repr.destructure_pattern();
28-
let to_variant = var_repr.to_variant(trait_kind)?;
28+
let to_variant = var_repr.make_to_variant_expr(trait_kind)?;
2929
quote! {
3030
{
3131
let #ident #destructure_pattern = self;
@@ -43,7 +43,7 @@ pub(crate) fn expand_to_variant(
4343
.iter()
4444
.map(|(var_ident, var_repr)| {
4545
let destructure_pattern = var_repr.destructure_pattern();
46-
let to_variant = var_repr.to_variant(trait_kind)?;
46+
let to_variant = var_repr.make_to_variant_expr(trait_kind)?;
4747
let var_ident_string = format!("{}", var_ident);
4848
let var_ident_string_literal = Literal::string(&var_ident_string);
4949
let tokens = quote! {

tools/deny.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,16 @@ allow = [
165165
#{ name = "ansi_term", version = "=0.11.0" },
166166
]
167167
# List of crates to deny
168+
# Each entry the name of a crate and a version range. If version is
169+
# not specified, all versions will be matched.
170+
#{ name = "ansi_term", version = "=0.11.0" },
171+
#
172+
# Wrapper crates can optionally be specified to allow the crate when it
173+
# is a direct dependency of the otherwise banned crate
174+
#{ name = "ansi_term", version = "=0.11.0", wrappers = [] },
168175
deny = [
169-
# Each entry the name of a crate and a version range. If version is
170-
# not specified, all versions will be matched.
171-
#{ name = "ansi_term", version = "=0.11.0" },
172-
#
173-
# Wrapper crates can optionally be specified to allow the crate when it
174-
# is a direct dependency of the otherwise banned crate
175-
#{ name = "ansi_term", version = "=0.11.0", wrappers = [] },
176+
# unmaintained since Feb 20 + https://github.com/noamtashma/owning-ref-unsoundness
177+
{ name = "owning_ref" },
176178
]
177179
# Certain crates/versions that will be skipped when doing duplicate detection.
178180
skip = [

0 commit comments

Comments
 (0)