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

+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/ty/query/plumbing.rs

+1-1
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

+3-2
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

+1-1
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

+1-1
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

+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/const_eval/machine.rs

+1-3
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

+2-1
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

+2-1
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

+1-1
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

src/librustc_mir/transform/const_prop.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
232232
}
233233

234234
#[inline(always)]
235-
fn tag_static_base_pointer(_memory_extra: &(), _id: AllocId) -> Self::PointerTag {
236-
()
237-
}
235+
fn tag_static_base_pointer(_memory_extra: &(), _id: AllocId) -> Self::PointerTag {}
238236

239237
fn box_alloc(
240238
_ecx: &mut InterpCx<'mir, 'tcx, Self>,

src/librustc_mir_build/build/expr/as_temp.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7373
// they are never assigned.
7474
ExprKind::Break { .. } | ExprKind::Continue { .. } | ExprKind::Return { .. } => (),
7575
ExprKind::Block { body: hir::Block { expr: None, targeted_by_break: false, .. } }
76-
if expr_ty.is_never() =>
77-
{
78-
()
79-
}
76+
if expr_ty.is_never() => {}
8077
_ => {
8178
this.cfg
8279
.push(block, Statement { source_info, kind: StatementKind::StorageLive(temp) });

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> {

src/librustc_span/source_map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,11 @@ impl SourceMap {
370370
pub fn doctest_offset_line(&self, file: &FileName, orig: usize) -> usize {
371371
match file {
372372
FileName::DocTest(_, offset) => {
373-
return if *offset >= 0 {
374-
orig + *offset as usize
375-
} else {
373+
if *offset < 0 {
376374
orig - (-(*offset)) as usize
377-
};
375+
} else {
376+
orig + *offset as usize
377+
}
378378
}
379379
_ => orig,
380380
}

src/librustc_target/spec/apple_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn macos_link_env_remove() -> Vec<String> {
5757
let mut env_remove = Vec::with_capacity(2);
5858
// Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
5959
// may occur when we're linking a custom build script while targeting iOS for example.
60-
if let Some(sdkroot) = env::var("SDKROOT").ok() {
60+
if let Ok(sdkroot) = env::var("SDKROOT") {
6161
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("iPhoneSimulator.platform") {
6262
env_remove.push("SDKROOT".to_string())
6363
}

src/librustc_target/spec/apple_sdk_base.rs

+7-21
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,26 @@ pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
4343
// to allow the SDK path to be set. (For clang, xcrun sets
4444
// SDKROOT; for rustc, the user or build system can set it, or we
4545
// can fall back to checking for xcrun on PATH.)
46-
if let Some(sdkroot) = env::var("SDKROOT").ok() {
46+
if let Ok(sdkroot) = env::var("SDKROOT") {
4747
let p = Path::new(&sdkroot);
4848
match sdk_name {
4949
// Ignore `SDKROOT` if it's clearly set for the wrong platform.
5050
"appletvos"
5151
if sdkroot.contains("TVSimulator.platform")
52-
|| sdkroot.contains("MacOSX.platform") =>
53-
{
54-
()
55-
}
52+
|| sdkroot.contains("MacOSX.platform") => {}
5653
"appletvsimulator"
57-
if sdkroot.contains("TVOS.platform") || sdkroot.contains("MacOSX.platform") =>
58-
{
59-
()
60-
}
54+
if sdkroot.contains("TVOS.platform") || sdkroot.contains("MacOSX.platform") => {}
6155
"iphoneos"
6256
if sdkroot.contains("iPhoneSimulator.platform")
63-
|| sdkroot.contains("MacOSX.platform") =>
64-
{
65-
()
66-
}
57+
|| sdkroot.contains("MacOSX.platform") => {}
6758
"iphonesimulator"
68-
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("MacOSX.platform") =>
69-
{
70-
()
59+
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("MacOSX.platform") => {
7160
}
7261
"macosx10.15"
7362
if sdkroot.contains("iPhoneOS.platform")
74-
|| sdkroot.contains("iPhoneSimulator.platform") =>
75-
{
76-
()
77-
}
63+
|| sdkroot.contains("iPhoneSimulator.platform") => {}
7864
// Ignore `SDKROOT` if it's not a valid path.
79-
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => (),
65+
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {}
8066
_ => return Ok(sdkroot),
8167
}
8268
}

src/librustc_trait_selection/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2792,7 +2792,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
27922792
trait_def_id, trait_obligations
27932793
);
27942794

2795-
VtableTraitAliasData { alias_def_id, substs: substs, nested: trait_obligations }
2795+
VtableTraitAliasData { alias_def_id, substs, nested: trait_obligations }
27962796
})
27972797
}
27982798

src/librustc_traits/type_op.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ impl AscribeUserTypeCx<'me, 'tcx> {
8080
where
8181
T: ToTrace<'tcx>,
8282
{
83-
Ok(self
84-
.infcx
83+
self.infcx
8584
.at(&ObligationCause::dummy(), self.param_env)
8685
.relate(a, variance, b)?
87-
.into_value_registering_obligations(self.infcx, self.fulfill_cx))
86+
.into_value_registering_obligations(self.infcx, self.fulfill_cx);
87+
Ok(())
8888
}
8989

9090
fn prove_predicate(&mut self, predicate: Predicate<'tcx>) {
@@ -165,10 +165,11 @@ fn type_op_eq<'tcx>(
165165
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
166166
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| {
167167
let (param_env, Eq { a, b }) = key.into_parts();
168-
Ok(infcx
168+
infcx
169169
.at(&ObligationCause::dummy(), param_env)
170170
.eq(a, b)?
171-
.into_value_registering_obligations(infcx, fulfill_cx))
171+
.into_value_registering_obligations(infcx, fulfill_cx);
172+
Ok(())
172173
})
173174
}
174175

@@ -221,10 +222,11 @@ fn type_op_subtype<'tcx>(
221222
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
222223
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| {
223224
let (param_env, Subtype { sub, sup }) = key.into_parts();
224-
Ok(infcx
225+
infcx
225226
.at(&ObligationCause::dummy(), param_env)
226227
.sup(sup, sub)?
227-
.into_value_registering_obligations(infcx, fulfill_cx))
228+
.into_value_registering_obligations(infcx, fulfill_cx);
229+
Ok(())
228230
})
229231
}
230232

0 commit comments

Comments
 (0)