Skip to content

Commit f5d0d08

Browse files
committed
Add newtype for IsTuple
1 parent 06d6c62 commit f5d0d08

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

compiler/rustc_builtin_macros/src/deriving/decodable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ where
198198
match fields {
199199
Unnamed(fields, is_tuple) => {
200200
let path_expr = cx.expr_path(outer_pat_path);
201-
if !*is_tuple {
201+
if matches!(is_tuple, IsTuple::No) {
202202
path_expr
203203
} else {
204204
let fields = fields

compiler/rustc_builtin_macros/src/deriving/default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ fn default_struct_substructure(
6262
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), ThinVec::new());
6363

6464
let expr = match summary {
65-
Unnamed(_, false) => cx.expr_ident(trait_span, substr.type_ident),
66-
Unnamed(fields, true) => {
65+
Unnamed(_, IsTuple::No) => cx.expr_ident(trait_span, substr.type_ident),
66+
Unnamed(fields, IsTuple::Yes) => {
6767
let exprs = fields.iter().map(|sp| default_call(*sp)).collect();
6868
cx.expr_call_ident(trait_span, substr.type_ident, exprs)
6969
}

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,16 @@ pub struct FieldInfo {
286286
pub other_selflike_exprs: Vec<P<Expr>>,
287287
}
288288

289+
#[derive(Copy, Clone)]
290+
pub enum IsTuple {
291+
No,
292+
Yes,
293+
}
294+
289295
/// Fields for a static method
290296
pub enum StaticFields {
291297
/// Tuple and unit structs/enum variants like this.
292-
Unnamed(Vec<Span>, bool /*is tuple*/),
298+
Unnamed(Vec<Span>, IsTuple),
293299
/// Normal structs/struct variants.
294300
Named(Vec<(Ident, Span)>),
295301
}
@@ -1439,7 +1445,10 @@ impl<'a> TraitDef<'a> {
14391445
}
14401446
}
14411447

1442-
let is_tuple = matches!(struct_def, ast::VariantData::Tuple(..));
1448+
let is_tuple = match struct_def {
1449+
ast::VariantData::Tuple(..) => IsTuple::Yes,
1450+
_ => IsTuple::No,
1451+
};
14431452
match (just_spans.is_empty(), named_idents.is_empty()) {
14441453
(false, false) => cx
14451454
.dcx()

0 commit comments

Comments
 (0)