Skip to content

Commit 42596a7

Browse files
authored
Rollup merge of rust-lang#94476 - c410-f3r:yet-more-let-chains, r=Dylan-DPC
7 - Make more use of `let_chains` Continuation of rust-lang#94376. cc rust-lang#53667
2 parents 2b72ecb + 7aa5ea9 commit 42596a7

File tree

9 files changed

+100
-112
lines changed

9 files changed

+100
-112
lines changed

compiler/rustc_mir_transform/src/const_debuginfo.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ fn find_optimization_oportunities<'tcx>(body: &Body<'tcx>) -> Vec<(Local, Consta
5555

5656
let mut locals_to_debuginfo = BitSet::new_empty(body.local_decls.len());
5757
for debuginfo in &body.var_debug_info {
58-
if let VarDebugInfoContents::Place(p) = debuginfo.value {
59-
if let Some(l) = p.as_local() {
60-
locals_to_debuginfo.insert(l);
61-
}
58+
if let VarDebugInfoContents::Place(p) = debuginfo.value && let Some(l) = p.as_local() {
59+
locals_to_debuginfo.insert(l);
6260
}
6361
}
6462

compiler/rustc_mir_transform/src/const_prop.rs

+23-27
Original file line numberDiff line numberDiff line change
@@ -633,24 +633,22 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
633633
fn propagate_operand(&mut self, operand: &mut Operand<'tcx>) {
634634
match *operand {
635635
Operand::Copy(l) | Operand::Move(l) => {
636-
if let Some(value) = self.get_const(l) {
637-
if self.should_const_prop(&value) {
638-
// FIXME(felix91gr): this code only handles `Scalar` cases.
639-
// For now, we're not handling `ScalarPair` cases because
640-
// doing so here would require a lot of code duplication.
641-
// We should hopefully generalize `Operand` handling into a fn,
642-
// and use it to do const-prop here and everywhere else
643-
// where it makes sense.
644-
if let interpret::Operand::Immediate(interpret::Immediate::Scalar(
645-
ScalarMaybeUninit::Scalar(scalar),
646-
)) = *value
647-
{
648-
*operand = self.operand_from_scalar(
649-
scalar,
650-
value.layout.ty,
651-
self.source_info.unwrap().span,
652-
);
653-
}
636+
if let Some(value) = self.get_const(l) && self.should_const_prop(&value) {
637+
// FIXME(felix91gr): this code only handles `Scalar` cases.
638+
// For now, we're not handling `ScalarPair` cases because
639+
// doing so here would require a lot of code duplication.
640+
// We should hopefully generalize `Operand` handling into a fn,
641+
// and use it to do const-prop here and everywhere else
642+
// where it makes sense.
643+
if let interpret::Operand::Immediate(interpret::Immediate::Scalar(
644+
ScalarMaybeUninit::Scalar(scalar),
645+
)) = *value
646+
{
647+
*operand = self.operand_from_scalar(
648+
scalar,
649+
value.layout.ty,
650+
self.source_info.unwrap().span,
651+
);
654652
}
655653
}
656654
}
@@ -1086,15 +1084,13 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
10861084
// This will return None if the above `const_prop` invocation only "wrote" a
10871085
// type whose creation requires no write. E.g. a generator whose initial state
10881086
// consists solely of uninitialized memory (so it doesn't capture any locals).
1089-
if let Some(ref value) = self.get_const(place) {
1090-
if self.should_const_prop(value) {
1091-
trace!("replacing {:?} with {:?}", rval, value);
1092-
self.replace_with_const(rval, value, source_info);
1093-
if can_const_prop == ConstPropMode::FullConstProp
1094-
|| can_const_prop == ConstPropMode::OnlyInsideOwnBlock
1095-
{
1096-
trace!("propagated into {:?}", place);
1097-
}
1087+
if let Some(ref value) = self.get_const(place) && self.should_const_prop(value) {
1088+
trace!("replacing {:?} with {:?}", rval, value);
1089+
self.replace_with_const(rval, value, source_info);
1090+
if can_const_prop == ConstPropMode::FullConstProp
1091+
|| can_const_prop == ConstPropMode::OnlyInsideOwnBlock
1092+
{
1093+
trace!("propagated into {:?}", place);
10981094
}
10991095
}
11001096
match can_const_prop {

compiler/rustc_mir_transform/src/coverage/debug.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,12 @@ impl DebugCounters {
357357
if let Some(counters) = &self.some_counters {
358358
if let Some(DebugCounter { counter_kind, some_block_label }) = counters.get(&operand) {
359359
if let CoverageKind::Expression { .. } = counter_kind {
360-
if let Some(block_label) = some_block_label {
361-
if debug_options().counter_format.block {
362-
return format!(
363-
"{}:({})",
364-
block_label,
365-
self.format_counter_kind(counter_kind)
366-
);
367-
}
360+
if let Some(label) = some_block_label && debug_options().counter_format.block {
361+
return format!(
362+
"{}:({})",
363+
label,
364+
self.format_counter_kind(counter_kind)
365+
);
368366
}
369367
return format!("({})", self.format_counter_kind(counter_kind));
370368
}

compiler/rustc_mir_transform/src/coverage/spans.rs

+19-24
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,13 @@ impl CoverageSpan {
191191
/// If the span is part of a macro, and the macro is visible (expands directly to the given
192192
/// body_span), returns the macro name symbol.
193193
pub fn visible_macro(&self, body_span: Span) -> Option<Symbol> {
194-
if let Some(current_macro) = self.current_macro() {
195-
if self
196-
.expn_span
197-
.parent_callsite()
198-
.unwrap_or_else(|| bug!("macro must have a parent"))
199-
.ctxt()
200-
== body_span.ctxt()
201-
{
202-
return Some(current_macro);
203-
}
194+
if let Some(current_macro) = self.current_macro() && self
195+
.expn_span
196+
.parent_callsite()
197+
.unwrap_or_else(|| bug!("macro must have a parent"))
198+
.ctxt() == body_span.ctxt()
199+
{
200+
return Some(current_macro);
204201
}
205202
None
206203
}
@@ -584,21 +581,19 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
584581
/// In either case, no more spans will match the span of `pending_dups`, so
585582
/// add the `pending_dups` if they don't overlap `curr`, and clear the list.
586583
fn check_pending_dups(&mut self) {
587-
if let Some(dup) = self.pending_dups.last() {
588-
if dup.span != self.prev().span {
589-
debug!(
590-
" SAME spans, but pending_dups are NOT THE SAME, so BCBs matched on \
591-
previous iteration, or prev started a new disjoint span"
592-
);
593-
if dup.span.hi() <= self.curr().span.lo() {
594-
let pending_dups = self.pending_dups.split_off(0);
595-
for dup in pending_dups.into_iter() {
596-
debug!(" ...adding at least one pending={:?}", dup);
597-
self.push_refined_span(dup);
598-
}
599-
} else {
600-
self.pending_dups.clear();
584+
if let Some(dup) = self.pending_dups.last() && dup.span != self.prev().span {
585+
debug!(
586+
" SAME spans, but pending_dups are NOT THE SAME, so BCBs matched on \
587+
previous iteration, or prev started a new disjoint span"
588+
);
589+
if dup.span.hi() <= self.curr().span.lo() {
590+
let pending_dups = self.pending_dups.split_off(0);
591+
for dup in pending_dups.into_iter() {
592+
debug!(" ...adding at least one pending={:?}", dup);
593+
self.push_refined_span(dup);
601594
}
595+
} else {
596+
self.pending_dups.clear();
602597
}
603598
}
604599
}

compiler/rustc_mir_transform/src/dest_prop.rs

+36-32
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,15 @@ impl<'a> Conflicts<'a> {
549549
target: _,
550550
unwind: _,
551551
} => {
552-
if let Some(place) = value.place() {
553-
if !place.is_indirect() && !dropped_place.is_indirect() {
554-
self.record_local_conflict(
555-
place.local,
556-
dropped_place.local,
557-
"DropAndReplace operand overlap",
558-
);
559-
}
552+
if let Some(place) = value.place()
553+
&& !place.is_indirect()
554+
&& !dropped_place.is_indirect()
555+
{
556+
self.record_local_conflict(
557+
place.local,
558+
dropped_place.local,
559+
"DropAndReplace operand overlap",
560+
);
560561
}
561562
}
562563
TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } => {
@@ -614,14 +615,15 @@ impl<'a> Conflicts<'a> {
614615
for op in operands {
615616
match op {
616617
InlineAsmOperand::In { reg: _, value } => {
617-
if let Some(p) = value.place() {
618-
if !p.is_indirect() && !dest_place.is_indirect() {
619-
self.record_local_conflict(
620-
p.local,
621-
dest_place.local,
622-
"asm! operand overlap",
623-
);
624-
}
618+
if let Some(p) = value.place()
619+
&& !p.is_indirect()
620+
&& !dest_place.is_indirect()
621+
{
622+
self.record_local_conflict(
623+
p.local,
624+
dest_place.local,
625+
"asm! operand overlap",
626+
);
625627
}
626628
}
627629
InlineAsmOperand::Out {
@@ -643,24 +645,26 @@ impl<'a> Conflicts<'a> {
643645
in_value,
644646
out_place,
645647
} => {
646-
if let Some(place) = in_value.place() {
647-
if !place.is_indirect() && !dest_place.is_indirect() {
648-
self.record_local_conflict(
649-
place.local,
650-
dest_place.local,
651-
"asm! operand overlap",
652-
);
653-
}
648+
if let Some(place) = in_value.place()
649+
&& !place.is_indirect()
650+
&& !dest_place.is_indirect()
651+
{
652+
self.record_local_conflict(
653+
place.local,
654+
dest_place.local,
655+
"asm! operand overlap",
656+
);
654657
}
655658

656-
if let Some(place) = out_place {
657-
if !place.is_indirect() && !dest_place.is_indirect() {
658-
self.record_local_conflict(
659-
place.local,
660-
dest_place.local,
661-
"asm! operand overlap",
662-
);
663-
}
659+
if let Some(place) = out_place
660+
&& !place.is_indirect()
661+
&& !dest_place.is_indirect()
662+
{
663+
self.record_local_conflict(
664+
place.local,
665+
dest_place.local,
666+
"asm! operand overlap",
667+
);
664668
}
665669
}
666670
InlineAsmOperand::Out { reg: _, late: _, place: None }

compiler/rustc_mir_transform/src/inline.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -724,12 +724,11 @@ impl<'tcx> Inliner<'tcx> {
724724
caller_body: &mut Body<'tcx>,
725725
) -> Local {
726726
// Reuse the operand if it is a moved temporary.
727-
if let Operand::Move(place) = &arg {
728-
if let Some(local) = place.as_local() {
729-
if caller_body.local_kind(local) == LocalKind::Temp {
730-
return local;
731-
}
732-
}
727+
if let Operand::Move(place) = &arg
728+
&& let Some(local) = place.as_local()
729+
&& caller_body.local_kind(local) == LocalKind::Temp
730+
{
731+
return local;
733732
}
734733

735734
// Otherwise, create a temporary for the argument.

compiler/rustc_mir_transform/src/instcombine.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
7777
_ => None,
7878
};
7979

80-
if let Some(new) = new {
81-
if self.should_combine(source_info, rvalue) {
82-
*rvalue = new;
83-
}
80+
if let Some(new) = new && self.should_combine(source_info, rvalue) {
81+
*rvalue = new;
8482
}
8583
}
8684

compiler/rustc_mir_transform/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
#![allow(rustc::potential_query_instability)]
12
#![feature(box_patterns)]
23
#![feature(box_syntax)]
34
#![feature(crate_visibility_modifier)]
5+
#![feature(let_chains)]
46
#![feature(let_else)]
57
#![feature(map_try_insert)]
68
#![feature(min_specialization)]
7-
#![feature(option_get_or_insert_default)]
8-
#![feature(once_cell)]
99
#![feature(never_type)]
10+
#![feature(once_cell)]
11+
#![feature(option_get_or_insert_default)]
1012
#![feature(trusted_step)]
1113
#![feature(try_blocks)]
1214
#![recursion_limit = "256"]
13-
#![allow(rustc::potential_query_instability)]
1415

1516
#[macro_use]
1617
extern crate tracing;

compiler/rustc_mir_transform/src/required_consts.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ impl<'a, 'tcx> RequiredConstsVisitor<'a, 'tcx> {
1414

1515
impl<'tcx> Visitor<'tcx> for RequiredConstsVisitor<'_, 'tcx> {
1616
fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) {
17-
if let Some(ct) = constant.literal.const_for_ty() {
18-
if let ConstKind::Unevaluated(_) = ct.val() {
19-
self.required_consts.push(*constant);
20-
}
17+
let literal = constant.literal;
18+
if let Some(ct) = literal.const_for_ty() && let ConstKind::Unevaluated(_) = ct.val() {
19+
self.required_consts.push(*constant);
2120
}
2221
}
2322
}

0 commit comments

Comments
 (0)