Skip to content

Commit 7df71b0

Browse files
committed
syntax: Substructure.fields doesn't need to be a reference
1 parent 45c5bae commit 7df71b0

File tree

10 files changed

+46
-45
lines changed

10 files changed

+46
-45
lines changed

src/libsyntax/ext/deriving/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn cs_clone(
6060
cx.expr_method_call(field.span, field.self_, clone_ident, Vec::new())
6161
};
6262

63-
match *substr.fields {
63+
match substr.fields {
6464
Struct(ref af) => {
6565
ctor_ident = substr.type_ident;
6666
all_fields = af;

src/libsyntax/ext/deriving/decodable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
7575
let calldecode = cx.expr_call_global(trait_span, recurse, vec!(blkdecoder));
7676
let lambdadecode = cx.lambda_expr_1(trait_span, calldecode, blkarg);
7777

78-
return match *substr.fields {
78+
match substr.fields {
7979
StaticStruct(_, ref summary) => {
8080
let nfields = match *summary {
8181
Unnamed(ref fields) => fields.len(),
@@ -149,7 +149,7 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
149149
))
150150
}
151151
_ => cx.bug("expected StaticEnum or StaticStruct in deriving(Decodable)")
152-
};
152+
}
153153
}
154154

155155
/// Create a decoder for a single enum variant/struct:

src/libsyntax/ext/deriving/default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn default_substructure(cx: &mut ExtCtxt, trait_span: Span,
5757
);
5858
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new());
5959

60-
return match *substr.fields {
60+
match substr.fields {
6161
StaticStruct(_, ref summary) => {
6262
match *summary {
6363
Unnamed(ref fields) => {
@@ -82,5 +82,5 @@ fn default_substructure(cx: &mut ExtCtxt, trait_span: Span,
8282
cx.expr_uint(trait_span, 0)
8383
}
8484
_ => cx.span_bug(trait_span, "Non-static method in `deriving(Default)`")
85-
};
85+
}
8686
}

src/libsyntax/ext/deriving/encodable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
138138
let blkencoder = cx.expr_ident(trait_span, blkarg);
139139
let encode = cx.ident_of("encode");
140140

141-
return match *substr.fields {
141+
match substr.fields {
142142
Struct(ref fields) => {
143143
let emit_struct_field = cx.ident_of("emit_struct_field");
144144
let mut stmts = Vec::new();
@@ -245,5 +245,5 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
245245
}
246246

247247
_ => cx.bug("expected Struct or EnumMatching in deriving(Encodable)")
248-
};
248+
}
249249
}

src/libsyntax/ext/deriving/generic/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ pub struct Substructure<'a> {
254254
pub self_args: &'a [Gc<Expr>],
255255
/// verbatim access to any other arguments
256256
pub nonself_args: &'a [Gc<Expr>],
257-
pub fields: &'a SubstructureFields<'a>
257+
/// The data structure fields
258+
pub fields: SubstructureFields<'a>
258259
}
259260

260261
/// Summary of the relevant parts of a struct/enum field.
@@ -568,7 +569,7 @@ impl<'a> MethodDef<'a> {
568569
type_ident: Ident,
569570
self_args: &[Gc<Expr>],
570571
nonself_args: &[Gc<Expr>],
571-
fields: &SubstructureFields)
572+
fields: SubstructureFields)
572573
-> Gc<Expr> {
573574
let substructure = Substructure {
574575
type_ident: type_ident,
@@ -769,7 +770,7 @@ impl<'a> MethodDef<'a> {
769770
type_ident,
770771
self_args,
771772
nonself_args,
772-
&Struct(fields));
773+
Struct(fields));
773774

774775
// make a series of nested matches, to destructure the
775776
// structs. This is actually right-to-left, but it shouldn't
@@ -795,7 +796,7 @@ impl<'a> MethodDef<'a> {
795796
trait_,
796797
type_ident,
797798
self_args, nonself_args,
798-
&StaticStruct(struct_def, summary))
799+
StaticStruct(struct_def, summary))
799800
}
800801

801802
/**
@@ -991,7 +992,7 @@ impl<'a> MethodDef<'a> {
991992
field_tuples);
992993
let arm_expr = self.call_substructure_method(
993994
cx, trait_, type_ident, self_args, nonself_args,
994-
&substructure);
995+
substructure);
995996

996997
cx.arm(sp, vec![single_pat], arm_expr)
997998
}).collect();
@@ -1044,7 +1045,7 @@ impl<'a> MethodDef<'a> {
10441045

10451046
let arm_expr = self.call_substructure_method(
10461047
cx, trait_, type_ident, self_args, nonself_args,
1047-
&catch_all_substructure);
1048+
catch_all_substructure);
10481049

10491050
// Builds the expression:
10501051
// {
@@ -1153,7 +1154,7 @@ impl<'a> MethodDef<'a> {
11531154
}).collect();
11541155
self.call_substructure_method(cx, trait_, type_ident,
11551156
self_args, nonself_args,
1156-
&StaticEnum(enum_def, summary))
1157+
StaticEnum(enum_def, summary))
11571158
}
11581159
}
11591160

@@ -1334,7 +1335,7 @@ pub fn cs_fold(use_foldl: bool,
13341335
trait_span: Span,
13351336
substructure: &Substructure)
13361337
-> Gc<Expr> {
1337-
match *substructure.fields {
1338+
match substructure.fields {
13381339
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
13391340
if use_foldl {
13401341
all_fields.iter().fold(base, |old, field| {
@@ -1380,7 +1381,7 @@ pub fn cs_same_method(f: |&mut ExtCtxt, Span, Vec<Gc<Expr>>| -> Gc<Expr>,
13801381
trait_span: Span,
13811382
substructure: &Substructure)
13821383
-> Gc<Expr> {
1383-
match *substructure.fields {
1384+
match substructure.fields {
13841385
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
13851386
// call self_n.method(other_1_n, other_2_n, ...)
13861387
let called = all_fields.iter().map(|field| {

src/libsyntax/ext/deriving/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span,
7777
};
7878
let mut stmts = Vec::new();
7979

80-
let fields = match *substr.fields {
80+
let fields = match substr.fields {
8181
Struct(ref fs) => fs,
8282
EnumMatching(index, variant, ref fs) => {
8383
// Determine the discriminant. We will feed this value to the byte

src/libsyntax/ext/deriving/primitive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span,
7777
_ => cx.span_bug(trait_span, "incorrect number of arguments in `deriving(FromPrimitive)`")
7878
};
7979

80-
match *substr.fields {
80+
match substr.fields {
8181
StaticStruct(..) => {
8282
cx.span_err(trait_span, "`FromPrimitive` cannot be derived for structs");
8383
return cx.expr_fail(trait_span, InternedString::new(""));

src/libsyntax/ext/deriving/rand.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span,
7272
vec!( *rng.get(0) ))
7373
};
7474

75-
return match *substr.fields {
75+
match substr.fields {
7676
StaticStruct(_, ref summary) => {
7777
rand_thing(cx, trait_span, substr.type_ident, summary, rand_call)
7878
}
@@ -130,30 +130,30 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span,
130130
cx.expr_block(block)
131131
}
132132
_ => cx.bug("Non-static method in `deriving(Rand)`")
133-
};
133+
}
134+
}
134135

135-
fn rand_thing(cx: &mut ExtCtxt,
136-
trait_span: Span,
137-
ctor_ident: Ident,
138-
summary: &StaticFields,
139-
rand_call: |&mut ExtCtxt, Span| -> Gc<Expr>)
140-
-> Gc<Expr> {
141-
match *summary {
142-
Unnamed(ref fields) => {
143-
if fields.is_empty() {
144-
cx.expr_ident(trait_span, ctor_ident)
145-
} else {
146-
let exprs = fields.iter().map(|span| rand_call(cx, *span)).collect();
147-
cx.expr_call_ident(trait_span, ctor_ident, exprs)
148-
}
149-
}
150-
Named(ref fields) => {
151-
let rand_fields = fields.iter().map(|&(ident, span)| {
152-
let e = rand_call(cx, span);
153-
cx.field_imm(span, ident, e)
154-
}).collect();
155-
cx.expr_struct_ident(trait_span, ctor_ident, rand_fields)
136+
fn rand_thing(cx: &mut ExtCtxt,
137+
trait_span: Span,
138+
ctor_ident: Ident,
139+
summary: &StaticFields,
140+
rand_call: |&mut ExtCtxt, Span| -> Gc<Expr>)
141+
-> Gc<Expr> {
142+
match *summary {
143+
Unnamed(ref fields) => {
144+
if fields.is_empty() {
145+
cx.expr_ident(trait_span, ctor_ident)
146+
} else {
147+
let exprs = fields.iter().map(|span| rand_call(cx, *span)).collect();
148+
cx.expr_call_ident(trait_span, ctor_ident, exprs)
156149
}
157150
}
151+
Named(ref fields) => {
152+
let rand_fields = fields.iter().map(|&(ident, span)| {
153+
let e = rand_call(cx, span);
154+
cx.field_imm(span, ident, e)
155+
}).collect();
156+
cx.expr_struct_ident(trait_span, ctor_ident, rand_fields)
157+
}
158158
}
159159
}

src/libsyntax/ext/deriving/show.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
6262
// <field>: {}, ... }` based on the "shape".
6363
//
6464
// Easy start: they all start with the name.
65-
let name = match *substr.fields {
65+
let name = match substr.fields {
6666
Struct(_) => substr.type_ident,
6767
EnumMatching(_, v, _) => v.node.name,
6868
EnumNonMatchingCollapsed(..) | StaticStruct(..) | StaticEnum(..) => {
@@ -75,7 +75,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
7575
let mut exprs = Vec::new();
7676

7777
// Getting harder... making the format string:
78-
match *substr.fields {
78+
match substr.fields {
7979
// unit struct/nullary variant: no work necessary!
8080
Struct(ref fields) if fields.len() == 0 => {}
8181
EnumMatching(_, _, ref fields) if fields.len() == 0 => {}

src/libsyntax/ext/deriving/zero.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn zero_substructure(cx: &mut ExtCtxt, trait_span: Span,
7373
);
7474
let zero_call = |span| cx.expr_call_global(span, zero_ident.clone(), Vec::new());
7575

76-
return match *substr.fields {
76+
match substr.fields {
7777
StaticStruct(_, ref summary) => {
7878
match *summary {
7979
Unnamed(ref fields) => {
@@ -98,5 +98,5 @@ fn zero_substructure(cx: &mut ExtCtxt, trait_span: Span,
9898
cx.expr_uint(trait_span, 0)
9999
}
100100
_ => cx.bug("Non-static method in `deriving(Zero)`")
101-
};
101+
}
102102
}

0 commit comments

Comments
 (0)