Skip to content

Commit 936bfea

Browse files
authored
Auto merge of #34113 - srinivasreddy:deriving_rustfmt, r=brson
run rustfmt on libsyntax_ext/deriving folder
2 parents 9d5965a + 9652fcb commit 936bfea

File tree

13 files changed

+932
-927
lines changed

13 files changed

+932
-927
lines changed

src/libsyntax_ext/deriving/bounds.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,22 @@ use deriving::generic::*;
1212
use deriving::generic::ty::*;
1313

1414
use syntax::ast::MetaItem;
15-
use syntax::ext::base::{ExtCtxt, Annotatable};
15+
use syntax::ext::base::{Annotatable, ExtCtxt};
1616
use syntax_pos::Span;
1717

1818
pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt,
1919
span: Span,
2020
_: &MetaItem,
2121
_: &Annotatable,
22-
_: &mut FnMut(Annotatable))
23-
{
22+
_: &mut FnMut(Annotatable)) {
2423
cx.span_err(span, "this unsafe trait should be implemented explicitly");
2524
}
2625

2726
pub fn expand_deriving_copy(cx: &mut ExtCtxt,
2827
span: Span,
2928
mitem: &MetaItem,
3029
item: &Annotatable,
31-
push: &mut FnMut(Annotatable))
32-
{
30+
push: &mut FnMut(Annotatable)) {
3331
let mut v = cx.crate_root.map(|s| vec![s]).unwrap_or(Vec::new());
3432
v.push("marker");
3533
v.push("Copy");

src/libsyntax_ext/deriving/clone.rs

+50-48
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@
1111
use deriving::generic::*;
1212
use deriving::generic::ty::*;
1313

14-
use syntax::ast::{Expr, ItemKind, Generics, MetaItem, VariantData};
14+
use syntax::ast::{Expr, Generics, ItemKind, MetaItem, VariantData};
1515
use syntax::attr;
16-
use syntax::ext::base::{ExtCtxt, Annotatable};
16+
use syntax::ext::base::{Annotatable, ExtCtxt};
1717
use syntax::ext::build::AstBuilder;
1818
use syntax::parse::token::InternedString;
1919
use syntax::ptr::P;
2020
use syntax_pos::Span;
2121

2222
#[derive(PartialEq)]
23-
enum Mode { Deep, Shallow }
23+
enum Mode {
24+
Deep,
25+
Shallow,
26+
}
2427

2528
pub fn expand_deriving_clone(cx: &mut ExtCtxt,
2629
span: Span,
2730
mitem: &MetaItem,
2831
item: &Annotatable,
29-
push: &mut FnMut(Annotatable))
30-
{
32+
push: &mut FnMut(Annotatable)) {
3133
// check if we can use a short form
3234
//
3335
// the short form is `fn clone(&self) -> Self { *self }`
@@ -46,8 +48,8 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
4648
match annitem.node {
4749
ItemKind::Struct(_, Generics { ref ty_params, .. }) |
4850
ItemKind::Enum(_, Generics { ref ty_params, .. })
49-
if ty_params.is_empty()
50-
&& attr::contains_name(&annitem.attrs, "derive_Copy") => {
51+
if ty_params.is_empty() &&
52+
attr::contains_name(&annitem.attrs, "derive_Copy") => {
5153

5254
bounds = vec![Literal(path_std!(cx, core::marker::Copy))];
5355
unify_fieldless_variants = true;
@@ -66,54 +68,53 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
6668
}
6769
}
6870

69-
_ => cx.span_bug(span, "#[derive(Clone)] on trait item or impl item")
71+
_ => cx.span_bug(span, "#[derive(Clone)] on trait item or impl item"),
7072
}
7173

7274
let inline = cx.meta_word(span, InternedString::new("inline"));
73-
let attrs = vec!(cx.attribute(span, inline));
75+
let attrs = vec![cx.attribute(span, inline)];
7476
let trait_def = TraitDef {
7577
span: span,
7678
attributes: Vec::new(),
7779
path: path_std!(cx, core::clone::Clone),
7880
additional_bounds: bounds,
7981
generics: LifetimeBounds::empty(),
8082
is_unsafe: false,
81-
methods: vec!(
82-
MethodDef {
83-
name: "clone",
84-
generics: LifetimeBounds::empty(),
85-
explicit_self: borrowed_explicit_self(),
86-
args: Vec::new(),
87-
ret_ty: Self_,
88-
attributes: attrs,
89-
is_unsafe: false,
90-
unify_fieldless_variants: unify_fieldless_variants,
91-
combine_substructure: substructure,
92-
}
93-
),
83+
methods: vec![MethodDef {
84+
name: "clone",
85+
generics: LifetimeBounds::empty(),
86+
explicit_self: borrowed_explicit_self(),
87+
args: Vec::new(),
88+
ret_ty: Self_,
89+
attributes: attrs,
90+
is_unsafe: false,
91+
unify_fieldless_variants: unify_fieldless_variants,
92+
combine_substructure: substructure,
93+
}],
9494
associated_types: Vec::new(),
9595
};
9696

9797
trait_def.expand(cx, mitem, item, push)
9898
}
9999

100-
fn cs_clone(
101-
name: &str,
102-
cx: &mut ExtCtxt, trait_span: Span,
103-
substr: &Substructure,
104-
mode: Mode) -> P<Expr> {
100+
fn cs_clone(name: &str,
101+
cx: &mut ExtCtxt,
102+
trait_span: Span,
103+
substr: &Substructure,
104+
mode: Mode)
105+
-> P<Expr> {
105106
let ctor_path;
106107
let all_fields;
107108
let fn_path = match mode {
108109
Mode::Shallow => cx.std_path(&["clone", "assert_receiver_is_clone"]),
109-
Mode::Deep => cx.std_path(&["clone", "Clone", "clone"]),
110+
Mode::Deep => cx.std_path(&["clone", "Clone", "clone"]),
110111
};
111112
let subcall = |field: &FieldInfo| {
112113
let args = vec![cx.expr_addr_of(field.span, field.self_.clone())];
113114

114115
let span = if mode == Mode::Shallow {
115116
// set the expn ID so we can call the unstable method
116-
Span { expn_id: cx.backtrace(), .. trait_span }
117+
Span { expn_id: cx.backtrace(), ..trait_span }
117118
} else {
118119
field.span
119120
};
@@ -131,15 +132,15 @@ fn cs_clone(
131132
ctor_path = cx.path(trait_span, vec![substr.type_ident, variant.node.name]);
132133
all_fields = af;
133134
vdata = &variant.node.data;
134-
},
135-
EnumNonMatchingCollapsed (..) => {
135+
}
136+
EnumNonMatchingCollapsed(..) => {
136137
cx.span_bug(trait_span,
137138
&format!("non-matching enum variants in \
138-
`derive({})`", name))
139+
`derive({})`",
140+
name))
139141
}
140142
StaticEnum(..) | StaticStruct(..) => {
141-
cx.span_bug(trait_span,
142-
&format!("static method in `derive({})`", name))
143+
cx.span_bug(trait_span, &format!("static method in `derive({})`", name))
143144
}
144145
}
145146

@@ -153,17 +154,20 @@ fn cs_clone(
153154
Mode::Deep => {
154155
match *vdata {
155156
VariantData::Struct(..) => {
156-
let fields = all_fields.iter().map(|field| {
157-
let ident = match field.name {
158-
Some(i) => i,
159-
None => {
160-
cx.span_bug(trait_span,
161-
&format!("unnamed field in normal struct in \
162-
`derive({})`", name))
163-
}
164-
};
165-
cx.field_imm(field.span, ident, subcall(field))
166-
}).collect::<Vec<_>>();
157+
let fields = all_fields.iter()
158+
.map(|field| {
159+
let ident = match field.name {
160+
Some(i) => i,
161+
None => {
162+
cx.span_bug(trait_span,
163+
&format!("unnamed field in normal struct in \
164+
`derive({})`",
165+
name))
166+
}
167+
};
168+
cx.field_imm(field.span, ident, subcall(field))
169+
})
170+
.collect::<Vec<_>>();
167171

168172
cx.expr_struct(trait_span, ctor_path, fields)
169173
}
@@ -172,9 +176,7 @@ fn cs_clone(
172176
let path = cx.expr_path(ctor_path);
173177
cx.expr_call(trait_span, path, subcalls)
174178
}
175-
VariantData::Unit(..) => {
176-
cx.expr_path(ctor_path)
177-
}
179+
VariantData::Unit(..) => cx.expr_path(ctor_path),
178180
}
179181
}
180182
}

src/libsyntax_ext/deriving/cmp/eq.rs

+31-36
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use deriving::generic::*;
1212
use deriving::generic::ty::*;
1313

14-
use syntax::ast::{MetaItem, Expr};
15-
use syntax::ext::base::{ExtCtxt, Annotatable};
14+
use syntax::ast::{Expr, MetaItem};
15+
use syntax::ext::base::{Annotatable, ExtCtxt};
1616
use syntax::ext::build::AstBuilder;
1717
use syntax::parse::token::InternedString;
1818
use syntax::ptr::P;
@@ -22,52 +22,47 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
2222
span: Span,
2323
mitem: &MetaItem,
2424
item: &Annotatable,
25-
push: &mut FnMut(Annotatable))
26-
{
25+
push: &mut FnMut(Annotatable)) {
2726
fn cs_total_eq_assert(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
28-
cs_same_method(
29-
|cx, span, exprs| {
30-
// create `a.<method>(); b.<method>(); c.<method>(); ...`
31-
// (where method is `assert_receiver_is_total_eq`)
32-
let stmts = exprs.into_iter().map(|e| cx.stmt_expr(e)).collect();
33-
let block = cx.block(span, stmts);
34-
cx.expr_block(block)
35-
},
36-
Box::new(|cx, sp, _, _| {
37-
cx.span_bug(sp, "non matching enums in derive(Eq)?") }),
38-
cx,
39-
span,
40-
substr
41-
)
27+
cs_same_method(|cx, span, exprs| {
28+
// create `a.<method>(); b.<method>(); c.<method>(); ...`
29+
// (where method is `assert_receiver_is_total_eq`)
30+
let stmts = exprs.into_iter().map(|e| cx.stmt_expr(e)).collect();
31+
let block = cx.block(span, stmts);
32+
cx.expr_block(block)
33+
},
34+
Box::new(|cx, sp, _, _| {
35+
cx.span_bug(sp, "non matching enums in derive(Eq)?")
36+
}),
37+
cx,
38+
span,
39+
substr)
4240
}
4341

4442
let inline = cx.meta_word(span, InternedString::new("inline"));
4543
let hidden = cx.meta_word(span, InternedString::new("hidden"));
46-
let doc = cx.meta_list(span, InternedString::new("doc"), vec!(hidden));
47-
let attrs = vec!(cx.attribute(span, inline),
48-
cx.attribute(span, doc));
44+
let doc = cx.meta_list(span, InternedString::new("doc"), vec![hidden]);
45+
let attrs = vec![cx.attribute(span, inline), cx.attribute(span, doc)];
4946
let trait_def = TraitDef {
5047
span: span,
5148
attributes: Vec::new(),
5249
path: path_std!(cx, core::cmp::Eq),
5350
additional_bounds: Vec::new(),
5451
generics: LifetimeBounds::empty(),
5552
is_unsafe: false,
56-
methods: vec!(
57-
MethodDef {
58-
name: "assert_receiver_is_total_eq",
59-
generics: LifetimeBounds::empty(),
60-
explicit_self: borrowed_explicit_self(),
61-
args: vec!(),
62-
ret_ty: nil_ty(),
63-
attributes: attrs,
64-
is_unsafe: false,
65-
unify_fieldless_variants: true,
66-
combine_substructure: combine_substructure(Box::new(|a, b, c| {
67-
cs_total_eq_assert(a, b, c)
68-
}))
69-
}
70-
),
53+
methods: vec![MethodDef {
54+
name: "assert_receiver_is_total_eq",
55+
generics: LifetimeBounds::empty(),
56+
explicit_self: borrowed_explicit_self(),
57+
args: vec![],
58+
ret_ty: nil_ty(),
59+
attributes: attrs,
60+
is_unsafe: false,
61+
unify_fieldless_variants: true,
62+
combine_substructure: combine_substructure(Box::new(|a, b, c| {
63+
cs_total_eq_assert(a, b, c)
64+
})),
65+
}],
7166
associated_types: Vec::new(),
7267
};
7368
trait_def.expand(cx, mitem, item, push)

0 commit comments

Comments
 (0)