Skip to content

Commit 6d2527d

Browse files
authored
Merge pull request #99 from ModProg/clippy
Clippy + Typos
2 parents 567f20b + cafac83 commit 6d2527d

27 files changed

+77
-38
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ zeroize_ = { version = "1.5", package = "zeroize", default-features = false }
4747
[package.metadata.docs.rs]
4848
all-features = true
4949
targets = []
50+
51+
[workspace.metadata.typos]
52+
default.extend-words.wheres = "wheres"

src/data.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ mod field;
44
mod fields;
55

66
use proc_macro2::Span;
7-
use syn::{Expr, FieldsNamed, Ident, Pat, PatPath, Path, Result, Variant};
7+
#[cfg(not(feature = "nightly"))]
8+
use syn::Expr;
9+
use syn::{FieldsNamed, Ident, Pat, PatPath, Path, Result, Variant};
810

911
pub use self::{
1012
field::{Field, Member},
@@ -27,6 +29,7 @@ pub struct Data<'a> {
2729
pub path: Path,
2830
/// [Type](DataType) of this struct, union or variant.
2931
pub type_: DataType<'a>,
32+
#[cfg(not(feature = "nightly"))]
3033
/// Discriminant of this variant.
3134
pub discriminant: Option<&'a Expr>,
3235
}
@@ -69,7 +72,7 @@ pub enum SimpleType<'a> {
6972
/// Tuple struct or tuple variant.
7073
Tuple(&'a Fields<'a>),
7174
/// Union.
72-
Union(&'a Fields<'a>),
75+
Union,
7376
/// Unit variant.
7477
Unit(&'a Pat),
7578
}
@@ -100,6 +103,7 @@ impl<'a> Data<'a> {
100103
ident,
101104
path,
102105
type_: DataType::Struct(fields),
106+
#[cfg(not(feature = "nightly"))]
103107
discriminant: None,
104108
})
105109
}
@@ -117,6 +121,7 @@ impl<'a> Data<'a> {
117121
ident,
118122
path,
119123
type_: DataType::Tuple(fields),
124+
#[cfg(not(feature = "nightly"))]
120125
discriminant: None,
121126
})
122127
}
@@ -131,6 +136,7 @@ impl<'a> Data<'a> {
131136
qself: None,
132137
path,
133138
})),
139+
#[cfg(not(feature = "nightly"))]
134140
discriminant: None,
135141
}),
136142
syn::Fields::Unit => Err(Error::item_empty(span)),
@@ -158,6 +164,7 @@ impl<'a> Data<'a> {
158164
ident,
159165
path,
160166
type_: DataType::Union(fields),
167+
#[cfg(not(feature = "nightly"))]
161168
discriminant: None,
162169
})
163170
}
@@ -191,6 +198,7 @@ impl<'a> Data<'a> {
191198
default,
192199
type_: VariantType::Struct(fields),
193200
},
201+
#[cfg(not(feature = "nightly"))]
194202
discriminant: variant.discriminant.as_ref().map(|(_, expr)| expr),
195203
})
196204
}
@@ -207,6 +215,7 @@ impl<'a> Data<'a> {
207215
default,
208216
type_: VariantType::Tuple(fields),
209217
},
218+
#[cfg(not(feature = "nightly"))]
210219
discriminant: variant.discriminant.as_ref().map(|(_, expr)| expr),
211220
})
212221
}
@@ -226,6 +235,7 @@ impl<'a> Data<'a> {
226235
default,
227236
type_: VariantType::Unit(pattern),
228237
},
238+
#[cfg(not(feature = "nightly"))]
229239
discriminant: variant.discriminant.as_ref().map(|(_, expr)| expr),
230240
})
231241
}
@@ -327,15 +337,12 @@ impl<'a> Data<'a> {
327337
type_: VariantType::Unit(pattern),
328338
..
329339
} => SimpleType::Unit(pattern),
330-
DataType::Union(fields) => SimpleType::Union(fields),
340+
DataType::Union(_) => SimpleType::Union,
331341
}
332342
}
333343

334344
/// Returns an [`Iterator`] over [`Field`]s.
335-
pub fn iter_fields(
336-
&self,
337-
trait_: Trait,
338-
) -> impl '_ + Iterator<Item = &'_ Field> + DoubleEndedIterator {
345+
pub fn iter_fields(&self, trait_: Trait) -> impl '_ + DoubleEndedIterator<Item = &'_ Field> {
339346
if self.skip(trait_) {
340347
[].iter()
341348
} else {
@@ -354,19 +361,13 @@ impl<'a> Data<'a> {
354361

355362
/// Returns an [`Iterator`] over [`struct@Ident`]s used as temporary
356363
/// variables for destructuring `self`.
357-
pub fn iter_self_ident(
358-
&self,
359-
trait_: Trait,
360-
) -> impl Iterator<Item = &'_ Ident> + DoubleEndedIterator {
364+
pub fn iter_self_ident(&self, trait_: Trait) -> impl DoubleEndedIterator<Item = &'_ Ident> {
361365
self.iter_fields(trait_).map(|field| &field.self_ident)
362366
}
363367

364368
/// Returns an [`Iterator`] over [`struct@Ident`]s used as temporary
365369
/// variables for destructuring `other`.
366-
pub fn iter_other_ident(
367-
&self,
368-
trait_: Trait,
369-
) -> impl Iterator<Item = &'_ Ident> + DoubleEndedIterator {
370+
pub fn iter_other_ident(&self, trait_: Trait) -> impl DoubleEndedIterator<Item = &'_ Ident> {
370371
self.iter_fields(trait_).map(|field| &field.other_ident)
371372
}
372373
}

src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,14 @@ impl Error {
213213
}
214214

215215
/// Unknown `repr`.
216+
#[cfg(not(feature = "nightly"))]
216217
pub fn repr_unknown(span: Span) -> syn::Error {
217218
syn::Error::new(span, "found unknown representation")
218219
}
219220

220221
/// Invalid enum with non-empty variants and custom discriminants without an
221222
/// integer representation.
223+
#[cfg(not(feature = "nightly"))]
222224
pub fn repr_discriminant_invalid(span: Span) -> syn::Error {
223225
syn::Error::new(
224226
span,

src/input.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use syn::{DeriveInput, GenericParam, Generics, ImplGenerics, Result, TypeGeneric
55

66
#[cfg(feature = "zeroize")]
77
use crate::DeriveTrait;
8-
use crate::{Data, DeriveWhere, Discriminant, Either, Error, Item, ItemAttr, Trait};
8+
#[cfg(not(feature = "nightly"))]
9+
use crate::Discriminant;
10+
use crate::{Data, DeriveWhere, Either, Error, Item, ItemAttr, Trait};
911

1012
/// Parsed input.
1113
pub struct Input<'a> {
@@ -51,6 +53,7 @@ impl<'a> Input<'a> {
5153
)
5254
.map(Item::Item)?,
5355
syn::Data::Enum(data) => {
56+
#[cfg(not(feature = "nightly"))]
5457
let discriminant = Discriminant::parse(attrs, &data.variants)?;
5558

5659
let variants = data
@@ -99,6 +102,7 @@ impl<'a> Input<'a> {
99102
}
100103

101104
Item::Enum {
105+
#[cfg(not(feature = "nightly"))]
102106
discriminant,
103107
ident,
104108
variants,

src/item.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
//! Intermediate representation of item data.
22
3-
use proc_macro2::{Ident, Span, TokenStream, TokenTree};
4-
use quote::ToTokens;
5-
use syn::{punctuated::Punctuated, spanned::Spanned, Attribute, Meta, Result, Token, Variant};
3+
use proc_macro2::Ident;
4+
#[cfg(not(feature = "nightly"))]
5+
use {
6+
proc_macro2::{Span, TokenStream, TokenTree},
7+
quote::ToTokens,
8+
syn::{punctuated::Punctuated, spanned::Spanned, Attribute, Meta, Result, Token, Variant},
9+
};
610

7-
use crate::{Data, Error, Incomparable, Trait};
11+
#[cfg(not(feature = "nightly"))]
12+
use crate::Error;
13+
use crate::{Data, Incomparable, Trait};
814

915
/// Fields or variants of an item.
1016
#[cfg_attr(test, derive(Debug))]
1117
#[allow(clippy::large_enum_variant)]
1218
pub enum Item<'a> {
1319
/// Enum.
1420
Enum {
21+
#[cfg(not(feature = "nightly"))]
1522
/// Type of discriminant used.
1623
discriminant: Discriminant,
1724
/// [`struct@Ident`] of this enum.
@@ -96,6 +103,7 @@ impl Item<'_> {
96103
/// Type of discriminant used.
97104
#[derive(Clone, Copy)]
98105
#[cfg_attr(test, derive(Debug))]
106+
#[cfg(not(feature = "nightly"))]
99107
pub enum Discriminant {
100108
/// The enum has only a single variant.
101109
Single,
@@ -109,6 +117,7 @@ pub enum Discriminant {
109117
DataRepr(Representation),
110118
}
111119

120+
#[cfg(not(feature = "nightly"))]
112121
impl Discriminant {
113122
/// Parse the representation of an item.
114123
pub fn parse(attrs: &[Attribute], variants: &Punctuated<Variant, Token![,]>) -> Result<Self> {
@@ -165,6 +174,7 @@ impl Discriminant {
165174
/// The type used to represent an enum.
166175
#[derive(Clone, Copy)]
167176
#[cfg_attr(test, derive(Debug))]
177+
#[cfg(not(feature = "nightly"))]
168178
pub enum Representation {
169179
/// [`u8`].
170180
U8,
@@ -192,6 +202,7 @@ pub enum Representation {
192202
ISize,
193203
}
194204

205+
#[cfg(not(feature = "nightly"))]
195206
impl Representation {
196207
/// Parse an [`struct@Ident`] to a valid representation if it is.
197208
fn parse(ident: &Ident) -> Option<Self> {
@@ -245,6 +256,7 @@ impl Representation {
245256
}
246257
}
247258

259+
#[cfg(not(feature = "nightly"))]
248260
impl ToTokens for Representation {
249261
fn to_tokens(&self, tokens: &mut TokenStream) {
250262
tokens.extend(self.to_token());

src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
//!
5656
//! ## Generic type bounds
5757
//!
58-
//! Separated from the list of traits with a semi-colon, types to bind to can be
58+
//! Separated from the list of traits with a semicolon, types to bind to can be
5959
//! specified. This example will restrict the implementation for `Example` to
6060
//! `T: Clone`:
6161
//!
@@ -307,7 +307,7 @@
307307
//! ## Supported items
308308
//!
309309
//! Structs, tuple structs, unions and enums are supported. Derive-where tries
310-
//! it's best to discourage usage that could be covered by std's `derive`. For
310+
//! its best to discourage usage that could be covered by std's `derive`. For
311311
//! example unit structs and enums only containing unit variants aren't
312312
//! supported.
313313
//!
@@ -408,6 +408,8 @@ use util::MetaListExt;
408408

409409
#[cfg(feature = "zeroize")]
410410
use self::attr::ZeroizeFqs;
411+
#[cfg(not(feature = "nightly"))]
412+
use self::item::Discriminant;
411413
use self::{
412414
attr::{
413415
Default, DeriveTrait, DeriveWhere, FieldAttr, Incomparable, ItemAttr, Skip, SkipGroup,
@@ -416,7 +418,7 @@ use self::{
416418
data::{Data, DataType, Field, SimpleType},
417419
error::Error,
418420
input::Input,
419-
item::{Discriminant, Item},
421+
item::Item,
420422
trait_::{Trait, TraitImpl},
421423
util::Either,
422424
};
@@ -588,7 +590,7 @@ pub fn derive_where_actual(input: proc_macro::TokenStream) -> proc_macro::TokenS
588590
clean_item.span()
589591
};
590592

591-
match { Input::from_input(span, &item) } {
593+
match Input::from_input(span, &item) {
592594
Ok(Input {
593595
derive_wheres,
594596
generics,

src/trait_/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl TraitImpl for Clone {
123123
SimpleType::Unit(pattern) => {
124124
quote! { #pattern => #pattern, }
125125
}
126-
SimpleType::Union(_) => TokenStream::new(),
126+
SimpleType::Union => TokenStream::new(),
127127
}
128128
}
129129
}

src/trait_/common_ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ pub fn build_incomparable_pattern(variants: &[Data]) -> Option<TokenStream> {
461461
.map(|variant @ Data { path, .. }| match variant.simple_type() {
462462
SimpleType::Struct(_) => quote!(#path{..}),
463463
SimpleType::Tuple(_) => quote!(#path(..)),
464-
SimpleType::Union(_) => unreachable!("enum variants cannot be unions"),
464+
SimpleType::Union => unreachable!("enum variants cannot be unions"),
465465
SimpleType::Unit(_) => quote!(#path),
466466
})
467467
.peekable();

src/trait_/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl TraitImpl for Debug {
7979
SimpleType::Unit(_) => {
8080
quote! { #self_pattern => ::core::fmt::Formatter::write_str(__f, #debug_name), }
8181
}
82-
SimpleType::Union(_) => unreachable!("unexpected trait for union"),
82+
SimpleType::Union => unreachable!("unexpected trait for union"),
8383
}
8484
}
8585
}

src/trait_/default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl TraitImpl for Default {
6060
SimpleType::Unit(_) => {
6161
quote! { #path }
6262
}
63-
SimpleType::Union(_) => unreachable!("unexpected trait for union"),
63+
SimpleType::Union => unreachable!("unexpected trait for union"),
6464
}
6565
}
6666
// Skip `Default` implementation if variant isn't marked with a `default` attribute.

0 commit comments

Comments
 (0)