Skip to content

Commit 71b694c

Browse files
committed
formatting changes to pass 'test tidy'
1 parent 1024689 commit 71b694c

File tree

7 files changed

+61
-41
lines changed

7 files changed

+61
-41
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,18 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
205205
cold_br: Option<bool>,
206206
) {
207207
// emit the branch instruction
208-
let n = unsafe {
209-
llvm::LLVMBuildCondBr(self.llbuilder, cond, then_llbb, else_llbb)
210-
};
208+
let n = unsafe { llvm::LLVMBuildCondBr(self.llbuilder, cond, then_llbb, else_llbb) };
211209

212210
// if one of the branches is cold, emit metadata with branch weights
213211
if let Some(cold_br) = cold_br {
214212
unsafe {
215213
let s = "branch_weights";
216214
let v = [
217-
llvm::LLVMMDStringInContext(self.cx.llcx, s.as_ptr() as *const c_char, s.len() as c_uint),
215+
llvm::LLVMMDStringInContext(
216+
self.cx.llcx,
217+
s.as_ptr() as *const c_char,
218+
s.len() as c_uint,
219+
),
218220
self.cx.const_u32(if cold_br { 1 } else { 2000 }), // 'then' branch weight
219221
self.cx.const_u32(if cold_br { 2000 } else { 1 }), // 'else' branch weight
220222
];

compiler/rustc_codegen_ssa/src/mir/block.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -327,20 +327,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
327327
let (test_value, target) = target_iter.next().unwrap();
328328
let lltrue = helper.llbb_with_cleanup(self, target);
329329
let llfalse = helper.llbb_with_cleanup(self, targets.otherwise());
330-
let cold_br = targets.cold_target().and_then(|t| {
331-
if t == 0 { Some(true) } else { Some(false) }
332-
});
330+
let cold_br =
331+
targets.cold_target().and_then(|t| if t == 0 { Some(true) } else { Some(false) });
333332

334333
if switch_ty == bx.tcx().types.bool {
335334
// Don't generate trivial icmps when switching on bool.
336335
match test_value {
337336
0 => {
338337
let cold_br = cold_br.and_then(|t| Some(!t));
339338
bx.cond_br_with_cold_br(discr.immediate(), llfalse, lltrue, cold_br);
340-
},
341-
1 => {
342-
bx.cond_br_with_cold_br(discr.immediate(), lltrue, llfalse, cold_br)
343-
},
339+
}
340+
1 => bx.cond_br_with_cold_br(discr.immediate(), lltrue, llfalse, cold_br),
344341
_ => bug!(),
345342
}
346343
} else {

compiler/rustc_data_structures/src/stable_hasher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use crate::sip128::SipHasher128;
22
use rustc_index::bit_set::{self, BitSet};
33
use rustc_index::{Idx, IndexSlice, IndexVec};
44
use smallvec::SmallVec;
5-
use thin_vec::ThinVec;
65
use std::fmt;
76
use std::hash::{BuildHasher, Hash, Hasher};
87
use std::marker::PhantomData;
98
use std::mem;
9+
use thin_vec::ThinVec;
1010

1111
#[cfg(test)]
1212
mod tests;

compiler/rustc_middle/src/mir/terminator.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ impl SwitchTargets {
6161
}
6262
}
6363

64+
// If this switch has exactly one target, returns it.
6465
pub fn cold_target(&self) -> Option<usize> {
65-
if self.cold_targets.len() == 1 {
66-
Some(self.cold_targets[0])
67-
} else {
68-
None
69-
}
66+
if self.cold_targets.len() == 1 { Some(self.cold_targets[0]) } else { None }
7067
}
7168

7269
/// Returns the fallback target that is jumped to when none of the values match the operand.
@@ -402,13 +399,15 @@ impl<'tcx> TerminatorKind<'tcx> {
402399
t: BasicBlock,
403400
f: BasicBlock,
404401
cold_branch: Option<bool>,
405-
) -> TerminatorKind<'tcx> {
402+
) -> TerminatorKind<'tcx> {
406403
TerminatorKind::SwitchInt {
407404
discr: cond,
408405
targets: SwitchTargets::static_if_with_cold_br(
409-
0, f, t,
406+
0,
407+
f,
408+
t,
410409
// we compare to zero, so have to invert the branch
411-
cold_branch.and_then(|b| Some(!b))
410+
cold_branch.and_then(|b| Some(!b)),
412411
),
413412
}
414413
}

compiler/rustc_mir_build/src/build/matches/mod.rs

+27-18
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6363
break_scope,
6464
variable_source_info,
6565
declare_bindings,
66-
match cold_branch { Some(false) => Some(false), _ => None },
66+
match cold_branch {
67+
Some(false) => Some(false),
68+
_ => None,
69+
},
6770
));
6871

6972
let rhs_then_block = unpack!(this.then_else_break(
@@ -89,7 +92,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8992
local_scope,
9093
variable_source_info,
9194
true,
92-
match cold_branch { Some(true) => Some(true), _ => None },
95+
match cold_branch {
96+
Some(true) => Some(true),
97+
_ => None,
98+
},
9399
)
94100
});
95101
let rhs_success_block = unpack!(this.then_else_break(
@@ -167,12 +173,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
167173

168174
let then_block = this.cfg.start_new_block();
169175
let else_block = this.cfg.start_new_block();
170-
let term = TerminatorKind::if_with_cold_br(
171-
operand,
172-
then_block,
173-
else_block,
174-
cold_branch
175-
);
176+
let term =
177+
TerminatorKind::if_with_cold_br(operand, then_block, else_block, cold_branch);
176178

177179
let source_info = this.source_info(expr_span);
178180
this.cfg.terminate(block, source_info, term);
@@ -307,8 +309,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
307309
let arm = &self.thir[arm];
308310
let arm_has_guard = arm.guard.is_some();
309311
let arm_is_cold = arm.is_cold;
310-
let arm_candidate =
311-
Candidate::new(scrutinee.clone(), &arm.pattern, arm_has_guard, arm_is_cold, self);
312+
let arm_candidate = Candidate::new(
313+
scrutinee.clone(),
314+
&arm.pattern,
315+
arm_has_guard,
316+
arm_is_cold,
317+
self,
318+
);
312319
(arm, arm_candidate)
313320
})
314321
.collect()
@@ -667,7 +674,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
667674
initializer: PlaceBuilder<'tcx>,
668675
set_match_place: bool,
669676
) -> BlockAnd<()> {
670-
let mut candidate = Candidate::new(initializer.clone(), irrefutable_pat, false, false, self);
677+
let mut candidate =
678+
Candidate::new(initializer.clone(), irrefutable_pat, false, false, self);
671679
let fake_borrow_temps = self.lower_match_tree(
672680
block,
673681
irrefutable_pat.span,
@@ -1520,7 +1528,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15201528
debug!("candidate={:#?}\npats={:#?}", candidate, pats);
15211529
let mut or_candidates: Vec<_> = pats
15221530
.iter()
1523-
.map(|pat| Candidate::new(place.clone(), pat, candidate.has_guard, candidate.is_cold, self))
1531+
.map(|pat| {
1532+
Candidate::new(place.clone(), pat, candidate.has_guard, candidate.is_cold, self)
1533+
})
15241534
.collect();
15251535
let mut or_candidate_refs: Vec<_> = or_candidates.iter_mut().collect();
15261536
let otherwise = if candidate.otherwise_block.is_some() {
@@ -1771,10 +1781,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17711781
// Find cold targets.
17721782
let mut cold_targets: ThinVec<usize> = ThinVec::new();
17731783

1774-
let is_otherwise_target_cold =
1775-
candidates.len() > 0 &&
1776-
candidates.iter().all(|c| c.is_cold);// && c.match_pairs.is_empty());
1777-
if is_otherwise_target_cold {
1784+
let is_otherwise_target_cold = candidates.len() > 0 && candidates.iter().all(|c| c.is_cold);
1785+
if is_otherwise_target_cold {
17781786
cold_targets.push(target_candidates.len());
17791787
}
17801788

@@ -1849,7 +1857,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
18491857
&match_place,
18501858
&test,
18511859
target_blocks,
1852-
cold_targets
1860+
cold_targets,
18531861
);
18541862
}
18551863

@@ -1948,7 +1956,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19481956
let expr_span = self.thir[expr_id].span;
19491957
let expr_place_builder = unpack!(block = self.lower_scrutinee(block, expr_id, expr_span));
19501958
let wildcard = Pat::wildcard_from_ty(pat.ty);
1951-
let mut guard_candidate = Candidate::new(expr_place_builder.clone(), pat, false, false, self);
1959+
let mut guard_candidate =
1960+
Candidate::new(expr_place_builder.clone(), pat, false, false, self);
19521961
let mut otherwise_candidate =
19531962
Candidate::new(expr_place_builder.clone(), &wildcard, false, false, self);
19541963
let fake_borrow_temps = self.lower_match_tree(

compiler/rustc_mir_build/src/build/matches/simplify.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
127127
) -> Vec<Candidate<'pat, 'tcx>> {
128128
pats.iter()
129129
.map(|box pat| {
130-
let mut candidate = Candidate::new(place.clone(), pat, candidate.has_guard, candidate.is_cold, self);
130+
let mut candidate = Candidate::new(
131+
place.clone(),
132+
pat,
133+
candidate.has_guard,
134+
candidate.is_cold,
135+
self,
136+
);
131137
self.simplify_candidate(&mut candidate);
132138
candidate
133139
})

compiler/rustc_mir_build/src/build/matches/test.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
219219
None
220220
} else {
221221
for i in cold_targets.iter() {
222-
if *i < 2 { cold_br[*i] = true; }
222+
if *i < 2 {
223+
cold_br[*i] = true;
224+
}
223225
}
224226
if cold_br[0] != cold_br[1] { Some(cold_br[0]) } else { None }
225227
};
@@ -231,7 +233,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
231233
0 => (second_bb, first_bb, cold_br.and_then(|x| Some(!x))),
232234
v => span_bug!(test.span, "expected boolean value but got {:?}", v),
233235
};
234-
TerminatorKind::if_with_cold_br(Operand::Copy(place), true_bb, false_bb, cold_br)
236+
TerminatorKind::if_with_cold_br(
237+
Operand::Copy(place),
238+
true_bb,
239+
false_bb,
240+
cold_br,
241+
)
235242
} else {
236243
// The switch may be inexhaustive so we have a catch all block
237244
debug_assert_eq!(options.len() + 1, target_blocks.len());

0 commit comments

Comments
 (0)