Skip to content

Commit 510767c

Browse files
committed
Merge some ifs.
For more concise code.
1 parent bd33796 commit 510767c

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

compiler/rustc_mir_transform/src/check_packed_ref.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,17 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
3737
}
3838

3939
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
40-
if context.is_borrow() {
41-
if util::is_disaligned(self.tcx, self.body, self.param_env, *place) {
42-
let def_id = self.body.source.instance.def_id();
43-
if let Some(impl_def_id) = self.tcx.impl_of_method(def_id)
44-
&& self.tcx.is_builtin_derived(impl_def_id)
45-
{
46-
// If we ever reach here it means that the generated derive
47-
// code is somehow doing an unaligned reference, which it
48-
// shouldn't do.
49-
span_bug!(
50-
self.source_info.span,
51-
"builtin derive created an unaligned reference"
52-
);
53-
} else {
54-
self.tcx
55-
.dcx()
56-
.emit_err(errors::UnalignedPackedRef { span: self.source_info.span });
57-
}
40+
if context.is_borrow() && util::is_disaligned(self.tcx, self.body, self.param_env, *place) {
41+
let def_id = self.body.source.instance.def_id();
42+
if let Some(impl_def_id) = self.tcx.impl_of_method(def_id)
43+
&& self.tcx.is_builtin_derived(impl_def_id)
44+
{
45+
// If we ever reach here it means that the generated derive
46+
// code is somehow doing an unaligned reference, which it
47+
// shouldn't do.
48+
span_bug!(self.source_info.span, "builtin derive created an unaligned reference");
49+
} else {
50+
self.tcx.dcx().emit_err(errors::UnalignedPackedRef { span: self.source_info.span });
5851
}
5952
}
6053
}

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,12 +1182,10 @@ fn elaborate_coroutine_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
11821182
source_info,
11831183
kind: TerminatorKind::Drop { place, target, unwind, replace: _ },
11841184
} => {
1185-
if let Some(local) = place.as_local() {
1186-
if local == SELF_ARG {
1187-
(target, unwind, source_info)
1188-
} else {
1189-
continue;
1190-
}
1185+
if let Some(local) = place.as_local()
1186+
&& local == SELF_ARG
1187+
{
1188+
(target, unwind, source_info)
11911189
} else {
11921190
continue;
11931191
}

0 commit comments

Comments
 (0)