Skip to content

Commit c8de935

Browse files
authored
Rollup merge of rust-lang#79940 - matthiaskrgr:cl15ppy, r=Dylan-DPC
fix more clippy::complexity findings fix clippy::unnecessary_filter_map use if let Some(x) = .. instead of ...map(|x|) to conditionally run fns that return () (clippy::option_map_unit_fn) fix clippy::{needless_bool, manual_unwrap_or} don't clone types that are copy (clippy::clone_on_copy) don't convert types into identical types with .into() (clippy::useless_conversion) use strip_prefix over slicing (clippy::manual_strip) r? `@Dylan-DPC`
2 parents 90da048 + cf10a0a commit c8de935

File tree

15 files changed

+70
-86
lines changed

15 files changed

+70
-86
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,7 @@ impl<'a> TraitDef<'a> {
597597

598598
let mut ty_params = params
599599
.iter()
600-
.filter_map(|param| match param.kind {
601-
ast::GenericParamKind::Type { .. } => Some(param),
602-
_ => None,
603-
})
600+
.filter(|param| matches!(param.kind, ast::GenericParamKind::Type{..}))
604601
.peekable();
605602

606603
if ty_params.peek().is_some() {

compiler/rustc_codegen_llvm/src/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@ fn generic_simd_intrinsic(
854854
));
855855
}
856856

857-
if name_str.starts_with("simd_shuffle") {
858-
let n: u64 = name_str["simd_shuffle".len()..].parse().unwrap_or_else(|_| {
857+
if let Some(stripped) = name_str.strip_prefix("simd_shuffle") {
858+
let n: u64 = stripped.parse().unwrap_or_else(|_| {
859859
span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")
860860
});
861861

compiler/rustc_llvm/build.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ fn main() {
201201
cmd.args(&components);
202202

203203
for lib in output(&mut cmd).split_whitespace() {
204-
let name = if lib.starts_with("-l") {
205-
&lib[2..]
206-
} else if lib.starts_with('-') {
207-
&lib[1..]
204+
let name = if let Some(stripped) = lib.strip_prefix("-l") {
205+
stripped
206+
} else if let Some(stripped) = lib.strip_prefix('-') {
207+
stripped
208208
} else if Path::new(lib).exists() {
209209
// On MSVC llvm-config will print the full name to libraries, but
210210
// we're only interested in the name part
@@ -241,17 +241,17 @@ fn main() {
241241
cmd.arg(llvm_link_arg).arg("--ldflags");
242242
for lib in output(&mut cmd).split_whitespace() {
243243
if is_crossed {
244-
if lib.starts_with("-LIBPATH:") {
245-
println!("cargo:rustc-link-search=native={}", lib[9..].replace(&host, &target));
246-
} else if lib.starts_with("-L") {
247-
println!("cargo:rustc-link-search=native={}", lib[2..].replace(&host, &target));
244+
if let Some(stripped) = lib.strip_prefix("-LIBPATH:") {
245+
println!("cargo:rustc-link-search=native={}", stripped.replace(&host, &target));
246+
} else if let Some(stripped) = lib.strip_prefix("-L") {
247+
println!("cargo:rustc-link-search=native={}", stripped.replace(&host, &target));
248248
}
249-
} else if lib.starts_with("-LIBPATH:") {
250-
println!("cargo:rustc-link-search=native={}", &lib[9..]);
251-
} else if lib.starts_with("-l") {
252-
println!("cargo:rustc-link-lib={}", &lib[2..]);
253-
} else if lib.starts_with("-L") {
254-
println!("cargo:rustc-link-search=native={}", &lib[2..]);
249+
} else if let Some(stripped) = lib.strip_prefix("-LIBPATH:") {
250+
println!("cargo:rustc-link-search=native={}", stripped);
251+
} else if let Some(stripped) = lib.strip_prefix("-l") {
252+
println!("cargo:rustc-link-lib={}", stripped);
253+
} else if let Some(stripped) = lib.strip_prefix("-L") {
254+
println!("cargo:rustc-link-search=native={}", stripped);
255255
}
256256
}
257257

@@ -262,10 +262,10 @@ fn main() {
262262
let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
263263
if let Some(s) = llvm_linker_flags {
264264
for lib in s.into_string().unwrap().split_whitespace() {
265-
if lib.starts_with("-l") {
266-
println!("cargo:rustc-link-lib={}", &lib[2..]);
267-
} else if lib.starts_with("-L") {
268-
println!("cargo:rustc-link-search=native={}", &lib[2..]);
265+
if let Some(stripped) = lib.strip_prefix("-l") {
266+
println!("cargo:rustc-link-lib={}", stripped);
267+
} else if let Some(stripped) = lib.strip_prefix("-L") {
268+
println!("cargo:rustc-link-search=native={}", stripped);
269269
}
270270
}
271271
}

compiler/rustc_mir/src/transform/coverage/debug.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl DebugCounters {
285285
),
286286
};
287287
counters
288-
.insert(id.into(), DebugCounter::new(counter_kind.clone(), some_block_label))
288+
.insert(id, DebugCounter::new(counter_kind.clone(), some_block_label))
289289
.expect_none(
290290
"attempt to add the same counter_kind to DebugCounters more than once",
291291
);
@@ -340,7 +340,7 @@ impl DebugCounters {
340340
if self.some_counters.is_some() && (counter_format.block || !counter_format.id) {
341341
let counters = self.some_counters.as_ref().unwrap();
342342
if let Some(DebugCounter { some_block_label: Some(block_label), .. }) =
343-
counters.get(&id.into())
343+
counters.get(&id)
344344
{
345345
return if counter_format.id {
346346
format!("{}#{}", block_label, id.index())

compiler/rustc_mir/src/transform/early_otherwise_branch.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
216216
let discr = self.find_switch_discriminant_info(bb, switch)?;
217217

218218
// go through each target, finding a discriminant read, and a switch
219-
let results = discr.targets_with_values.iter().map(|(value, target)| {
220-
self.find_discriminant_switch_pairing(&discr, target.clone(), value.clone())
221-
});
219+
let results = discr
220+
.targets_with_values
221+
.iter()
222+
.map(|(value, target)| self.find_discriminant_switch_pairing(&discr, *target, *value));
222223

223224
// if the optimization did not apply for one of the targets, then abort
224225
if results.clone().any(|x| x.is_none()) || results.len() == 0 {

compiler/rustc_mir_build/src/build/scope.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
616616
debug!("stmt_expr Break val block_context.push(SubExpr)");
617617
self.block_context.push(BlockFrame::SubExpr);
618618
unpack!(block = self.into(destination, dest_scope, block, value));
619-
dest_scope
620-
.map(|scope| self.unschedule_drop(scope, destination.as_local().unwrap()));
619+
if let Some(scope) = dest_scope {
620+
self.unschedule_drop(scope, destination.as_local().unwrap())
621+
};
621622
self.block_context.pop();
622623
} else {
623624
self.cfg.push_assign_unit(block, source_info, destination, self.hir.tcx())

compiler/rustc_session/src/session.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1109,10 +1109,7 @@ impl Session {
11091109
}
11101110

11111111
pub fn link_dead_code(&self) -> bool {
1112-
match self.opts.cg.link_dead_code {
1113-
Some(explicitly_set) => explicitly_set,
1114-
None => false,
1115-
}
1112+
self.opts.cg.link_dead_code.unwrap_or(false)
11161113
}
11171114

11181115
pub fn mark_attr_known(&self, attr: &Attribute) {

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -1448,31 +1448,30 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
14481448
});
14491449
};
14501450

1451-
typeck_results
1451+
if let Some(cause) = typeck_results
14521452
.generator_interior_types
14531453
.iter()
14541454
.find(|ty::GeneratorInteriorTypeCause { ty, .. }| ty_matches(ty))
1455-
.map(|cause| {
1456-
// Check to see if any awaited expressions have the target type.
1457-
let from_awaited_ty = visitor
1458-
.awaits
1459-
.into_iter()
1460-
.map(|id| hir.expect_expr(id))
1461-
.find(|await_expr| {
1462-
let ty = typeck_results.expr_ty_adjusted(&await_expr);
1463-
debug!(
1464-
"maybe_note_obligation_cause_for_async_await: await_expr={:?}",
1465-
await_expr
1466-
);
1467-
ty_matches(ty)
1468-
})
1469-
.map(|expr| expr.span);
1470-
let ty::GeneratorInteriorTypeCause { span, scope_span, yield_span, expr, .. } =
1471-
cause;
1455+
{
1456+
// Check to see if any awaited expressions have the target type.
1457+
let from_awaited_ty = visitor
1458+
.awaits
1459+
.into_iter()
1460+
.map(|id| hir.expect_expr(id))
1461+
.find(|await_expr| {
1462+
let ty = typeck_results.expr_ty_adjusted(&await_expr);
1463+
debug!(
1464+
"maybe_note_obligation_cause_for_async_await: await_expr={:?}",
1465+
await_expr
1466+
);
1467+
ty_matches(ty)
1468+
})
1469+
.map(|expr| expr.span);
1470+
let ty::GeneratorInteriorTypeCause { span, scope_span, yield_span, expr, .. } = cause;
14721471

1473-
interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior(*span));
1474-
interior_extra_info = Some((*scope_span, *yield_span, *expr, from_awaited_ty));
1475-
});
1472+
interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior(*span));
1473+
interior_extra_info = Some((*scope_span, *yield_span, *expr, from_awaited_ty));
1474+
};
14761475

14771476
debug!(
14781477
"maybe_note_obligation_cause_for_async_await: interior_or_upvar={:?} \

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
447447
);
448448
nested.push(Obligation::new(
449449
obligation.cause.clone(),
450-
obligation.param_env.clone(),
450+
obligation.param_env,
451451
normalized_super_trait,
452452
));
453453
}
@@ -485,7 +485,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
485485
);
486486
nested.push(Obligation::new(
487487
obligation.cause.clone(),
488-
obligation.param_env.clone(),
488+
obligation.param_env,
489489
normalized_bound,
490490
));
491491
}

compiler/rustc_typeck/src/check/upvar.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
294294

295295
closure_captures.insert(*var_hir_id, upvar_id);
296296

297-
let new_capture_kind = if let Some(capture_kind) =
298-
upvar_capture_map.get(&upvar_id)
299-
{
300-
// upvar_capture_map only stores the UpvarCapture (CaptureKind),
301-
// so we create a fake capture info with no expression.
302-
let fake_capture_info =
303-
ty::CaptureInfo { expr_id: None, capture_kind: capture_kind.clone() };
304-
determine_capture_info(fake_capture_info, capture_info).capture_kind
305-
} else {
306-
capture_info.capture_kind
307-
};
297+
let new_capture_kind =
298+
if let Some(capture_kind) = upvar_capture_map.get(&upvar_id) {
299+
// upvar_capture_map only stores the UpvarCapture (CaptureKind),
300+
// so we create a fake capture info with no expression.
301+
let fake_capture_info =
302+
ty::CaptureInfo { expr_id: None, capture_kind: *capture_kind };
303+
determine_capture_info(fake_capture_info, capture_info).capture_kind
304+
} else {
305+
capture_info.capture_kind
306+
};
308307
upvar_capture_map.insert(upvar_id, new_capture_kind);
309308
}
310309
}

compiler/rustc_typeck/src/collect.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -2141,13 +2141,8 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
21412141
// * It must be an associated type for this trait (*not* a
21422142
// supertrait).
21432143
if let ty::Projection(projection) = ty.kind() {
2144-
if projection.substs == trait_identity_substs
2144+
projection.substs == trait_identity_substs
21452145
&& tcx.associated_item(projection.item_def_id).container.id() == def_id
2146-
{
2147-
true
2148-
} else {
2149-
false
2150-
}
21512146
} else {
21522147
false
21532148
}

src/bootstrap/dist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ pub fn sanitize_sh(path: &Path) -> String {
11861186
return change_drive(unc_to_lfs(&path)).unwrap_or(path);
11871187

11881188
fn unc_to_lfs(s: &str) -> &str {
1189-
if s.starts_with("//?/") { &s[4..] } else { s }
1189+
s.strip_prefix("//?/").unwrap_or(s)
11901190
}
11911191

11921192
fn change_drive(s: &str) -> Option<String> {

src/bootstrap/sanity.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,7 @@ pub fn check(build: &mut Build) {
159159
panic!("the iOS target is only supported on macOS");
160160
}
161161

162-
build
163-
.config
164-
.target_config
165-
.entry(target.clone())
166-
.or_insert(Target::from_triple(&target.triple));
162+
build.config.target_config.entry(*target).or_insert(Target::from_triple(&target.triple));
167163

168164
if target.contains("-none-") || target.contains("nvptx") {
169165
if build.no_std(*target) == Some(false) {
@@ -176,7 +172,7 @@ pub fn check(build: &mut Build) {
176172
// If this is a native target (host is also musl) and no musl-root is given,
177173
// fall back to the system toolchain in /usr before giving up
178174
if build.musl_root(*target).is_none() && build.config.build == *target {
179-
let target = build.config.target_config.entry(target.clone()).or_default();
175+
let target = build.config.target_config.entry(*target).or_default();
180176
target.musl_root = Some("/usr".into());
181177
}
182178
match build.musl_libdir(*target) {

src/librustdoc/html/markdown.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ fn map_line(s: &str) -> Line<'_> {
139139
let trimmed = s.trim();
140140
if trimmed.starts_with("##") {
141141
Line::Shown(Cow::Owned(s.replacen("##", "#", 1)))
142-
} else if trimmed.starts_with("# ") {
142+
} else if let Some(stripped) = trimmed.strip_prefix("# ") {
143143
// # text
144-
Line::Hidden(&trimmed[2..])
144+
Line::Hidden(&stripped)
145145
} else if trimmed == "#" {
146146
// We cannot handle '#text' because it could be #[attr].
147147
Line::Hidden("")

src/librustdoc/passes/collect_intra_doc_links.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1012,15 +1012,14 @@ impl LinkCollector<'_, '_> {
10121012
} else {
10131013
// This is a bug.
10141014
debug!("attempting to resolve item without parent module: {}", path_str);
1015-
let err_kind = ResolutionFailure::NoParentItem.into();
10161015
resolution_failure(
10171016
self,
10181017
&item,
10191018
path_str,
10201019
disambiguator,
10211020
dox,
10221021
link_range,
1023-
smallvec![err_kind],
1022+
smallvec![ResolutionFailure::NoParentItem],
10241023
);
10251024
return None;
10261025
};

0 commit comments

Comments
 (0)