Skip to content

Commit afb853a

Browse files
committed
Auto merge of #43008 - zackmdavis:field_init_shorthand_in_librustc, r=estebank
use field init shorthand in src/librustc/ Commentary on #37340 [suggested](#37340 (comment)) using the new field init syntax in the compiler. Do we care about this? If so, here's a pull request for the librustc/ directory. While [`rustfmt` might do this in the future](#37340 (comment)), in the meantime, some simple Python will do: ```python #!/usr/bin/env python3 import os, re, sys OPPORTUNITY = re.compile(r" (\w+): \1,?\n") def field_init_shorthand_substitution(filename): with open(filename) as f: text = f.read() revised = OPPORTUNITY.sub(r" \1,\n", text) with open(filename, 'w') as f: f.write(revised) def substitute_in_directory(path): for dirname, _subdirs, basenames in os.walk(path): for basename in basenames: field_init_shorthand_substitution(os.path.join(dirname, basename)) if __name__ == "__main__": substitute_in_directory(sys.argv[1]) ``` **Update 3 July**: edited the search (respectively replace) regex to ` (\w+): \1,?\n` (` \1,\n`) from ` (\w+): \1,` (` \1,`)
2 parents 7f1c4be + f668999 commit afb853a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+374
-374
lines changed

src/librustc/cfg/construct.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
5858
let tables = tcx.typeck_tables_of(owner_def_id);
5959

6060
let mut cfg_builder = CFGBuilder {
61-
tcx: tcx,
61+
tcx,
6262
owner_def_id,
63-
tables: tables,
64-
graph: graph,
65-
fn_exit: fn_exit,
63+
tables,
64+
graph,
65+
fn_exit,
6666
loop_scopes: Vec::new(),
6767
breakable_block_scopes: Vec::new(),
6868
};
6969
body_exit = cfg_builder.expr(&body.value, entry);
7070
cfg_builder.add_contained_edge(body_exit, fn_exit);
7171
let CFGBuilder { graph, .. } = cfg_builder;
7272
CFG {
73-
graph: graph,
74-
entry: entry,
73+
graph,
74+
entry,
7575
exit: fn_exit,
7676
}
7777
}

src/librustc/dep_graph/dep_tracking_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<M: DepTrackingMapConfig> DepTrackingMap<M> {
3636
pub fn new(graph: DepGraph) -> DepTrackingMap<M> {
3737
DepTrackingMap {
3838
phantom: PhantomData,
39-
graph: graph,
39+
graph,
4040
map: FxHashMap(),
4141
}
4242
}

src/librustc/dep_graph/query.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ impl DepGraphQuery {
3636
}
3737

3838
DepGraphQuery {
39-
graph: graph,
40-
indices: indices
39+
graph,
40+
indices,
4141
}
4242
}
4343

src/librustc/dep_graph/shadow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl ShadowGraph {
5959

6060
ShadowGraph {
6161
stack: RefCell::new(vec![]),
62-
forbidden_edge: forbidden_edge,
62+
forbidden_edge,
6363
}
6464
}
6565

src/librustc/dep_graph/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl DepGraphThreadData {
7878
}
7979

8080
DepGraphThreadData {
81-
enabled: enabled,
81+
enabled,
8282
shadow_graph: ShadowGraph::new(),
8383
messages: VecCell::with_capacity(INITIAL_CAPACITY),
8484
swap_in: rx2,

src/librustc/hir/lowering.rs

+53-53
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ pub fn lower_crate(sess: &Session,
126126

127127
LoweringContext {
128128
crate_root: std_inject::injected_crate_name(krate),
129-
sess: sess,
129+
sess,
130130
parent_def: None,
131-
resolver: resolver,
131+
resolver,
132132
name_map: FxHashMap(),
133133
items: BTreeMap::new(),
134134
trait_items: BTreeMap::new(),
@@ -251,15 +251,15 @@ impl<'a> LoweringContext<'a> {
251251
.init_node_id_to_hir_id_mapping(self.node_id_to_hir_id);
252252

253253
hir::Crate {
254-
module: module,
255-
attrs: attrs,
254+
module,
255+
attrs,
256256
span: c.span,
257257
exported_macros: hir::HirVec::from(self.exported_macros),
258258
items: self.items,
259259
trait_items: self.trait_items,
260260
impl_items: self.impl_items,
261261
bodies: self.bodies,
262-
body_ids: body_ids,
262+
body_ids,
263263
trait_impls: self.trait_impls,
264264
trait_default_impl: self.trait_default_impl,
265265
}
@@ -368,7 +368,7 @@ impl<'a> LoweringContext<'a> {
368368
arguments: decl.map_or(hir_vec![], |decl| {
369369
decl.inputs.iter().map(|x| self.lower_arg(x)).collect()
370370
}),
371-
value: value
371+
value,
372372
};
373373
let id = body.id();
374374
self.bodies.insert(id, body);
@@ -809,7 +809,7 @@ impl<'a> LoweringContext<'a> {
809809
self.lower_path_segment(p.span, segment, param_mode, 0)
810810
}).chain(name.map(|name| {
811811
hir::PathSegment {
812-
name: name,
812+
name,
813813
parameters: hir::PathParameters::none()
814814
}
815815
})).collect(),
@@ -857,7 +857,7 @@ impl<'a> LoweringContext<'a> {
857857

858858
hir::PathSegment {
859859
name: self.lower_ident(segment.identifier),
860-
parameters: parameters,
860+
parameters,
861861
}
862862
}
863863

@@ -881,7 +881,7 @@ impl<'a> LoweringContext<'a> {
881881
hir::ParenthesizedParameterData {
882882
inputs: inputs.iter().map(|ty| self.lower_ty(ty)).collect(),
883883
output: output.as_ref().map(|ty| self.lower_ty(ty)),
884-
span: span,
884+
span,
885885
}
886886
}
887887

@@ -970,8 +970,8 @@ impl<'a> LoweringContext<'a> {
970970

971971
hir::TyParam {
972972
id: self.lower_node_id(tp.id),
973-
name: name,
974-
bounds: bounds,
973+
name,
974+
bounds,
975975
default: tp.default.as_ref().map(|x| self.lower_ty(x)),
976976
span: tp.span,
977977
pure_wrt_drop: tp.attrs.iter().any(|attr| attr.check_name("may_dangle")),
@@ -1081,14 +1081,14 @@ impl<'a> LoweringContext<'a> {
10811081
TraitTyParamBound(_, TraitBoundModifier::Maybe) => None,
10821082
_ => Some(self.lower_ty_param_bound(bound))
10831083
}).collect(),
1084-
span: span,
1084+
span,
10851085
})
10861086
}
10871087
WherePredicate::RegionPredicate(WhereRegionPredicate{ ref lifetime,
10881088
ref bounds,
10891089
span}) => {
10901090
hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
1091-
span: span,
1091+
span,
10921092
lifetime: self.lower_lifetime(lifetime),
10931093
bounds: bounds.iter().map(|bound| self.lower_lifetime(bound)).collect(),
10941094
})
@@ -1101,7 +1101,7 @@ impl<'a> LoweringContext<'a> {
11011101
id: self.lower_node_id(id),
11021102
lhs_ty: self.lower_ty(lhs_ty),
11031103
rhs_ty: self.lower_ty(rhs_ty),
1104-
span: span,
1104+
span,
11051105
})
11061106
}
11071107
}
@@ -1133,7 +1133,7 @@ impl<'a> LoweringContext<'a> {
11331133
qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath)
11341134
};
11351135
hir::TraitRef {
1136-
path: path,
1136+
path,
11371137
ref_id: self.lower_node_id(p.ref_id),
11381138
}
11391139
}
@@ -1201,10 +1201,10 @@ impl<'a> LoweringContext<'a> {
12011201
P(hir::Block {
12021202
id: self.lower_node_id(b.id),
12031203
stmts: stmts.into(),
1204-
expr: expr,
1204+
expr,
12051205
rules: self.lower_block_check_mode(&b.rules),
12061206
span: b.span,
1207-
targeted_by_break: targeted_by_break,
1207+
targeted_by_break,
12081208
})
12091209
}
12101210

@@ -1259,8 +1259,8 @@ impl<'a> LoweringContext<'a> {
12591259
name: import.rename.unwrap_or(ident).name,
12601260
attrs: attrs.clone(),
12611261
node: hir::ItemUse(P(path), hir::UseKind::Single),
1262-
vis: vis,
1263-
span: span,
1262+
vis,
1263+
span,
12641264
});
12651265
});
12661266
}
@@ -1441,7 +1441,7 @@ impl<'a> LoweringContext<'a> {
14411441
name: self.lower_ident(i.ident),
14421442
span: i.span,
14431443
defaultness: self.lower_defaultness(Defaultness::Default, has_default),
1444-
kind: kind,
1444+
kind,
14451445
}
14461446
}
14471447

@@ -1523,9 +1523,9 @@ impl<'a> LoweringContext<'a> {
15231523
if let ItemKind::MacroDef(ref def) = i.node {
15241524
if !def.legacy || i.attrs.iter().any(|attr| attr.path == "macro_export") {
15251525
self.exported_macros.push(hir::MacroDef {
1526-
name: name,
1527-
vis: vis,
1528-
attrs: attrs,
1526+
name,
1527+
vis,
1528+
attrs,
15291529
id: i.id,
15301530
span: i.span,
15311531
body: def.stream(),
@@ -1541,10 +1541,10 @@ impl<'a> LoweringContext<'a> {
15411541

15421542
Some(hir::Item {
15431543
id: self.lower_node_id(i.id),
1544-
name: name,
1545-
attrs: attrs,
1546-
node: node,
1547-
vis: vis,
1544+
name,
1545+
attrs,
1546+
node,
1547+
vis,
15481548
span: i.span,
15491549
})
15501550
}
@@ -1650,7 +1650,7 @@ impl<'a> LoweringContext<'a> {
16501650
Some(def) => {
16511651
hir::PatKind::Path(hir::QPath::Resolved(None, P(hir::Path {
16521652
span: pth1.span,
1653-
def: def,
1653+
def,
16541654
segments: hir_vec![
16551655
hir::PathSegment::from_name(pth1.node.name)
16561656
],
@@ -1887,9 +1887,9 @@ impl<'a> LoweringContext<'a> {
18871887
let blk = P(hir::Block {
18881888
stmts: hir_vec![],
18891889
expr: Some(els),
1890-
id: id,
1890+
id,
18911891
rules: hir::DefaultBlock,
1892-
span: span,
1892+
span,
18931893
targeted_by_break: false,
18941894
});
18951895
P(self.expr_block(blk, ThinVec::new()))
@@ -2108,7 +2108,7 @@ impl<'a> LoweringContext<'a> {
21082108
sub_expr,
21092109
arms.into(),
21102110
hir::MatchSource::IfLetDesugar {
2111-
contains_else_clause: contains_else_clause,
2111+
contains_else_clause,
21122112
})
21132113
}
21142114

@@ -2536,7 +2536,7 @@ impl<'a> LoweringContext<'a> {
25362536
fn arm(&mut self, pats: hir::HirVec<P<hir::Pat>>, expr: P<hir::Expr>) -> hir::Arm {
25372537
hir::Arm {
25382538
attrs: hir_vec![],
2539-
pats: pats,
2539+
pats,
25402540
guard: None,
25412541
body: expr,
25422542
}
@@ -2546,10 +2546,10 @@ impl<'a> LoweringContext<'a> {
25462546
hir::Field {
25472547
name: Spanned {
25482548
node: name,
2549-
span: span,
2549+
span,
25502550
},
2551-
span: span,
2552-
expr: expr,
2551+
span,
2552+
expr,
25532553
is_shorthand: false,
25542554
}
25552555
}
@@ -2578,8 +2578,8 @@ impl<'a> LoweringContext<'a> {
25782578
};
25792579

25802580
let expr_path = hir::ExprPath(hir::QPath::Resolved(None, P(hir::Path {
2581-
span: span,
2582-
def: def,
2581+
span,
2582+
def,
25832583
segments: hir_vec![hir::PathSegment::from_name(id)],
25842584
})));
25852585

@@ -2619,9 +2619,9 @@ impl<'a> LoweringContext<'a> {
26192619
fn expr(&mut self, span: Span, node: hir::Expr_, attrs: ThinVec<Attribute>) -> hir::Expr {
26202620
hir::Expr {
26212621
id: self.next_id(),
2622-
node: node,
2623-
span: span,
2624-
attrs: attrs,
2622+
node,
2623+
span,
2624+
attrs,
26252625
}
26262626
}
26272627

@@ -2632,7 +2632,7 @@ impl<'a> LoweringContext<'a> {
26322632
source: hir::LocalSource)
26332633
-> hir::Stmt {
26342634
let local = P(hir::Local {
2635-
pat: pat,
2635+
pat,
26362636
ty: None,
26372637
init: ex,
26382638
id: self.next_id(),
@@ -2662,11 +2662,11 @@ impl<'a> LoweringContext<'a> {
26622662
fn block_all(&mut self, span: Span, stmts: hir::HirVec<hir::Stmt>, expr: Option<P<hir::Expr>>)
26632663
-> hir::Block {
26642664
hir::Block {
2665-
stmts: stmts,
2666-
expr: expr,
2665+
stmts,
2666+
expr,
26672667
id: self.next_id(),
26682668
rules: hir::DefaultBlock,
2669-
span: span,
2669+
span,
26702670
targeted_by_break: false,
26712671
}
26722672
}
@@ -2719,15 +2719,15 @@ impl<'a> LoweringContext<'a> {
27192719
};
27202720

27212721
P(hir::Pat {
2722-
id: id,
2722+
id,
27232723
node: hir::PatKind::Binding(bm,
27242724
def_id,
27252725
Spanned {
2726-
span: span,
2726+
span,
27272727
node: name,
27282728
},
27292729
None),
2730-
span: span,
2730+
span,
27312731
})
27322732
}
27332733

@@ -2739,7 +2739,7 @@ impl<'a> LoweringContext<'a> {
27392739
P(hir::Pat {
27402740
id: self.next_id(),
27412741
node: pat,
2742-
span: span,
2742+
span,
27432743
})
27442744
}
27452745

@@ -2748,7 +2748,7 @@ impl<'a> LoweringContext<'a> {
27482748
/// The path is also resolved according to `is_value`.
27492749
fn std_path(&mut self, span: Span, components: &[&str], is_value: bool) -> hir::Path {
27502750
let mut path = hir::Path {
2751-
span: span,
2751+
span,
27522752
def: Def::Err,
27532753
segments: iter::once(keywords::CrateRoot.name()).chain({
27542754
self.crate_root.into_iter().chain(components.iter().cloned()).map(Symbol::intern)
@@ -2769,9 +2769,9 @@ impl<'a> LoweringContext<'a> {
27692769
let id = self.next_id();
27702770
let block = P(hir::Block {
27712771
rules: rule,
2772-
span: span,
2773-
id: id,
2774-
stmts: stmts,
2772+
span,
2773+
id,
2774+
stmts,
27752775
expr: Some(expr),
27762776
targeted_by_break: false,
27772777
});
@@ -2810,7 +2810,7 @@ impl<'a> LoweringContext<'a> {
28102810
fn elided_lifetime(&mut self, span: Span) -> hir::Lifetime {
28112811
hir::Lifetime {
28122812
id: self.next_id(),
2813-
span: span,
2813+
span,
28142814
name: keywords::Invalid.name()
28152815
}
28162816
}

0 commit comments

Comments
 (0)