Skip to content

Commit e58fec0

Browse files
authored
Rollup merge of #70229 - matthiaskrgr:cl3ppy, r=Mark-Simulacrum
more clippy fixes * remove unused unit values (clippy::unused_unit) * make some let-if-bindings more idiomatic (clippy::useless_let_if_seq) * clarify when we pass () to functions (clippy::unit_arg) * don't redundantly repeat field names (clippy::redundant_field_names) * remove redundant returns (clippy::needless_return) * use let instead of match for matches with single bindings (clippy::match_single_binding) * don't convert results to options just for matching (clippy::if_let_some_result)
2 parents 3c8f8b6 + e45fdcf commit e58fec0

File tree

22 files changed

+92
-115
lines changed

22 files changed

+92
-115
lines changed

src/librustc/ty/layout.rs

Lines changed: 25 additions & 29 deletions
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/ty/query/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ impl<'tcx> TyCtxt<'tcx> {
746746
/// side-effects -- e.g., in order to report errors for erroneous programs.
747747
///
748748
/// Note: The optimization is only available during incr. comp.
749-
pub(super) fn ensure_query<Q: QueryDescription<'tcx> + 'tcx>(self, key: Q::Key) -> () {
749+
pub(super) fn ensure_query<Q: QueryDescription<'tcx> + 'tcx>(self, key: Q::Key) {
750750
if Q::EVAL_ALWAYS {
751751
let _ = self.get_query::<Q>(DUMMY_SP, key);
752752
return;

src/librustc_builtin_macros/deriving/generic/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,9 @@ impl<'a> MethodDef<'a> {
10561056
self_: field,
10571057
other: other_fields
10581058
.iter_mut()
1059-
.map(|l| match l.next().unwrap() {
1060-
(.., ex, _) => ex,
1059+
.map(|l| {
1060+
let (.., ex, _) = l.next().unwrap();
1061+
ex
10611062
})
10621063
.collect(),
10631064
attrs,

src/librustc_infer/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub type NormalizedTy<'tcx> = Normalized<'tcx, Ty<'tcx>>;
2323

2424
impl<'tcx, T> Normalized<'tcx, T> {
2525
pub fn with<U>(self, value: U) -> Normalized<'tcx, U> {
26-
Normalized { value: value, obligations: self.obligations }
26+
Normalized { value, obligations: self.obligations }
2727
}
2828
}
2929

src/librustc_infer/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct PredicateSet<'tcx> {
4747

4848
impl PredicateSet<'tcx> {
4949
fn new(tcx: TyCtxt<'tcx>) -> Self {
50-
Self { tcx: tcx, set: Default::default() }
50+
Self { tcx, set: Default::default() }
5151
}
5252

5353
fn insert(&mut self, pred: &ty::Predicate<'tcx>) -> bool {

src/librustc_mir/borrow_check/diagnostics/move_errors.rs

Lines changed: 4 additions & 8 deletions
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/const_eval/machine.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
335335
}
336336

337337
#[inline(always)]
338-
fn tag_static_base_pointer(_memory_extra: &MemoryExtra, _id: AllocId) -> Self::PointerTag {
339-
()
340-
}
338+
fn tag_static_base_pointer(_memory_extra: &MemoryExtra, _id: AllocId) -> Self::PointerTag {}
341339

342340
fn box_alloc(
343341
_ecx: &mut InterpCx<'mir, 'tcx, Self>,

src/librustc_mir/interpret/eval_context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
581581
/// If `target` is `None`, that indicates the function cannot return, so we raise UB.
582582
pub fn return_to_block(&mut self, target: Option<mir::BasicBlock>) -> InterpResult<'tcx> {
583583
if let Some(target) = target {
584-
Ok(self.go_to_block(target))
584+
self.go_to_block(target);
585+
Ok(())
585586
} else {
586587
throw_ub!(Unreachable)
587588
}

src/librustc_mir/interpret/intrinsics/type_name.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ impl PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
192192

193193
impl Write for AbsolutePathPrinter<'_> {
194194
fn write_str(&mut self, s: &str) -> std::fmt::Result {
195-
Ok(self.path.push_str(s))
195+
self.path.push_str(s);
196+
Ok(())
196197
}
197198
}
198199

src/librustc_mir/interpret/terminator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
370370
self.stack.pop();
371371
Err(err)
372372
}
373-
Ok(v) => Ok(v),
373+
Ok(()) => Ok(()),
374374
}
375375
}
376376
// cannot use the shim here, because that will only result in infinite recursion

0 commit comments

Comments
 (0)