Skip to content

Commit 47e9775

Browse files
committed
make some let-if-bindings more idiomatic (clippy::useless_let_if_seq)
1 parent a6692b7 commit 47e9775

File tree

4 files changed

+41
-46
lines changed

4 files changed

+41
-46
lines changed

src/librustc/ty/layout.rs

+25-29
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
381381
// Field 5 would be the first element, so memory_index is i:
382382
// Note: if we didn't optimize, it's already right.
383383

384-
let memory_index;
385-
if optimize {
386-
memory_index = invert_mapping(&inverse_memory_index);
387-
} else {
388-
memory_index = inverse_memory_index;
389-
}
384+
let memory_index =
385+
if optimize { invert_mapping(&inverse_memory_index) } else { inverse_memory_index };
390386

391387
let size = min_size.align_to(align.abi);
392388
let mut abi = Abi::Aggregate { sized };
@@ -944,33 +940,33 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
944940
let offset = st[i].fields.offset(field_index) + niche.offset;
945941
let size = st[i].size;
946942

947-
let mut abi = match st[i].abi {
948-
Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()),
949-
Abi::ScalarPair(ref first, ref second) => {
950-
// We need to use scalar_unit to reset the
951-
// valid range to the maximal one for that
952-
// primitive, because only the niche is
953-
// guaranteed to be initialised, not the
954-
// other primitive.
955-
if offset.bytes() == 0 {
956-
Abi::ScalarPair(
957-
niche_scalar.clone(),
958-
scalar_unit(second.value),
959-
)
960-
} else {
961-
Abi::ScalarPair(
962-
scalar_unit(first.value),
963-
niche_scalar.clone(),
964-
)
943+
let abi = if st.iter().all(|v| v.abi.is_uninhabited()) {
944+
Abi::Uninhabited
945+
} else {
946+
match st[i].abi {
947+
Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()),
948+
Abi::ScalarPair(ref first, ref second) => {
949+
// We need to use scalar_unit to reset the
950+
// valid range to the maximal one for that
951+
// primitive, because only the niche is
952+
// guaranteed to be initialised, not the
953+
// other primitive.
954+
if offset.bytes() == 0 {
955+
Abi::ScalarPair(
956+
niche_scalar.clone(),
957+
scalar_unit(second.value),
958+
)
959+
} else {
960+
Abi::ScalarPair(
961+
scalar_unit(first.value),
962+
niche_scalar.clone(),
963+
)
964+
}
965965
}
966+
_ => Abi::Aggregate { sized: true },
966967
}
967-
_ => Abi::Aggregate { sized: true },
968968
};
969969

970-
if st.iter().all(|v| v.abi.is_uninhabited()) {
971-
abi = Abi::Uninhabited;
972-
}
973-
974970
let largest_niche =
975971
Niche::from_scalar(dl, offset, niche_scalar.clone());
976972

src/librustc_mir/borrow_check/diagnostics/move_errors.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -490,17 +490,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
490490
{
491491
if pat_snippet.starts_with('&') {
492492
let pat_snippet = pat_snippet[1..].trim_start();
493-
let suggestion;
494-
let to_remove;
495-
if pat_snippet.starts_with("mut")
493+
let (suggestion, to_remove) = if pat_snippet.starts_with("mut")
496494
&& pat_snippet["mut".len()..].starts_with(rustc_lexer::is_whitespace)
497495
{
498-
suggestion = pat_snippet["mut".len()..].trim_start();
499-
to_remove = "&mut";
496+
(pat_snippet["mut".len()..].trim_start(), "&mut")
500497
} else {
501-
suggestion = pat_snippet;
502-
to_remove = "&";
503-
}
498+
(pat_snippet, "&")
499+
};
504500
suggestions.push((pat_span, to_remove, suggestion.to_owned()));
505501
}
506502
}

src/librustc_mir_build/build/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,12 @@ where
637637
);
638638
assert_eq!(block, builder.return_block());
639639

640-
let mut spread_arg = None;
641-
if abi == Abi::RustCall {
640+
let spread_arg = if abi == Abi::RustCall {
642641
// RustCall pseudo-ABI untuples the last argument.
643-
spread_arg = Some(Local::new(arguments.len()));
644-
}
642+
Some(Local::new(arguments.len()))
643+
} else {
644+
None
645+
};
645646
debug!("fn_id {:?} has attrs {:?}", fn_def_id, tcx.get_attrs(fn_def_id));
646647

647648
let mut body = builder.finish();

src/librustc_resolve/build_reduced_graph.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -750,14 +750,16 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
750750
// If this is a tuple or unit struct, define a name
751751
// in the value namespace as well.
752752
if let Some(ctor_node_id) = vdata.ctor_id() {
753-
let mut ctor_vis = vis;
754753
// If the structure is marked as non_exhaustive then lower the visibility
755754
// to within the crate.
756-
if vis == ty::Visibility::Public
755+
let mut ctor_vis = if vis == ty::Visibility::Public
757756
&& attr::contains_name(&item.attrs, sym::non_exhaustive)
758757
{
759-
ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX));
760-
}
758+
ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))
759+
} else {
760+
vis
761+
};
762+
761763
for field in vdata.fields() {
762764
// NOTE: The field may be an expansion placeholder, but expansion sets
763765
// correct visibilities for unnamed field placeholders specifically, so the
@@ -1166,7 +1168,7 @@ macro_rules! method {
11661168
visit::$walk(self, node);
11671169
}
11681170
}
1169-
}
1171+
};
11701172
}
11711173

11721174
impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {

0 commit comments

Comments
 (0)