Skip to content

Commit

Permalink
make some let-if-bindings more idiomatic (clippy::useless_let_if_seq)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskrgr committed Mar 21, 2020
1 parent a6692b7 commit 47e9775
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 46 deletions.
54 changes: 25 additions & 29 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
// Field 5 would be the first element, so memory_index is i:
// Note: if we didn't optimize, it's already right.

let memory_index;
if optimize {
memory_index = invert_mapping(&inverse_memory_index);
} else {
memory_index = inverse_memory_index;
}
let memory_index =
if optimize { invert_mapping(&inverse_memory_index) } else { inverse_memory_index };

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

let mut abi = match st[i].abi {
Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()),
Abi::ScalarPair(ref first, ref second) => {
// We need to use scalar_unit to reset the
// valid range to the maximal one for that
// primitive, because only the niche is
// guaranteed to be initialised, not the
// other primitive.
if offset.bytes() == 0 {
Abi::ScalarPair(
niche_scalar.clone(),
scalar_unit(second.value),
)
} else {
Abi::ScalarPair(
scalar_unit(first.value),
niche_scalar.clone(),
)
let abi = if st.iter().all(|v| v.abi.is_uninhabited()) {
Abi::Uninhabited
} else {
match st[i].abi {
Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()),
Abi::ScalarPair(ref first, ref second) => {
// We need to use scalar_unit to reset the
// valid range to the maximal one for that
// primitive, because only the niche is
// guaranteed to be initialised, not the
// other primitive.
if offset.bytes() == 0 {
Abi::ScalarPair(
niche_scalar.clone(),
scalar_unit(second.value),
)
} else {
Abi::ScalarPair(
scalar_unit(first.value),
niche_scalar.clone(),
)
}
}
_ => Abi::Aggregate { sized: true },
}
_ => Abi::Aggregate { sized: true },
};

if st.iter().all(|v| v.abi.is_uninhabited()) {
abi = Abi::Uninhabited;
}

let largest_niche =
Niche::from_scalar(dl, offset, niche_scalar.clone());

Expand Down
12 changes: 4 additions & 8 deletions src/librustc_mir/borrow_check/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,17 +490,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
{
if pat_snippet.starts_with('&') {
let pat_snippet = pat_snippet[1..].trim_start();
let suggestion;
let to_remove;
if pat_snippet.starts_with("mut")
let (suggestion, to_remove) = if pat_snippet.starts_with("mut")
&& pat_snippet["mut".len()..].starts_with(rustc_lexer::is_whitespace)
{
suggestion = pat_snippet["mut".len()..].trim_start();
to_remove = "&mut";
(pat_snippet["mut".len()..].trim_start(), "&mut")
} else {
suggestion = pat_snippet;
to_remove = "&";
}
(pat_snippet, "&")
};
suggestions.push((pat_span, to_remove, suggestion.to_owned()));
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_mir_build/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,12 @@ where
);
assert_eq!(block, builder.return_block());

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

let mut body = builder.finish();
Expand Down
12 changes: 7 additions & 5 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,14 +750,16 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
// If this is a tuple or unit struct, define a name
// in the value namespace as well.
if let Some(ctor_node_id) = vdata.ctor_id() {
let mut ctor_vis = vis;
// If the structure is marked as non_exhaustive then lower the visibility
// to within the crate.
if vis == ty::Visibility::Public
let mut ctor_vis = if vis == ty::Visibility::Public
&& attr::contains_name(&item.attrs, sym::non_exhaustive)
{
ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX));
}
ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))
} else {
vis
};

for field in vdata.fields() {
// NOTE: The field may be an expansion placeholder, but expansion sets
// correct visibilities for unnamed field placeholders specifically, so the
Expand Down Expand Up @@ -1166,7 +1168,7 @@ macro_rules! method {
visit::$walk(self, node);
}
}
}
};
}

impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
Expand Down

0 comments on commit 47e9775

Please sign in to comment.