Skip to content

Commit cafac83

Browse files
daxpeddaModProg
authored andcommitted
Remove allow(unused) in favor of cfg guards
1 parent a6264a2 commit cafac83

File tree

15 files changed

+49
-22
lines changed

15 files changed

+49
-22
lines changed

src/data.rs

Lines changed: 13 additions & 4 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,7 +29,7 @@ pub struct Data<'a> {
2729
pub path: Path,
2830
/// [Type](DataType) of this struct, union or variant.
2931
pub type_: DataType<'a>,
30-
#[cfg_attr(feature = "nightly", allow(unused))]
32+
#[cfg(not(feature = "nightly"))]
3133
/// Discriminant of this variant.
3234
pub discriminant: Option<&'a Expr>,
3335
}
@@ -70,7 +72,7 @@ pub enum SimpleType<'a> {
7072
/// Tuple struct or tuple variant.
7173
Tuple(&'a Fields<'a>),
7274
/// Union.
73-
Union(#[allow(unused)] &'a Fields<'a>),
75+
Union,
7476
/// Unit variant.
7577
Unit(&'a Pat),
7678
}
@@ -101,6 +103,7 @@ impl<'a> Data<'a> {
101103
ident,
102104
path,
103105
type_: DataType::Struct(fields),
106+
#[cfg(not(feature = "nightly"))]
104107
discriminant: None,
105108
})
106109
}
@@ -118,6 +121,7 @@ impl<'a> Data<'a> {
118121
ident,
119122
path,
120123
type_: DataType::Tuple(fields),
124+
#[cfg(not(feature = "nightly"))]
121125
discriminant: None,
122126
})
123127
}
@@ -132,6 +136,7 @@ impl<'a> Data<'a> {
132136
qself: None,
133137
path,
134138
})),
139+
#[cfg(not(feature = "nightly"))]
135140
discriminant: None,
136141
}),
137142
syn::Fields::Unit => Err(Error::item_empty(span)),
@@ -159,6 +164,7 @@ impl<'a> Data<'a> {
159164
ident,
160165
path,
161166
type_: DataType::Union(fields),
167+
#[cfg(not(feature = "nightly"))]
162168
discriminant: None,
163169
})
164170
}
@@ -192,6 +198,7 @@ impl<'a> Data<'a> {
192198
default,
193199
type_: VariantType::Struct(fields),
194200
},
201+
#[cfg(not(feature = "nightly"))]
195202
discriminant: variant.discriminant.as_ref().map(|(_, expr)| expr),
196203
})
197204
}
@@ -208,6 +215,7 @@ impl<'a> Data<'a> {
208215
default,
209216
type_: VariantType::Tuple(fields),
210217
},
218+
#[cfg(not(feature = "nightly"))]
211219
discriminant: variant.discriminant.as_ref().map(|(_, expr)| expr),
212220
})
213221
}
@@ -227,6 +235,7 @@ impl<'a> Data<'a> {
227235
default,
228236
type_: VariantType::Unit(pattern),
229237
},
238+
#[cfg(not(feature = "nightly"))]
230239
discriminant: variant.discriminant.as_ref().map(|(_, expr)| expr),
231240
})
232241
}
@@ -328,7 +337,7 @@ impl<'a> Data<'a> {
328337
type_: VariantType::Unit(pattern),
329338
..
330339
} => SimpleType::Unit(pattern),
331-
DataType::Union(fields) => SimpleType::Union(fields),
340+
DataType::Union(_) => SimpleType::Union,
332341
}
333342
}
334343

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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +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 {
15-
#[cfg_attr(feature = "nightly", allow(unused))]
21+
#[cfg(not(feature = "nightly"))]
1622
/// Type of discriminant used.
1723
discriminant: Discriminant,
1824
/// [`struct@Ident`] of this enum.
@@ -97,7 +103,7 @@ impl Item<'_> {
97103
/// Type of discriminant used.
98104
#[derive(Clone, Copy)]
99105
#[cfg_attr(test, derive(Debug))]
100-
#[cfg_attr(feature = "nightly", allow(unused))]
106+
#[cfg(not(feature = "nightly"))]
101107
pub enum Discriminant {
102108
/// The enum has only a single variant.
103109
Single,
@@ -111,6 +117,7 @@ pub enum Discriminant {
111117
DataRepr(Representation),
112118
}
113119

120+
#[cfg(not(feature = "nightly"))]
114121
impl Discriminant {
115122
/// Parse the representation of an item.
116123
pub fn parse(attrs: &[Attribute], variants: &Punctuated<Variant, Token![,]>) -> Result<Self> {
@@ -167,6 +174,7 @@ impl Discriminant {
167174
/// The type used to represent an enum.
168175
#[derive(Clone, Copy)]
169176
#[cfg_attr(test, derive(Debug))]
177+
#[cfg(not(feature = "nightly"))]
170178
pub enum Representation {
171179
/// [`u8`].
172180
U8,
@@ -194,6 +202,7 @@ pub enum Representation {
194202
ISize,
195203
}
196204

205+
#[cfg(not(feature = "nightly"))]
197206
impl Representation {
198207
/// Parse an [`struct@Ident`] to a valid representation if it is.
199208
fn parse(ident: &Ident) -> Option<Self> {
@@ -247,6 +256,7 @@ impl Representation {
247256
}
248257
}
249258

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

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
};

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.

src/trait_/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl TraitImpl for Hash {
6969
}
7070
}
7171
}
72-
SimpleType::Union(_) => unreachable!("unexpected trait for union"),
72+
SimpleType::Union => unreachable!("unexpected trait for union"),
7373
}
7474
}
7575
}

0 commit comments

Comments
 (0)