Skip to content

Commit 1da4a49

Browse files
committed
clippy::complexity fixes
filter_next needless_question_mark bind_instead_of_map manual_find derivable_impls map_identity redundant_slicing skip_while_next unnecessary_unwrap needless_bool
1 parent 48b3c46 commit 1da4a49

File tree

15 files changed

+26
-54
lines changed

15 files changed

+26
-54
lines changed

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
620620
self.impl_trait_defs = current_impl_trait_defs;
621621
self.impl_trait_bounds = current_impl_trait_bounds;
622622

623-
debug_assert!(self.children.iter().find(|(id, _)| id == &def_id).is_none());
623+
debug_assert!(!self.children.iter().any(|(id, _)| id == &def_id));
624624
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
625625
}
626626

Diff for: compiler/rustc_borrowck/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -2059,12 +2059,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20592059
) -> Option<InitIndex> {
20602060
let mpi = self.move_data.rev_lookup.find_local(local);
20612061
let ii = &self.move_data.init_path_map[mpi];
2062-
for &index in ii {
2063-
if flow_state.ever_inits.contains(index) {
2064-
return Some(index);
2065-
}
2066-
}
2067-
None
2062+
ii.into_iter().find(|&&index| flow_state.ever_inits.contains(index)).copied()
20682063
}
20692064

20702065
/// Adds the place into the used mutable variables set

Diff for: compiler/rustc_codegen_llvm/src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
233233
// Set KCFI operand bundle
234234
let is_indirect_call = unsafe { llvm::LLVMIsAFunction(llfn).is_none() };
235235
let kcfi_bundle =
236-
if self.tcx.sess.is_sanitizer_kcfi_enabled() && fn_abi.is_some() && is_indirect_call {
237-
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi.unwrap());
236+
if self.tcx.sess.is_sanitizer_kcfi_enabled() && let Some(fn_abi) = fn_abi && is_indirect_call {
237+
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi);
238238
Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)]))
239239
} else {
240240
None

Diff for: compiler/rustc_codegen_ssa/src/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn try_filter_fat_archs<'a>(
123123
) -> io::Result<Option<(&'a [u8], u64)>> {
124124
let archs = archs.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
125125

126-
let desired = match archs.iter().filter(|a| a.architecture() == target_arch).next() {
126+
let desired = match archs.iter().find(|a| a.architecture() == target_arch) {
127127
Some(a) => a,
128128
None => return Ok(None),
129129
};

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1128,9 +1128,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11281128
}
11291129

11301130
let hir = self.tcx.hir();
1131-
let cond_parent = hir.parent_iter(expr.hir_id).skip_while(|(_, node)| {
1132-
matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(op, _, _), .. }) if op.node == hir::BinOpKind::And)
1133-
}).next();
1131+
let cond_parent = hir.parent_iter(expr.hir_id).find(|(_, node)| {
1132+
!matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(op, _, _), .. }) if op.node == hir::BinOpKind::And)
1133+
});
11341134
// Don't suggest:
11351135
// `let Some(_) = a.is_some() && b`
11361136
// ++++++++++

Diff for: compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
488488
// If this empty region is from a universe that can
489489
// name the placeholder, then the placeholder is
490490
// larger; otherwise, the only ancestor is `'static`.
491-
if a_ui.can_name(placeholder.universe) { true } else { false }
491+
return a_ui.can_name(placeholder.universe);
492492
}
493493
}
494494
}

Diff for: compiler/rustc_infer/src/infer/undo_log.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,12 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for InferCtxtInner<'tcx> {
8787

8888
/// The combined undo log for all the various unification tables. For each change to the storage
8989
/// for any kind of inference variable, we record an UndoLog entry in the vector here.
90-
#[derive(Clone)]
90+
#[derive(Clone, Default)]
9191
pub(crate) struct InferCtxtUndoLogs<'tcx> {
9292
logs: Vec<UndoLog<'tcx>>,
9393
num_open_snapshots: usize,
9494
}
9595

96-
impl Default for InferCtxtUndoLogs<'_> {
97-
fn default() -> Self {
98-
Self { logs: Default::default(), num_open_snapshots: Default::default() }
99-
}
100-
}
101-
10296
/// The UndoLogs trait defines how we undo a particular kind of action (of type T). We can undo any
10397
/// action that is convertible into an UndoLog (per the From impls above).
10498
impl<'tcx, T> UndoLogs<T> for InferCtxtUndoLogs<'tcx>

Diff for: compiler/rustc_middle/src/middle/privacy.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ impl EffectiveVisibilities {
103103

104104
pub fn public_at_level(&self, id: LocalDefId) -> Option<Level> {
105105
self.effective_vis(id).and_then(|effective_vis| {
106-
for level in Level::all_levels() {
107-
if effective_vis.is_public_at_level(level) {
108-
return Some(level);
109-
}
110-
}
111-
None
106+
Level::all_levels().into_iter().find(|&level| effective_vis.is_public_at_level(level))
112107
})
113108
}
114109

Diff for: compiler/rustc_mir_transform/src/sroa.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn replace_flattened_locals<'tcx>(
182182
let mut fragments = IndexVec::new();
183183
for (k, v) in &replacements.fields {
184184
fragments.ensure_contains_elem(k.local, || Vec::new());
185-
fragments[k.local].push((&k.projection[..], *v));
185+
fragments[k.local].push((k.projection, *v));
186186
}
187187
debug!(?fragments);
188188

Diff for: compiler/rustc_monomorphize/src/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,8 @@ fn check_recursion_limit<'tcx>(
595595
let def_path_str = tcx.def_path_str(def_id);
596596
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance);
597597
let mut path = PathBuf::new();
598-
let was_written = if written_to_path.is_some() {
599-
path = written_to_path.unwrap();
598+
let was_written = if let Some(written_to_path) = written_to_path {
599+
path = written_to_path;
600600
Some(())
601601
} else {
602602
None

Diff for: compiler/rustc_parse/src/parser/path.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ impl<'a> Parser<'a> {
277277
if let Some(arg) = args
278278
.iter()
279279
.rev()
280-
.skip_while(|arg| matches!(arg, AngleBracketedArg::Constraint(_)))
281-
.next()
280+
.find(|arg| !matches!(arg, AngleBracketedArg::Constraint(_)))
282281
{
283282
err.span_suggestion_verbose(
284283
arg.span().shrink_to_hi(),

Diff for: compiler/rustc_passes/src/dead.rs

-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ impl<'tcx> DeadVisitor<'tcx> {
787787
let mut dead_codes = dead_codes
788788
.iter()
789789
.filter(|v| !v.name.as_str().starts_with('_'))
790-
.map(|v| v)
791790
.collect::<Vec<&DeadVariant>>();
792791
if dead_codes.is_empty() {
793792
return;

Diff for: compiler/rustc_session/src/filesearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
122122
let target = crate::config::host_triple();
123123
let mut sysroot_candidates: SmallVec<[PathBuf; 2]> =
124124
smallvec![get_or_default_sysroot().expect("Failed finding sysroot")];
125-
let path = current_dll_path().and_then(|s| Ok(s.canonicalize().map_err(|e| e.to_string())?));
125+
let path = current_dll_path().and_then(|s| s.canonicalize().map_err(|e| e.to_string()));
126126
if let Ok(dll) = path {
127127
// use `parent` twice to chop off the file name and then also the
128128
// directory containing the dll which should be either `lib` or `bin`.
@@ -165,7 +165,7 @@ pub fn get_or_default_sysroot() -> Result<PathBuf, String> {
165165
}
166166

167167
fn default_from_rustc_driver_dll() -> Result<PathBuf, String> {
168-
let dll = current_dll_path().and_then(|s| Ok(canonicalize(s)))?;
168+
let dll = current_dll_path().map(|s| canonicalize(s))?;
169169

170170
// `dll` will be in one of the following two:
171171
// - compiler's libdir: $sysroot/lib/*.dll

Diff for: compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,8 @@ fn is_c_void_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
9999
ty::Adt(adt_def, ..) => {
100100
let def_id = adt_def.0.did;
101101
let crate_name = tcx.crate_name(def_id.krate);
102-
if tcx.item_name(def_id).as_str() == "c_void"
102+
tcx.item_name(def_id).as_str() == "c_void"
103103
&& (crate_name == sym::core || crate_name == sym::std || crate_name == sym::libc)
104-
{
105-
true
106-
} else {
107-
false
108-
}
109104
}
110105
_ => false,
111106
}
@@ -267,8 +262,7 @@ fn encode_predicates<'tcx>(
267262
) -> String {
268263
// <predicate1[..predicateN]>E as part of vendor extended type
269264
let mut s = String::new();
270-
let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> =
271-
predicates.iter().map(|predicate| predicate).collect();
265+
let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> = predicates.iter().collect();
272266
for predicate in predicates {
273267
s.push_str(&encode_predicate(tcx, predicate, dict, options));
274268
}
@@ -322,7 +316,7 @@ fn encode_substs<'tcx>(
322316
) -> String {
323317
// [I<subst1..substN>E] as part of vendor extended type
324318
let mut s = String::new();
325-
let substs: Vec<GenericArg<'_>> = substs.iter().map(|subst| subst).collect();
319+
let substs: Vec<GenericArg<'_>> = substs.iter().collect();
326320
if !substs.is_empty() {
327321
s.push('I');
328322
for subst in substs {
@@ -703,11 +697,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
703697
tcx.layout_of(param_env.and(ty)).map_or(false, |layout| layout.is_zst());
704698
!is_zst
705699
});
706-
if field.is_none() {
707-
// Transform repr(transparent) types without non-ZST field into ()
708-
ty = tcx.mk_unit();
709-
} else {
710-
let ty0 = tcx.type_of(field.unwrap().did);
700+
if let Some(field) = field {
701+
let ty0 = tcx.type_of(field.did);
711702
// Generalize any repr(transparent) user-defined type that is either a pointer
712703
// or reference, and either references itself or any other type that contains or
713704
// references itself, to avoid a reference cycle.
@@ -720,6 +711,9 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
720711
} else {
721712
ty = transform_ty(tcx, ty0, options);
722713
}
714+
} else {
715+
// Transform repr(transparent) types without non-ZST field into ()
716+
ty = tcx.mk_unit();
723717
}
724718
} else {
725719
ty = tcx.mk_adt(*adt_def, transform_substs(tcx, substs, options));

Diff for: compiler/rustc_transmute/src/maybe_transmutable/query_context.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ mod rustc {
7676
}
7777
};
7878

79-
let ret = if self.visibility(def_id).is_accessible_from(parent, *self) {
80-
true
81-
} else {
82-
false
83-
};
79+
let ret: bool = self.visibility(def_id).is_accessible_from(parent, *self);
8480

8581
trace!(?ret, "ret");
8682
ret

0 commit comments

Comments
 (0)