Add newtype for IsTuple
This commit is contained in:
parent
06d6c62f80
commit
f5d0d087ad
3 changed files with 14 additions and 5 deletions
|
@ -198,7 +198,7 @@ where
|
||||||
match fields {
|
match fields {
|
||||||
Unnamed(fields, is_tuple) => {
|
Unnamed(fields, is_tuple) => {
|
||||||
let path_expr = cx.expr_path(outer_pat_path);
|
let path_expr = cx.expr_path(outer_pat_path);
|
||||||
if !*is_tuple {
|
if matches!(is_tuple, IsTuple::No) {
|
||||||
path_expr
|
path_expr
|
||||||
} else {
|
} else {
|
||||||
let fields = fields
|
let fields = fields
|
||||||
|
|
|
@ -62,8 +62,8 @@ fn default_struct_substructure(
|
||||||
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), ThinVec::new());
|
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), ThinVec::new());
|
||||||
|
|
||||||
let expr = match summary {
|
let expr = match summary {
|
||||||
Unnamed(_, false) => cx.expr_ident(trait_span, substr.type_ident),
|
Unnamed(_, IsTuple::No) => cx.expr_ident(trait_span, substr.type_ident),
|
||||||
Unnamed(fields, true) => {
|
Unnamed(fields, IsTuple::Yes) => {
|
||||||
let exprs = fields.iter().map(|sp| default_call(*sp)).collect();
|
let exprs = fields.iter().map(|sp| default_call(*sp)).collect();
|
||||||
cx.expr_call_ident(trait_span, substr.type_ident, exprs)
|
cx.expr_call_ident(trait_span, substr.type_ident, exprs)
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,10 +286,16 @@ pub struct FieldInfo {
|
||||||
pub other_selflike_exprs: Vec<P<Expr>>,
|
pub other_selflike_exprs: Vec<P<Expr>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub enum IsTuple {
|
||||||
|
No,
|
||||||
|
Yes,
|
||||||
|
}
|
||||||
|
|
||||||
/// Fields for a static method
|
/// Fields for a static method
|
||||||
pub enum StaticFields {
|
pub enum StaticFields {
|
||||||
/// Tuple and unit structs/enum variants like this.
|
/// Tuple and unit structs/enum variants like this.
|
||||||
Unnamed(Vec<Span>, bool /*is tuple*/),
|
Unnamed(Vec<Span>, IsTuple),
|
||||||
/// Normal structs/struct variants.
|
/// Normal structs/struct variants.
|
||||||
Named(Vec<(Ident, Span)>),
|
Named(Vec<(Ident, Span)>),
|
||||||
}
|
}
|
||||||
|
@ -1439,7 +1445,10 @@ impl<'a> TraitDef<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_tuple = matches!(struct_def, ast::VariantData::Tuple(..));
|
let is_tuple = match struct_def {
|
||||||
|
ast::VariantData::Tuple(..) => IsTuple::Yes,
|
||||||
|
_ => IsTuple::No,
|
||||||
|
};
|
||||||
match (just_spans.is_empty(), named_idents.is_empty()) {
|
match (just_spans.is_empty(), named_idents.is_empty()) {
|
||||||
(false, false) => cx
|
(false, false) => cx
|
||||||
.dcx()
|
.dcx()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue